fix(webhooks): durable delivery queue + re-drive (audit #3)#98
Merged
Conversation
The dispatcher marked an event seen (in-memory) before attempting delivery, and delivery happened inline with a bounded retry burst. A delivery that failed every attempt -- or any event in flight when the process restarted -- was silently dropped (audit_28_06_26.md #3): the in-memory seen-set is rebuilt from existing events on restart and never re-attempts. Add a durable per-(webhook, event) delivery queue in DuckDB (webhook_delivery_queue, PK (webhook_id, event_id)) alongside the existing append-only webhook_deliveries log: - dispatch_new_events enqueues each matching delivery durably, attempts it inline (unchanged happy-path latency), then records the outcome. - process_delivery_queue re-drives due 'pending' rows each loop pass with a backoff schedule, parks a row 'dead' after max_delivery_attempts, and parks (does not retry forever) a delivery whose webhook was removed or deactivated. The stored canonical body lets a delivery be replayed without re-reading pipeline_events, so it survives a restart. mark-seen-on-scan is left untouched: it still drives event-driven metric cache invalidation (main.py wraps dispatch on seen-set growth). deliver() keeps its return shape and 3-attempt burst for the /test endpoint. Verification (no-Docker, on Windows): ruff / ruff format / mypy clean; full unit suite 1135 passed / 1 skipped; webhook unit+integration 34 passed including new tests for enqueue idempotency, the outcome state machine, re-drive of due / dead-at-max / not-due / removed-webhook rows, survival across a fresh dispatcher instance (restart), and an end-to-end failed-then-redriven delivery. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
DORA Metrics
|
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.
Audit #3 — webhook durable re-drive
Problem
The dispatcher marked an event seen (in-memory) before attempting delivery, and delivery happened inline with a bounded retry burst. A delivery that failed every attempt — or any event in flight when the process restarted — was silently dropped (
audit_28_06_26.md#3): the in-memory seen-set is rebuilt from existing events on restart and never re-attempts. This violates at-least-once delivery.Fix
Add a durable per-
(webhook, event)delivery queue in DuckDB (webhook_delivery_queue, PK(webhook_id, event_id)) alongside the existing append-onlywebhook_deliverieslog:dispatch_new_eventsenqueues each matching delivery durably, attempts it inline (unchanged happy-path latency), then records the outcome.process_delivery_queuere-drives duependingrows each loop pass with a backoff schedule, parks a rowdeadaftermax_delivery_attempts, and parks (does not retry forever) a delivery whose webhook was removed or deactivated. The stored canonical body lets a delivery be replayed without re-readingpipeline_events, so it survives a restart.mark-seen-on-scanis left untouched: it still drives event-driven metric cache invalidation (main.pywraps dispatch on seen-set growth).deliver()keeps its return shape and 3-attempt burst for the/testendpoint — the durable queue is layered over inline delivery, not a replacement.Verification (no-Docker, on Windows)
ruff/ruff format/mypyclean🤖 Generated with Claude Code