Skip to content

feat(serve): answer a prompt that stops for an approval with stopReason approval_required and the approval id #571

Closed

Description

@ajianaz

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, answer 200 {"stopReason": "approval_required", "approval": {"id": "<queue id>", "tool": "<tool>", "status": "pending"}}, with the same row shape as GET /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 answer approval_required and omit approval; the client then falls back to GET /approvals.
  • Every other outcome keeps its current stopReason (refusal stays for the cases that are real refusals).
  • The MCP and ACP faces are out of scope: ACP's stopReason values 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_requested with 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 refusal and keep the old value: no break for existing clients, but refusal would stay ambiguous for any client that only reads stopReason.

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_required with 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}/decision accepts.
  • If the queue entry is gone, the response is still approval_required without approval, covered by a test.
  • docs/mobile-control.md and the CHANGELOG are updated in the same PR.

Part of #523. Related: #524, #561.

Activity

  1. added
    enhancement
    on Nov 11, 2026
  2. added
    pending
    and removed
    pending
    on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions