Repository navigation
fix(webhook_out): send approval and turn events on one worker per destination (#980) - #1002
Merged
Merged
Conversation
…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.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
…-hang # Conflicts: # CHANGELOG.md
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
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::looksent every due event synchronously on the single sender thread. A destination may settimeout_secsup 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 (whoseapproval_resolved/expiredevents were then late).turn_finished(#962) rides the same queue and inherited the stall.Changes
webhook_out/approval_sender.rs:spawnnow callsstart, 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.drain(queue, wanted, dests, clock, ...): sends due events of the destinationswantedaccepts, 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 oflook;lookstays as tick + drain of every destination on the calling thread (the existing unit tests use it).send_one: a refusedrequeuenow counts asgave_upand callsfailed(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 setsstop.webhook_out/volatile.rs:take_due_where(now, wanted);take_duedelegates to it. A refusedrequeueis no longer added todropped()(the sender reports it asqueue_full, so it is reported once, not also in the dropped line). Queue andTakendocs 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 expectsdropped() == 0.docs/webhook-delivery-design.md(section 4 and the sender bullet) anddocs/turn-finished-event.mddescribe the per-destination delivery model.CHANGELOG.md: entry under Fixed.Size: 7 files, +509 / -132.
Testing
a_hung_destination_delays_neither_another_destination_nor_the_expiry_timer: realNetPosteragainst 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.)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.