feat(orb): Orb relay failure queue with periodic retry#1386
Merged
Conversation
When forwardOrbEvent fails to reach a brokered self-host container (e.g. it is temporarily unreachable), the delivery is now recorded in a new orb_relay_failures table instead of being silently dropped. The cron fires a retry-orb-relay job every sweep cycle (≈2 min) when ORB_BROKER_ENABLED is set. retryFailedRelays re-calls forwardOrbEvent for each pending row, deletes it on success or on a RELAY_FORWARD_EVENTS skip, and increments its attempt counter on continued failure. Rows are pruned after 5 attempts or a 1-hour TTL — whichever comes first. Boundary behaviour: - insertions are idempotent (ON CONFLICT DO NOTHING on delivery_id) - storeRelayFailure is a no-op if the forward was skipped (the event type is not forwardable) or if installation_id is not set; only "failed" from a registered relay is recorded - retryFailedRelays never throws; a persistently-down container burns its budget (5 attempts) and the row is cleaned up, preventing unbounded growth The Cloudflare Worker deploy is byte-identical until ORB_BROKER_ENABLED is set (the cron job is not enqueued unless the flag is truthy).
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1386 +/- ##
==========================================
- Coverage 95.36% 95.33% -0.03%
==========================================
Files 191 191
Lines 20714 20730 +16
Branches 7489 7493 +4
==========================================
+ Hits 19753 19763 +10
- Misses 380 383 +3
- Partials 581 584 +3
🚀 New features to boost your workflow:
|
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.
Summary
When
forwardOrbEventfails to reach a brokered self-host container (e.g. it is temporarily unreachable or returning a non-2xx response), the delivery was previously dropped silently. This adds a retry queue so transient failures recover automatically.What ships:
orb_relay_failurestable (delivery_id PK, event_name, installation_id, raw_body, attempts, last_attempt_at, created_at, expires_at)storeRelayFailure— idempotent insert (ON CONFLICT DO NOTHING); called fromhandleOrbWebhookwhenforwardOrbEventreturns"failed"and the installation_id is knownretryFailedRelays— periodic retry worker: deletes rows on success or skip, incrementsattemptson continued failure; prunes rows that have exhausted 5 attempts or exceeded a 1-hour TTLretry-orb-relayjob type — added tosrc/types.tsandsrc/queue/processors.tssrc/index.tsenqueuesretry-orb-relayevery sweep cycle (≈2 min) only whenORB_BROKER_ENABLEDis set — the Cloudflare Worker deploy is byte-identical until the broker flag is turned onBoundary decisions:
"failed"returns fromforwardOrbEventare stored —"skipped"events (non-forwardable type, no registered relay) are fast no-ops that don't need retryingretryFailedRelaysnever throws; a persistently-down container burns its attempt budget and the row is pruned cleanly"skipped"now also deletes the row — if a container deregisters its relay URL between the initial failure and the retry, the failure is cleaned up rather than exhausting attemptsScope
Validation
npx vitest run test/integration/orb-relay.test.ts— 26 tests (19 existing + 7 new), all passnpx vitest run test/integration/orb-webhook.test.ts— 17 tests, all passnpm run test:ci— exit 0, full gate greenSafety
ORB_BROKER_ENABLEDis unsetstoreRelayFailurestores the raw webhook body inraw_body(same data already stored inorb_webhook_events.payload_hash); no new sensitive data is persisted