Files
Brit a812918f03 fix(wait): started interactive job waits at the top window
- In the top-level interactive session a first idle wait on owned jobs could only end the turn after 5s, one request more than blocking until the result.
- The idle notice keys on an existing streak instead of the rung.
2026-11-20 18:54:17 +01:00

6.3 KiB

wait

Block until the next background result, peer message, or steering interrupt when there is no other work to do.

Source

  • Entry: packages/coding-agent/src/tools/wait.ts
  • Model-facing prompt: packages/coding-agent/src/prompts/tools/wait.md
  • Job delivery: packages/coding-agent/src/async/job-manager.ts

Input and availability

wait has no arguments. It is an essential, read-approved, interruptible tool available when async jobs, peer messaging, or supervised services are enabled; it does not select a particular peer or job.

Behavior

  • Returns on the first settled caller-owned job or incoming peer message. Job results delivered by this call are consumed so no duplicate async-result follows.
  • Each settled job's Delivery: line distinguishes four cases: already consumed by an earlier call; delivered by this call (the job was not settled when the call began); handed over by this snapshot, which superseded the job's queued completion push so no duplicate result follows; and a genuinely late result, which keeps the "not auto-delivered" wording and adds how long before the call it had finished. Entry state comes from settledJobIds() (membership, not a timestamp comparison), and JobSnapshot.settledAtMs carries the finish time.
  • A steering/tool interrupt returns Wait interrupted by message. with details.interrupted=true; other aborts propagate. Handle the incoming notice before calling wait again.
  • There is no caller-selectable timeout. A wait with nothing new returns a still-running snapshot (useless) after 5s, then after 4m for each back-to-back idle wait; any wait that returns news, or 60s away from wait, restarts it at 5s. In the top-level interactive session a wait on owned jobs starts at 4m: an early return there can only end its turn, one more request than blocking until the result. A back-to-back wait that is the only tool call of its turn goes straight to 4m: an agent that answers an idle return with nothing but another wait has nothing else to do, so the early returns would only cost it requests. The top window stays inside a 5-minute prompt-cache lifetime, so an idle return still reads a warm cache in sessions without the cache warmer (every subagent). The elapsed line names the window spent and what to do once nothing else is left: the top-level interactive session (the TUI transcript), whose next turn every result and message starts, is told to end its turn; any other agent, to call wait again right away with no other tool call. From the second back-to-back idle wait on, an elapsed wait appends a <system-notice> with the time spent waiting, telling the agent to make progress on everything that does not need the result.
  • With no owned job or service running, wait blocks for a reply when the caller sent a direct message (not a broadcast) during its current run to an agent that has not answered it since and is still running. The agent answers with a direct message back (a woken subagent's relayed turn output included), or by settling a job of it the caller owns (its spawn job, or the job of a turn the caller's message woke), which delivers its result. Any incoming direct message (other than agent://<id>?progress) ends wait. An agent://all broadcast never settles the question: one arriving from an agent asked while wait is blocking for a reply interrupts that wait so a later wait keeps blocking for the direct reply, while broadcasts received earlier or from other agents do not end wait and reach the caller when it returns. It also ends, without an error, once no agent asked can still answer: each one finished its turn without replying, or is blocked on the caller (a wait only the caller's result can end, entered after the question; an inline task spawn of it; an untimed eval handle wait on it). A reply that cannot come is what would park both sides.
  • An agent://<id>?progress message from an agent asked is not its answer and does not end wait: wait keeps blocking for that agent while it is still live (even idle), and from then on only a direct message answers — not an agent://all broadcast or a settled job of the turn that sent the progress.
  • Otherwise returns immediately with “Nothing to wait for”, naming any agent asked that finished without replying or cannot reply before the caller finishes.
  • With no owned jobs, a service finishing returns a notice directing the caller to proc:// for status/output; with jobs, the call returns their current snapshot/result instead.
  • Results and peer messages also auto-deliver without calling wait. Continue useful work instead of polling.
  • Queued peer messages are checked first. Already-settled but undelivered owned jobs are returned without another wait. A wake already queued before execution still lets wait drain its message or owned job instead of being skipped; host-owned notices inject at the next boundary after the normal wait result. If a peer message wins a race with job completion, that job remains eligible for normal async delivery.
  • Job waits emit progress snapshots every 500 ms when an update callback is present. Job results/snapshots use details: { op: "wait", jobs: ... }; peer-message results use the messaging result shape.
  • A running subagent's row carries its latest progress, e.g. - `AcpSurface` [task] — <label> — 5h7m · 90 req · $18.40 · ctx 160K/1M · stage: <stage>: run time, requests, cost, context fill, self-estimated completion and stage, whichever its progress record reports. Bash and eval rows, and task rows without a progress record, stay - `<id>` [<type>] — <label>. read proc:// and read proc://<id> show the same progress on running task rows.
  • read proc:// lists caller-visible jobs and project services; read proc://<id> inspects state/output without consuming delivery.
  • write proc://<id>/kill cancels a job or owned subagent, or stops a service; send empty content. Bare proc://<id> writes send stdin only to a service, including empty input.
  • write agent://<id> sends a peer message; agent://all broadcasts to visible live peers from the main agent only. Bare read history:// discovers registered agent transcripts. The final result of a subagent is delivered to its parent automatically.
  • Start supervised services with bash name and optional ready; inspect and control them through proc://.