15 KiB
Client Awareness of wait_for_events Yields
Summary
When an Oz cloud agent calls the server-side wait_for_events tool, the agent has not finished its work — it has yielded the turn and is waiting on an inbound message or lifecycle event. The Warp client must observe this yield, keep the run alive, suppress completion-shaped UI (notifications, success badges), and surface a distinct "waiting for events" presentation in the orchestration UI.
Problem
Today the client cannot tell a wait_for_events yield apart from real completion. The model turn ends cleanly, the local conversation status flips to Success, and two things go wrong as a result:
- The Oz CLI driver treats
Successas run completion and schedules the process exit through its--idle-on-completetimer. For cloud agents, this means the worker can exit seconds after yielding, even though child events were expected. Server-side compensations (shouldPreserveInProgressOnClientSuccess,ExtendTaskIdleTimeout) preserve task state in the database but do not keep the running process alive, so the inbound event has no agent to wake. - The notifications mailbox fires
NotificationCategory::Complete("Task completed.") on everySuccesstransition. Orchestrators that yield between turns produce spammy "Task completed" toasts that users have complained about.
A fix has to come from the client: server-side preservation cannot keep a local process alive and cannot suppress local notifications.
Note on orchestration badges: in current one-level orchestration the pill bar aggregator already returns InProgress whenever any child is still active, so a yielded orchestrator with children-in-flight does not display a green check today. The new state still drives a distinct badge in the narrower case where an orchestrator yields with no descendants (or with all descendants terminal) and in any future multi-level orchestration; see invariants 21–24.
Goals
- The client distinguishes a
wait_for_eventsyield from real completion using a first-class state. - While yielded, the agent run stays alive, the conversation reads as non-terminal, completion notifications do not fire, and orchestration UI surfaces a distinct "waiting" badge.
- The yield state clears automatically when the next user input or inbound event resumes the agent.
Non-goals
- Changing how
wait_for_eventsis invoked by the model, or its tool contract from the agent's perspective. - Adding a new mechanism for the user to manually pause / resume a run.
- Redesigning the orchestration pill bar visual language; the new state reuses existing badge primitives with a new color/icon.
- Re-architecting
ConversationStatusconsumers beyond what is required to add the new variant exhaustively.
Figma
Figma: none provided. The new badge should reuse the existing render_avatar_with_status_overlay / status_icon_and_color plumbing with a distinct color and icon for WaitingForEvents so it is visually distinguishable from Success, Blocked, and InProgress.
Behavior
Terms
- A
wait_for_eventsyield is the act of the agent calling the server-sidewait_for_eventstool. The yield ends the current model turn but does not end the run. - A waiting run is an agent run whose most recent turn ended via a
wait_for_eventsyield and which has not yet received any resume input — user query or other conversation input, inbound message, inbound lifecycle event, cancellation, or watchdog timeout — that ends the waiting state. - A terminal status is one of
Success,Error,Cancelled. These mean the run is finished. - A quiescent status is a status in which the agent is not actively streaming output.
Success,Error,Cancelled,Blocked, and the newWaitingForEventsare all quiescent.InProgressis not quiescent.
Conversation status
- The client adds a new
ConversationStatus::WaitingForEventsvalue alongside the existingInProgress,Success,Blocked,Error, andCancelledvalues. WaitingForEventsis quiescent but not terminal: the agent is not actively streaming, but the run is still alive and may resume.- When the current model turn ends via a
wait_for_eventsyield, the conversation status transitions toWaitingForEvents, notSuccess. - When the agent resumes, the conversation status transitions back to
InProgressand the waiting state is cleared. Any of the following triggers a resume: the user submits a new query or other conversation input; the user invokes a slash command or other action that adds a new exchange; the orchestration event stream delivers a message or lifecycle event the agent will consume on its next turn. WaitingForEventsmay only be reached fromInProgress. It may transition toInProgress,Cancelled,Error, orSuccess(if a follow-up turn completes the run conventionally). It must not transition directly to anotherWaitingForEventswithout re-enteringInProgressfirst.- The waiting state is not durable across restart. Shutting the app down ends the wait; on the next start the conversation restores as whatever its last-exchange status implies (typically
Success, since the yielding stream finished cleanly). The unresolvedwait_for_eventstool call stays in the transcript as an orphan, and the next outbound request triggers the server's existing supersede mechanism to synthesize the matchingCancel. The user can re-engage manually if they want to resume the conversation.
Run lifecycle
- A waiting Oz cloud agent run does not trigger CLI driver process exit. The local CLI driver only schedules its
--idle-on-completeexit timer on a true terminal status, not onWaitingForEvents. - A waiting run may still bound its lifetime: if no resume input arrives within an upper bound — no user query or other input, and no inbound message or lifecycle event — the client emits an empty
WaitForEventsResultas a new tool-call-result input on the agent's behalf, closing the unresolvedwait_for_eventscall. The agent's next turn observes the empty timeout result and decides how to proceed (commonlyfinish_task, but the agent may also re-yield via anotherwait_for_events, ask the user, or take other action). The run does not auto-cancel on timeout; the agent owns the post-timeout decision. The upper bound is read from the server-suppliedidle_timeout_secondson thewait_for_eventstool call, falling back to a built-in client default if the server did not supply one. - The watchdog used in (12) is distinct from the completion idle timer. A
WaitingForEventsrun does not enter the completion-idle path even when the configured--idle-on-completevalue is shorter than the waiting watchdog. - The user can cancel a waiting run through any existing cancel affordance. Cancellation transitions to
Cancelledimmediately. - The local
ai_tasksrow reported viaLocalAgentTaskSyncModel.update_agent_taskreportsIN_PROGRESSwhile the conversation isWaitingForEvents. The client does not reportSUCCEEDEDfor a yielded conversation.
Notifications
- A transition into
WaitingForEventsdoes not produce any notification (no toast, no badge in the notification mailbox). - A pre-existing stale notification for the same conversation origin (e.g. a leftover "task in progress" item) is cleared on entry to
WaitingForEvents, the same wayInProgressclears it today. - A subsequent transition from
WaitingForEventsback toInProgress(because the agent resumed) does not produce a notification on its own. - A subsequent transition from
WaitingForEventsto a terminal status (Success,Error,Cancelled) produces the same notification that the same transition fromInProgresswould have produced. - An orchestrator's notifications on
Success,Cancelled, andErrorfire as they do today. If the orchestrator itself reachesSuccess(or another terminal status) it is treating itself as done; the mailbox does not second-guess that based on the state of descendants. The known "orchestrator notification spam" case is the one where the orchestrator yielded viawait_for_eventsbetween turns — that case is already handled by (16), because the orchestrator's status isWaitingForEvents, notSuccess, while it is waiting.
Orchestration pill bar and avatar badges
- A child pill whose conversation status is
WaitingForEventsrenders with the new "waiting" badge (icon + color distinct fromSuccess,Blocked, andInProgress). - The orchestrator pill bar badge is driven by
aggregated_orchestrator_statusover the orchestration tree. The aggregator's precedence isInProgress > Blocked > WaitingForEvents > Error > Cancelled > Success, with one carve-out: when the orchestrator itself yielded intoWaitingForEvents, its own waiting state outranks any descendantInProgress. Rationale:InProgresswins when the orchestrator itself is active or when no node is yielded, because something is actively streaming.- When the orchestrator's own status is
WaitingForEventsbut a descendant is still running, the parent's waiting state is the more useful signal: the user sees that THIS conversation is paused waiting on inbound input even while work continues in the tree. BlockedoutranksWaitingForEventsbecause a blocked node needs user action and must not be masked by a quiescent parent.WaitingForEventsoutranks terminal statuses because the parent is explicitly still alive and listening; the orchestration is not done.
- The hover details card and the orchestration breadcrumb avatars use the same badge mapping. There is no per-surface override for
WaitingForEvents. - The pill sort order treats
WaitingForEventsas part of the "active-ish" section of the bar, not the "done" bucket. A waiting child does not drift to the right of completed siblings.
Other client surfaces
- The block status bar and any "is the agent thinking" indicator must not show a streaming spinner for
WaitingForEvents. Waiting is quiescent: no spinner, no Stop button, no live-streaming affordances. - Conversation input is enabled while in
WaitingForEvents: the user can submit a new query, run a slash command, or any other action that produces a new exchange. Doing so clears the waiting state and starts a new turn (transitioning toInProgress). The user does not need to wait for an inbound event before submitting input. - The block status bar may show an unobtrusive "waiting for events" affordance when the conversation is in
WaitingForEvents. The exact copy is up to design; this spec only requires it not be styled as completion. ConversationStatus::is_done()keeps its existing semantics —Success | Error | Cancelled— and so returnsfalseforWaitingForEvents. No new helper is introduced.
Resume and clearing the waiting state
- The waiting state is cleared (i.e., the conversation leaves
WaitingForEvents) when any of the following happens. The agent itself cannot self-resume fromWaitingForEvents; resume always requires input from outside the agent's own decision-making — user input, the orchestration event stream, the client-side watchdog acting on the agent's behalf, or user cancellation.- The user submits a new query, runs a slash command, or otherwise adds a new exchange to the conversation. A user query is a first-class resume path — it does not require an inbound event to arrive first. The server's existing supersede mechanism emits a generic
Canceltool-call result for the unresolvedwait_for_eventscall; the agent's next turn sees both the cancel and the new input. - The orchestration event stream delivers a message or lifecycle event that the agent will consume in its next turn. Same server-side supersede path as the user-input case.
- The user cancels the run; the conversation transitions to
Cancelled. Pending tool calls are not retroactively cancelled — the unresolvedwait_for_eventstool-call message stays in transcript history as an orphan. - The watchdog from (12) fires; the client emits an empty
WaitForEventsResulton the agent's behalf, closing the unresolved call. The conversation transitions back toInProgresswhile the agent's next turn decides how to proceed (per (12)). The pending tool call is not orphaned by the watchdog path because the client-emitted result closes it.
- The user submits a new query, runs a slash command, or otherwise adds a new exchange to the conversation. A user query is a first-class resume path — it does not require an inbound event to arrive first. The server's existing supersede mechanism emits a generic
- Clearing the waiting state is observable: a transition out of
WaitingForEventsmust produce a status update event so subscribers (task sync, notifications, pill bar) re-evaluate. - The waiting state must not survive across distinct agent runs. Starting a new conversation never inherits
WaitingForEventsfrom a prior conversation.
Backwards compatibility and rollout
This fix requires a coordinated release across the proto contract (warp-proto-apis), the server (warp-server), and the client (warp). The user-visible behavior during the rollout is bounded by the following invariants.
- The fix is gated by a server-side feature flag. When the flag is off for a
wait_for_eventscall, the legacy behavior is unchanged: the client treats the conversation asSuccess, the CLI driver exits per--idle-on-complete, and the existing server-side preservation (shouldPreserveInProgressOnClientSuccess,ExtendTaskIdleTimeout) keeps the taskIN_PROGRESSon the server. This is the pre-fix bug and is acceptable during rollout. - When the server flag is on and the client build includes the new
WaitingForEventssupport, all behavior in this spec applies. The flag flips perwait_for_eventscall (not per conversation), so an individual call's behavior is determined by the flag state at yield time. - The flag may flip mid-conversation. A single conversation can legitimately contain both legacy (pre-flag) and new (post-flag)
wait_for_eventsyields. The new yields activate theWaitingForEventsflow; legacy yields stay on the existing path. The user-visible expectation is that new yields show the "waiting" badge and suppress completion notifications, while legacy yields look the same as today. Both produce the same final outcome (the run resumes correctly when the next inbound event arrives) because the server-side gates protect task state on both paths. - A new client receiving a transcript that contains only legacy
wait_for_eventsyields (e.g. restored from a pre-flag persistence record) treats the conversation as it does today — no retroactive reclassification is attempted. The legacy server-handled tool call is opaque to the client and cannot be detected. - A new client receiving the new public
WaitForEventstool-call variant from any server with the flag on activates the full fix. There is no separate client-side feature flag.