Skip to content

fix(webhook_out): send approval and turn events on one worker per destination (#980) - #1002

Merged
ajianaz merged 3 commits into
developfrom
fix/webhook-sender-hang
Nov 19, 2026
Merged

ajianaz merged 3 commits into
developfrom
fix/webhook-sender-hang

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes #980. The volatile webhook queue (approval_requested, approval_resolved, turn_finished) is now drained by one worker thread per destination plus a separate expiry-timer thread, instead of one thread that sent every due event in turn. A retry that comes back to a full queue is now given up and reported once (queue_full) instead of being lost without a report.

Why

ApprovalSender::look sent every due event synchronously on the single sender thread. A destination may set timeout_secs up to 30, fresh events are all due at once (up to 256 per destination), so one hung or unreachable destination held back every other destination and the 30 s approval expiry timer (whose approval_resolved / expired events were then late). turn_finished (#962) rides the same queue and inherited the stall.

Changes

  • webhook_out/approval_sender.rs:
    • spawn now calls start, which starts the timer thread first (expiry every 30 s, dropped-event report) and then one worker per destination that lists a volatile event (the destination map is loaded once, so the thread count is fixed by the config, no unbounded creation). Each worker drains only its own destination, one request in flight.
    • New drain(queue, wanted, dests, clock, ...): sends due events of the destinations wanted accepts, reads the clock before each send (signature timestamp and retry time stay current after a slow send), and leaves a destination alone for the rest of the pass after a transient failure, so a dead destination costs at most one timeout per pass.
    • ApprovalSender::tick (the timer) split out of look; look stays as tick + drain of every destination on the calling thread (the existing unit tests use it).
    • send_one: a refused requeue now counts as gave_up and calls failed(dest, "queue_full"). Requeue semantics are unchanged (the retry is the one dropped, never a newer event).
    • Wiring (poster, keys, clock, failed, stop flag) so the threads can be driven by fakes in tests; serve never sets stop.
  • webhook_out/volatile.rs: take_due_where(now, wanted); take_due delegates to it. A refused requeue is no longer added to dropped() (the sender reports it as queue_full, so it is reported once, not also in the dropped line). Queue and Taken docs updated for per-destination workers. Otherwise feat(webhook): turn_finished event types, builder and queue (#962) #999 semantics unchanged: D8 same-session replacement on push, requeue never evicts, retry schedule 2 s, 10 s, 30 s, 2 min, then every 5 min to the 15 min horizon.
  • webhook_out/volatile_tests.rs: the refused-requeue test now expects dropped() == 0.
  • Docs: docs/webhook-delivery-design.md (section 4 and the sender bullet) and docs/turn-finished-event.md describe the per-destination delivery model.
  • CHANGELOG.md: entry under Fixed.

Size: 7 files, +509 / -132.

Testing

  • New a_hung_destination_delays_neither_another_destination_nor_the_expiry_timer: real NetPoster against two loopback listeners built at runtime, one that accepts and never answers (20 s timeout) and one that answers 200. Asserts the hung destination has a request in flight, the healthy one receives all three of its events in order within 5 s, the expiry timer's first tick is awaited (deadline loop) before the test clock moves 30 s and then fires again, all well before the hung timeout, with one request in flight for the hung destination and its other events still queued. The test key is generated at runtime; no process-global env is touched. (Against the old single-thread sender this test would block on the hung destination first.)
  • Flake check after review: with a temporary 300 ms and then 2 s sleep at the start of the timer thread (removed again) the test passes; 20 consecutive runs without it: 20/20 pass.
  • New a_retry_refused_by_a_full_queue_is_given_up_and_reported.
  • cargo fmt --all --check: clean.
  • cargo clippy --workspace --all-targets -- -D warnings, with --no-default-features, and with --no-default-features --features shell-tools: clean.
  • cargo test -p tole-cli --lib: 939 passed, 0 failed.
  • cargo test -p tole-cli --test serve_webhook_out --test serve_webhook_approvals --test serve_webhook_turn: 9 + 1 + 8 passed.
  • scripts/review-local.sh: no findings, but deterministic checks only (no LLM configured in this environment), so not a full review.
  • An independent read-only review (outbound data path) found the production change sound and asked for the test deflake, the single report of a refused retry and the doc updates; all three are in the second commit. A re-check of that commit is still needed.

…tination (#980)

A destination that hung until its timeout held back every other
destination and the approval expiry timer, because one thread sent
every due event in turn. The volatile queue is now drained by one
worker thread per destination listing a volatile event (a fixed count
from the loaded config), one request in flight each, and a separate
timer thread. A retry refused by a full queue is now given up and
reported with queue_full.
…sed retry once (#980)

Start the timer thread before the workers and wait for its first tick
before the test moves the clock. A retry refused by a full queue is no
longer added to the dropped counter, since the sender already reports
it as queue_full. Update the queue and Taken docs for per-destination
workers.
@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

@ajianaz
ajianaz merged commit 897118d into develop Nov 19, 2026
22 checks passed
@ajianaz
ajianaz deleted the fix/webhook-sender-hang branch November 20, 2026 08:39
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.

fix(webhook_out): the approval event sender sends inline on one thread, so a hung destination stalls the rest

1 participant