ADR 0013: Outbox relay attempt cap
Status
Accepted (2026-10-13, ecosystem gap fix D12). Amends the outbox ordering
guarantee recorded in
ADR 0007 §1 (the relay drains
rows in id order and a later row never overtakes a failed earlier one):
ordering still holds for every row the relay can deliver, but a row excluded
by the cap is overtaken. Everything else in ADR 0007 and
ADR 0005 (one row per event and topic,
written in the use case's transaction, drained in id order) is unchanged.
Context
cmd/api runs the transactional-outbox relay
(internal/adapters/outbound/outbox). It sends rows one at a time in id
order and stops a pass at the first failed row, so a later row never
overtakes an earlier one. Until now there was no limit: a row that failed was
retried on every pass, forever.
That is right for a broker outage, which ends. It is wrong for a poison
row, one the broker will never accept (a message over the broker's size
limit, a topic that cannot be created, a value the sink rejects every time).
Such a row fails every pass, every pass stops at it, and every row behind it,
for every plan and both topics (warehouse.warehouse-planning.events and
warehouse.warehouse-planning.analytics), waits forever. Nothing pages: the
relay logs outbox relay pass failed per pass and the process stays healthy.
The fleet decision (gap-fix wave 2026-10-12, D12) is that every relay passes an attempt cap, with the convention the fleet's reference relay already had: an excluded row stays in the outbox table for inspection.
Decision
- The relay takes an attempt cap.
outboxrelay.WithMaxAttempts(n); the relay's own zero value stays0(unlimited) so the cap is always an explicit choice at the composition root.Store.Drainreceives the cap and does not claim a row whoseattemptsalready reached it (Postgres:AND attempts < $2on theFOR UPDATE SKIP LOCKEDclaim; the in-memory store applies the same filter). cmd/apireadsOUTBOX_MAX_ATTEMPTS. Default20(outboxrelay.DefaultMaxAttempts);0means unlimited, the old behaviour; an invalid or negative value logs a WARN and uses the default, so a typo cannot silently remove the cap. The chart exposes it asconfig.outboxMaxAttempts(rendered into the ConfigMap and the api Deployment's env).cmd/mcp,cmd/planning-projectorandcmd/planning-reportsrun no relay.- An excluded row is kept, not moved. It stays in
outbox_eventswithpublished_at IS NULL, itsattemptsand itslast_error, for inspection. There is no DLQ topic: a row the broker rejects would most likely be rejected on a DLQ topic of the same broker too, and the table already is the inspectable store. Nothing deletes outbox rows automatically, so an excluded row is never lost. - The failure that reaches the cap is logged once at ERROR, after the
attempt is committed, with the message
outbox relay: row reached the attempt cap and is excluded from future claims; ...and the fieldsoutbox_id,topic,event_type,key,attempts,max_attemptsanderror. A failedDrainreturns an*outbox.SendFailureError(row id, message, attempts after the failure, cause) so the relay can do that without another query. Every failed pass still logsoutbox relay pass failed, as before. - Re-arming is an operator action. After fixing the cause,
UPDATE outbox_events SET attempts = 0 WHERE id = <id>;makes the row claimable again on the next pass (runbook, "Outbox relay"). - Sensor. The architecture fitness test
TestOutboxRelaysPassAttemptCapfails when a non-test file undercmd/callsNewRelay(or the fleet nameNewOutboxRelay) without aWithMaxAttempts(...)argument.
Consequences
- Per-key ordering is no longer absolute. Once a row is excluded, later
rows overtake it, including rows with the same key (the plan id): a
consumer can see
CapacityPlanPublishedfor a plan whoseCapacityPlanCreatednever arrived, or see a re-armed earlier row late. This is the deliberate trade: the cap exists so one poison row cannot stop the whole relay, for every plan, forever. Consumers already dedupe on the CloudEventsid(ADR 0006, ADR 0007 §2); a re-armed row is a late delivery of the sameid. - Ordering among rows that are not excluded is unchanged: within a pass the relay still stops at the first failure, so a transient failure below the cap never lets a later row overtake.
- With the defaults (1 s interval, cap 20) a row that fails every send is
excluded after roughly 20 seconds of continuous failure. A broker outage
longer than that also excludes the rows at the head of the queue, one per
pass, as each reaches the cap: each is logged at ERROR and must be
re-armed. Raise
OUTBOX_MAX_ATTEMPTS(or set0) where long broker outages are expected and a stalled relay is preferable to manual re-arming. - An excluded row is visible with
SELECT id, topic, event_type, key, attempts, last_error FROM outbox_events WHERE published_at IS NULL AND attempts >= 20; - The relay's
Storeport changed shape (DraingainedmaxAttempts); both adapters and the test doubles were updated together.
Verification
go test ./internal/adapters/outbound/outbox/ -run TestRelay_(in-memory store):TestRelay_MaxAttempts_PoisonRowExcludedThenGoodRowPublishes,TestRelay_NoCap_PoisonRowBlocksLaterRows,TestRelay_MaxAttemptsNegativeIgnoredAndDefaultIsTwenty,TestRelay_SendFailureCarriesTheRow.go test -tags=integration ./internal/adapters/outbound/outbox/ -run TestOutboxRelay_ -count=1(real Postgres via testcontainers):TestOutboxRelay_MaxAttempts_PoisonRowExcludedThenGoodRowPublishes,TestOutboxRelay_MaxAttempts_ReArmedRowIsClaimedAgain,TestOutboxRelay_NoCap_PoisonRowBlocksLaterRows.go test ./cmd/api/ -run 'TestOutboxMaxAttempts|TestDefaultOutboxMaxAttemptsIsTwenty'.go test ./internal/architecture/ -run OutboxRelay.bash charts/warehouse-planning/tests/render_test.shasserts the chart default (OUTBOX_MAX_ATTEMPTS: "20") and that0renders as is.