Skip to content

feat(webhook): turn_finished event types, builder and queue (#962) - #999

Merged
ajianaz merged 1 commit into
developfrom
feat/turn-finished-core
Nov 19, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/turn-finished-core

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 1 of 2 of the turn_finished outbound webhook event (#962, design docs/turn-finished-event.md, owner decisions D1-D10 confirmed 2026-11-19). The contract and the queue only: nothing in the session host or tole serve calls it yet. Part 2 (#988) wires it into the turn path and adds the real-binary e2e, docs and CHANGELOG.

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, with ids and a status word only.

Size: this was one 18-file, about 2,300-line PR; the Cora job timed out on it, so it is split by layer per the PR size standard. This part is 8 files and 1,314 changed lines (above the 1,000 ideal, under the 1,500 ceiling; 591 of them are unit tests), because the types, the builder, the queue rule and the sender retry schedule must land together to be tested and green on their own.

Changes

  • webhook_out/turn.rs (new): closed TurnStatus / TurnCode enums, TurnEnd, TurnSignal, and TurnEnd::from_outcome, one exhaustive match on TurnOutcome with no wildcard arm that drops every payload string. All knobs are named constants (D1-D10).
  • webhook_out/event.rs: turn_finished builder (body at most 1 KiB, refused not cut; an id outside its charset or one the redactor would change is not sent) and turn_event_id (turn:<readable>:<hash16>:<last_seq>:<settle>, at most 128 characters, shared with the cron helper).
  • Event::TurnFinished (ALL is now 4). Default events is unchanged, so an existing destination does not receive it.
  • volatile.rs: on a full queue a new turn event replaces the oldest queued one of the same session (D8). A retry (requeue) never takes that replacement: when full the retry is dropped and counted, so an older settle can never evict a newer one.
  • approval_sender.rs: the sender starts for a turn event too, with its own retry schedule (2 s, 10 s, 30 s, 2 min, then every 5 min, 15 min horizon); a lost event is one stderr line with the destination name and a closed code.

Testing

  • cargo fmt --all -- --check: clean.
  • cargo clippy -p tole-cli --all-targets -- -D warnings: clean for default features and for --no-default-features.
  • cargo test -p tole-cli --lib webhook_out: 163 passed.
  • Unit tests cover outcome mapping, the exact key-set allow-list, the 1 KiB bound, id properties (including the failed-before-append case and the 128-character maximum), opt-in/default, the pinned v2 signature vector (computed independently with Python), the overflow policy, the retry-never-evicts-newer case (found by Cora on the combined PR), and the retry schedule and horizon.
  • An independent read-only review of the whole design and the outbound data path was done on the combined PR; its findings are fixed here. Part 2 carries the real-binary e2e with the leak check.

Part 1 of 2 of the turn_finished outbound event: 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 (a retry never evicts a newer event), and the sender changes that deliver it. Nothing in the session host or serve calls it yet; part 2 wires it and adds the real-binary e2e.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit cb5877f into develop Nov 19, 2026
26 checks passed
ajianaz added a commit that referenced this pull request Nov 19, 2026
…962) (#988)

Part 2 of 2 of the turn_finished outbound webhook event (owner decisions D1-D10 confirmed 2026-11-19). Wires the part-1 types and queue (#999) into the turn path: run_session_turn_with_end and resume_session_turn_with_end return a typed TurnEnd with a per-session settle counter, and serve announces after the turn returns, outside every lock; the approval id comes from the queue entry, never from the outcome. Adds the real-binary e2e (8 tests) with a run-time-built leak-check marker proven to reach the log, plus the threat-model rows, design and delivery notes, faces.md row, CHANGELOG and README. Independent read-only review done; Cora verdict clean and CI green on the merged head.
ajianaz added a commit that referenced this pull request Nov 19, 2026
…hing else (#980) (#1002)

The approval and turn_finished sender sent every due event inline on one thread, so a destination that hung (timeout up to 30 s, up to 256 events due at once) stalled every other destination and the approval-expiry timer. The sender now runs one worker thread per destination that lists approval_requested, approval_resolved or turn_finished, plus one timer thread started first; each worker has at most one request in flight and skips its destination for the rest of the pass after a transient failure. A retry refused by a full queue is reported once as queue_full instead of being dropped silently or counted twice. The #999 queue rules are unchanged (same-session replacement on push, a retry never evicts a newer event, same retry schedule and 15 min horizon). Independent read-only review done and re-checked; Cora verdict clean and CI green on the merged head.
@ajianaz
ajianaz deleted the feat/turn-finished-core 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.

1 participant