Skip to content

feat(serve): announce turn_finished when a serve session's turn ends (#962) - #988

Merged
ajianaz merged 8 commits into
developfrom
feat/turn-finished-event
Nov 19, 2026
Merged

ajianaz merged 8 commits into
developfrom
feat/turn-finished-event

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 2 of 2 of the turn_finished outbound webhook event of #962 (design docs/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 a tole serve session's turn ends, a destination that lists turn_finished in events gets 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_end and resume_session_turn_with_end (the old functions stay as wrappers); an in-memory per-session settles counter 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 to failed/provider, a router error to failed/internal, an approval stop with no Pending entry to blocked/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.
  • Docs: threat-model rows, design note and delivery-design updates, faces.md row (policy), CHANGELOG, README line, docs/epics.md.

Decisions and where to change them: D1 volatile queue; D2 field last_seq; D3 EMIT_APPROVAL_PENDING; D4 FOLD_DETACHED_INTO_CANCELLED; D5 serve sessions only (the two call sites in serve.rs); D6 the enums; D7 no profile; D8 OVERFLOW_REPLACES_OLDEST_PER_SESSION; D9 RETRY_HORIZON_SECS; D10 ID_INCLUDES_SETTLE_COUNTER. All live in webhook_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.
  • An independent read-only review of the outbound data path and turn runner was done; its findings (D10 id reuse, vacuous leak assertions) are fixed. Cora found the requeue eviction case on the combined PR; it is fixed and tested in part 1.
  • The CI Cora Review is the merge gate for this head.

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.
…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
ajianaz marked this pull request as ready for review November 19, 2026 12:26
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🔍 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())
ajianaz and others added 3 commits November 19, 2026 12:56
… 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
ajianaz changed the base branch from develop to feat/turn-finished-core November 19, 2026 21:48
@ajianaz
ajianaz changed the base branch from feat/turn-finished-core to develop November 19, 2026 21:48
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.
@ajianaz ajianaz changed the title feat(serve): turn_finished outbound webhook event (#962) feat(serve): announce turn_finished when a serve session's turn ends (#962) Nov 19, 2026
@ajianaz
ajianaz merged commit 0486494 into develop Nov 19, 2026
26 checks passed
@ajianaz
ajianaz deleted the feat/turn-finished-event branch November 20, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants