42. Outbox relay attempt cap (OUTBOX_MAX_ATTEMPTS)
Status
Accepted. Decided 2026-10-12 (fleet gap-fix wave, decision D12). Amends the relay retry behaviour of ADR-0020; that ADR's body is not edited. It follows the fleet convention that inventory-storage introduced first (same option name, env var, default and log fields).
Context
The relay of ADR-0020 drains
outbox_events one row at a time in id order and stops a pass at the first
failed send, recording attempts and last_error on that row. That keeps
per-key ordering, but a row the broker will never accept (a message over the
broker's size limit, a topic that no longer exists, a payload a broker-side
policy rejects) is retried forever: every later row, of every key and both
topics, waits behind it. One poison row stops the whole relay, and with it
every integration and analytics event this service publishes.
Decision
postgres.WithMaxAttempts(n). Withn > 0the relay's claim query only selects rows withattempts < n. A row that has failednsends is excluded from future claims. It is not deleted or moved: it stays inoutbox_eventswithpublished_at IS NULL, itsattemptsand itslast_error, so an operator can inspect it.- Logged at ERROR once. The failed send that brings a row to the cap is
logged at ERROR, after the pass commits, with
outbox_id,topic,event_type,key,attempts,max_attemptsand the error. Failures below the cap are logged at WARN. - Configuration.
cmd/execution(the only process that runs the relay) readsOUTBOX_MAX_ATTEMPTS: default20(postgres.DefaultOutboxMaxAttempts),0means unlimited (the previous behaviour), a malformed or negative value falls back to the default with a WARN instead of failing the boot. It reaches the relay throughcomposition.PublisherConfig.RelayMaxAttempts. The chart value isconfig.outboxMaxAttempts. - Re-arming. After fixing the cause, an operator re-arms a row with
UPDATE outbox_events SET attempts = 0 WHERE id = ...; the next pass claims it again (runbook). - Sensor. The architecture fitness test
TestOutboxRelaysPassAttemptCapfails when a non-test file undercmd/orinternal/composition/(where this repo builds the relay) callsNewOutboxRelaywithout an inlineWithMaxAttempts(...).
Consequences
Easier
- One poison row costs at most
OUTBOX_MAX_ATTEMPTSfailed passes, then the relay moves on. The rest of the outbox keeps flowing. - The excluded row is visible (ERROR log, the row itself) instead of a silently growing lag.
Harder
- Per-key ordering is given up for an excluded row. Rows behind it,
including rows with the same key (the same task or package), are
published before it. A consumer can see a later state of an aggregate
without the earlier event, and sees the earlier one only if an operator
re-arms it (then out of order). That is the deliberate trade: ordering is
kept while a row is retried, and broken only once a row has failed
Ntimes and is presumed poison. - A long broker outage also counts as failures: with the default
20and the relay's1sinterval, a row excluded during a broker outage stays excluded after the broker comes back and must be re-armed. Operators who prefer to wait out outages can setOUTBOX_MAX_ATTEMPTS=0, or a larger value. - No dead-letter topic is introduced for the outbox: the table itself holds the excluded rows.