Repository navigation
feat(serve): answer a prompt that stops for an approval with approval_required - #913
Merged
Merged
Conversation
…_required
POST /sessions/{id}/prompt now answers stopReason approval_required plus
the pending approval row (GET /approvals shape, looked up by session id
and tool) instead of refusal. The row is omitted when the queue entry is
gone. Other non-final outcomes keep refusal; ACP and MCP are unchanged.
Closes #571
A pre-tool hook denial settles the same turn outcome as an approval stop but queues nothing, and a lookup keyed on session and tool alone could return an older undecided entry. Snapshot the approval queue sequence before the turn and answer approval_required only for an entry of this session and tool queued after it; otherwise keep refusal. Also: stop-gate refusal test, concurrent cross-session test, stale and no-queue unit tests, #[non_exhaustive] TurnResult, docs for resumed turns.
…e session The snapshot was taken before the busy claim, so an approvals-resume thread could queue an entry in between and a hook denial of the same tool would return it. run_session_turn_detailed now takes the mark right after claim_turn and returns it in TurnResult. The queue sequence number is also assigned under the entries lock so sequence order is insertion order.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
POST /sessions/{id}/promptontole serveanswers200 {"stopReason":"approval_required","approval":{"id","tool","status":"pending",...}}when the turn stops because a Write needs an approval that its own turn queued. Every other non-final stop staysrefusal.Why
A graphical client or chat gateway could not tell "waiting for approval" from "failed" using the prompt response, and had to correlate an ephemeral SSE frame or poll
GET /approvals. Closes #571 (G0a of the gateway epic #910; serve protocol only, no UI).Changes
approvals.rs: the queue gets a monotonic sequence (PendingApproval.seq,mark(),queued_since()), assigned under the entries lock so sequence order equals insertion order.approval_required_bodynames only an entry of this session and tool queued after the snapshot. The row has theGET /approvalsshape and appears only while the entry is pending; if it expired or was decided meanwhile, the answer isapproval_requiredwithoutapproval.session/host.rs:run_session_turn_detailed(optional queue parameter) takes the snapshot right after the turn claims the session and returns it asTurnResult.queue_mark;TurnResultis#[non_exhaustive]. The ACP and MCP entry points andstop_reason()are unchanged, so ACPstopReasonvalues and the MCPstop_reasondo not change.tole_core::turnis untouched.serve.rs: the prompt route uses the snapshot (one turn per session at a time, 409 otherwise) and answersrefusalwhen the turn queued nothing, such as a pre-tool hook denial, so no client waits for an approval that does not exist. A blocked stop gate, an unknown tool, a provider failure and a loop stayrefusal.docs/mobile-control.md(including that a turn resumed after an allow has noapproval_required: watchapproval_requestedor pollGET /approvals?session=until feat(cron): outbound signed webhook delivery target for cron results and approval requests #911), CHANGELOG (compatibility note and the new public items, including the newseqfield onPendingApproval),docs/epics.md(feat(serve): answer a prompt that stops for an approval with stopReason approval_required and the approval id #571 moved to the gateway track epic: gateway — Telegram (then Discord) over tole serve, in a separate repository #910).stop_reasonis called only byrun_session_turn_detailedandresume_session_turn; ACP and MCPtole_session_promptgo through the unchanged wrappers;queue_entryis called only byQueueApprover::decide. Tests to rerun:serve_approvals,serve_events,serve_approval_required,acp_approval,session_tools.Testing
serve_approval_required): an approval stop answersapproval_requiredwith the row and the idPOST /approvals/{id}/decisionaccepts; overlapping sessions get their own rows; unknown tool, provider failure, loop and a blocked stop gate (--on-turnend,cfg(unix)) arerefusalwith an empty queue.approval); a stop that queued nothing is notapproval_requiredeven with an older pending entry of the same session and tool; no leak across sessions or tools; sequence order equals insertion order under concurrent pushes.refusalpath fails the real-binary tests; dropping the session filter or the sequence filter, or assigning the sequence outside the lock, fails the unit tests. Not covered by a test: the post-claim position of the snapshot (the window needs a resumed turn queueing an entry between two instructions and cannot be driven deterministically).approval_requiredwith nothing queued, and that a stale pending entry of the same session and tool could be returned (fixed by the snapshot). Round 2 found no blocker; its two should-fix items (snapshot taken before the claim, sequence assigned outside the lock) are fixed in the last commit.cargo fmt,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace(freshTOLE_TEST_TMP, empty afterwards),cargo check -p tole-cli --no-default-features: clean.cora review --staged --no-llm: no issues.scripts/review-local.sh: not run in this container.