ask: the wait for an answer is the operator's to set, and a late answer is refused

The 900 s wait was not the defect -- a person reads and thinks. Being hard
coded was: a run with no operator attached (an older protocol client that
does not know SP_EV_ASK, a script) lost the turn for fifteen minutes and
nobody could shorten it. Measured before the change: a client that ignores
the event saw the question and then no turn for 10 s.

sp_ask_wait_s() reads $SPLINTER_ASK_TIMEOUT, then ask_timeout from the
config, then SP_ASK_WAIT_S = 900. No upper bound: how long a turn may wait
is the operator's call. Consumers: engine_ask, tg_ask.

protocol.c also dropped sp_engine_answer's return value, so an answer that
arrived after the question was gone (wait expired, turn cancelled) looked
accepted. It now reports "no question is pending", as steer already did.

Test evidence:
- tests/test_ask_timeout.sh (new, wired into make check): with
  SPLINTER_ASK_TIMEOUT=3 the turn returns in 3 s with the "no answer"
  observation instead of parking. Proven red against the old code (env
  ignored: 5 FAILs, the client got no turn at all) and green on the fix.
- ask_timeout in the config file takes effect too: measured 3.1 s against a
  running --serve, so the docs line is not a claim.
- sp_ask_wait_s() edge cases: unset/0/-5/abc -> 900, 1 -> 1, 42 -> 42,
  999999999999 -> clamped.
- make check green (336 s), make check-asan and check-tsan clean (46
  binaries each).
This commit is contained in:
lotherk committed 2026-11-24 09:00:49 +00:00
1 parent 181b2c0638
commit 6debe213c3
16 files changed
+192 -18

No files matched your search

+8 -4
View File
@@ -369,12 +369,16 @@ int sp_session_remove_if_empty(const char *dir, const char *id);
#define SP_ASK_OPTIONS 8 /* "which one?" alternatives */
#define SP_ASK_OPT_LEN 96
/*
* How long the `ask` tool waits for an answer. Long enough that a person can
* read the question and think, short enough that a turn with no front end
* attached (a script, a gateway that forgot the caller) comes back with "nobody
* answered" instead of hanging until somebody kills it.
* How long the `ask` tool waits for an answer, when nothing else says. Long
* enough that a person can read the question and think, short enough that a
* turn whose front end does not know the question (an old client, a script)
* comes back with "nobody answered" instead of hanging until somebody kills
* it. Overridden by $SPLINTER_ASK_TIMEOUT, then by `ask_timeout` in the
* config; see sp_ask_wait_s(). No upper bound: how long a turn may wait is
* the operator's call, not the program's.
*/
#define SP_ASK_WAIT_S 900
int sp_ask_wait_s(void);
struct sp_agent_config {
size_t max_steps; /* tool rounds per turn */