Repository navigation
feat(serve): announce turn_finished when a serve session's turn ends (#962) - #988
Merged
Merged
Conversation
A tole serve session's turn end is announced to destinations that list turn_finished: ids and a status word only, built from a typed TurnEnd in the session host. Opt-in per destination, same v2 signing, volatile queue with a 15 minute horizon. Owner decisions D1-D9 are provisional defaults, one constant or seam each.
…-event # Conflicts: # docs/epics.md
…check is not vacuous (#962) A turn that fails before it appends anything settles at the same last_seq as the turn before it, so its event id repeated the earlier id. The id now ends in a per-session in-memory settle counter (provisional D10, one constant). The e2e leak check proves the marker reached the provider-failure and unknown-tool log lines.
ajianaz
marked this pull request as ready for review
November 19, 2026 12:26
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
| // lost: only the latest settle of a session matters to a receiver. | ||
| if turn::OVERFLOW_REPLACES_OLDEST_PER_SESSION | ||
| && event.event == Event::TurnFinished | ||
| && replace_oldest_of_session(q, event.session.as_deref()) |
… session (#962) requeue delegated to push, so a retry into a full queue took the D8 replacement and could remove the newer settle of its own session while keeping the stale one. requeue now never replaces: when the queue is full the retry is dropped and counted. Regression test covers the E0 retry versus queued E1 case.
ajianaz
added a commit
that referenced
this pull request
Nov 19, 2026
) Part 1 of 2 of the turn_finished outbound webhook event (owner decisions D1-D10 confirmed). The contract and the queue only: the closed TurnStatus/TurnCode enums and TurnEnd with its exhaustive outcome mapping, the signed event builder and per-settle event id, the volatile queue with the same-session overflow replacement where a retry never evicts a newer event, and the sender changes and retry schedule. Nothing in the session host or serve calls it yet; part 2 (#988) wires it and adds the real-binary e2e. Split from the original 18-file PR per the PR size standard. Cora verdict clean, CI green.
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
Part 2 of 2 of the
turn_finishedoutbound webhook event of #962 (designdocs/turn-finished-event.md; owner confirmed D1-D10 on 2026-11-19). Part 1 (#999, merged) added the event types, builder, queue and sender. This part wires it into the turn path: when atole servesession's turn ends, a destination that liststurn_finishedineventsgets one signed event with ids and a status word only.Why
The chat gateway (epic #910, tole-gateway#16 and #969) polls status and log after an Allow to learn that a turn ended. One signed event per turn end removes that polling and tells the gateway which thread to answer in, without ever carrying the answer.
Size: 10 files, about 1,080 changed lines (the real-binary e2e file is 808 of them); the original combined PR was split by layer per the PR size standard.
Changes
session/host.rs:TurnResult.turn_end,TurnError,run_session_turn_with_endandresume_session_turn_with_end(the old functions stay as wrappers); an in-memory per-sessionsettlescounter is bumped once per claimed turn, so a turn that fails before appending anything gets a different id than the previous one (D10).serve.rs: announces after the turn returns, outside every lock; the approval id comes from the queue entry, never from the outcome. Failures before the busy claim (busy, unknown session) emit nothing. A provider that cannot be built maps tofailed/provider, a router error tofailed/internal, an approval stop with no Pending entry toblocked/approval.tests/serve_webhook_turn.rs(new, real binary, 8 tests): completed turn, approval stop then Allow, failed/blocked/cancelled, 500 then 200 (same id and body, new timestamp), 400 final, hung receiver, killed receiver, restart without replay. LEAK CHECK: a run-time-built marker in the environment, prompt, tool result, final answer, provider error message and unknown tool name appears in no delivered body and no webhook stderr line; the provider-error and unknown-tool paths first prove the marker reached the log, so the clean-body assertions are not vacuous.faces.mdrow (policy), CHANGELOG, README line,docs/epics.md.Decisions and where to change them: D1 volatile queue; D2 field
last_seq; D3EMIT_APPROVAL_PENDING; D4FOLD_DETACHED_INTO_CANCELLED; D5 serve sessions only (the two call sites inserve.rs); D6 the enums; D7 noprofile; D8OVERFLOW_REPLACES_OLDEST_PER_SESSION; D9RETRY_HORIZON_SECS; D10ID_INCLUDES_SETTLE_COUNTER. All live inwebhook_out/turn.rs(part 1).Not in this PR: the 10-minute approval expiry with an auto-judge (design note merged in #996, owner decisions A1 to A18 open).
Testing
cargo fmt --all -- --check: clean.cargo clippy -p tole-cli --all-targets -- -D warnings: clean for default,--no-default-features, and--no-default-features --features shell-tools.cargo test -p tole-cli --lib: 923 passed (before the split);--test serve_webhook_turn: 8 passed.