Repository navigation
Description
What problem does this solve?
When a turn started through POST /sessions/{id}/prompt reaches a Write that is not pre-authorized, the turn settles TurnOutcome::ApprovalRequired and serve answers 200 {"stopReason": "refusal"}. That is the same value serve gives for a blocked stop gate, an unknown tool, a provider failure and a detected loop (crates/tole-cli/src/session_host.rs, stop_reason).
A graphical client therefore cannot tell "the turn is waiting for you to approve" from "the turn failed" using the prompt response. It has to correlate an approval_requested event from the SSE stream, which is ephemeral and not replayed, or poll GET /approvals. A client that was disconnected when the request was queued (a phone opened from a notification) sees only refusal.
Found while mapping the client flow for #561 (flow map, pin 3). The clients (#527, #528, #529) should not each work around it.
Proposed solution
Change only the POST /sessions/{id}/prompt response (and the same outcome in any other serve route that returns a stopReason from this outcome):
- When the outcome is
ApprovalRequired, answer200 {"stopReason": "approval_required", "approval": {"id": "<queue id>", "tool": "<tool>", "status": "pending"}}, with the same row shape asGET /approvals, so a client can show the panel immediately. - Look the pending entry up by session id and tool in the approval queue (
approvals.rs). If the queue holds no pending entry for it (expired or already decided in the meantime), still answerapproval_requiredand omitapproval; the client then falls back toGET /approvals. - Every other outcome keeps its current
stopReason(refusalstays for the cases that are real refusals). - The MCP and ACP faces are out of scope: ACP's
stopReasonvalues come from the ACP spec and must not change; check whether the MCP session tool exposes the same string and keep it consistent only if it already does.
Alternatives considered
- Leave it to clients to correlate
approval_requestedwith the prompt response: works only while the stream was open and adds a race (the frame can arrive before or after the response). - Add a separate field next to
refusaland keep the old value: no break for existing clients, butrefusalwould stay ambiguous for any client that only readsstopReason.
Compatibility
stopReason gains a new value. Clients that treat unknown values as a stop keep working; a client that matches refusal exactly to detect approvals (none known; uteke-mobile polls GET /approvals, see docs/mobile-control.md) would need the new value. Note it in the CHANGELOG.
Acceptance criteria
- A prompt that stops on a non-pre-authorized Write answers
approval_requiredwith the approval id, over the real serve binary; a test fails on the old behavior. - A stop gate block, an unknown tool, a provider failure and a loop still answer
refusal. - The id in the response is the id
POST /approvals/{id}/decisionaccepts. - If the queue entry is gone, the response is still
approval_requiredwithoutapproval, covered by a test. -
docs/mobile-control.mdand the CHANGELOG are updated in the same PR.
Activity