mirror of
https://github.com/can1357/oh-my-pi.git
synced 2026-11-23 12:53:26 +08:00
- 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.
6.3 KiB
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 fromsettledJobIds()(membership, not a timestamp comparison), andJobSnapshot.settledAtMscarries the finish time. - A steering/tool interrupt returns
Wait interrupted by message.withdetails.interrupted=true; other aborts propagate. Handle the incoming notice before callingwaitagain. - 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 fromwait, 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 anotherwaithas 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 callwaitagain 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,
waitblocks 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 thanagent://<id>?progress) endswait. Anagent://allbroadcast never settles the question: one arriving from an agent asked whilewaitis blocking for a reply interrupts thatwaitso a laterwaitkeeps blocking for the direct reply, while broadcasts received earlier or from other agents do not endwaitand 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 (awaitonly the caller's result can end, entered after the question; an inlinetaskspawn of it; an untimed eval handle wait on it). A reply that cannot come is what would park both sides. - An
agent://<id>?progressmessage from an agent asked is not its answer and does not endwait:waitkeeps blocking for that agent while it is still live (even idle), and from then on only a direct message answers — not anagent://allbroadcast 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
waitdrain 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://andread proc://<id>show the same progress on running task rows.
Related surfaces
read proc://lists caller-visible jobs and project services;read proc://<id>inspects state/output without consuming delivery.write proc://<id>/killcancels a job or owned subagent, or stops a service; send emptycontent. Bareproc://<id>writes send stdin only to a service, including empty input.write agent://<id>sends a peer message;agent://allbroadcasts to visible live peers from the main agent only. Bareread history://discovers registered agent transcripts. The final result of a subagent is delivered to its parent automatically.- Start supervised services with
bashnameand optionalready; inspect and control them throughproc://.