0030. Outbox relay attempt cap
Status
Accepted. Amends ADR 0003: a row that has reached the cap no longer holds back later rows of the same path.
Context
The relay (ADR 0003, internal/adapters/outbound/postgres/outbox_relay.go)
drains outbox_events in id order and stops a pass at the first failed
send, recording attempts and last_error on the row, so that a later
event of the same path can never overtake an earlier one. The price was not
written down: a row the broker will never accept (an oversized message,
a topic that cannot be created, a payload a broker-side policy rejects) is
claimed first on every pass, fails every time, and stops every event behind
it forever. One poison row silences the whole Published Language that
fulfillment-execution, wes-work-planning and workforce-management build
their path caches from, and the analytics topic with it. The only signals
were outbox relay pass failed lines and a rising
process_path_management.outbox.lag_seconds.
The fleet's 2026-10-12 gap review (D12) decided that every relay gets an attempt cap with one shared convention, the one inventory-storage already ships.
Decision
postgres.WithMaxAttempts(n)is a new relay option. Withn > 0the claim query only selects unpublished rows withattempts < n. The zero value (no option, orn = 0) keeps the previous unlimited behaviour.- When a failure brings a row to the cap, the relay logs it once at ERROR,
outbox relay: row reached the attempt cap and is no longer claimed, withoutbox_id,topic,event_type,key(thepathIdorsiteId),attempts,max_attempts,errorand the re-arm SQL. The row is not deleted, not moved and not marked published: it stays inoutbox_eventswithattemptsandlast_errorfor inspection, and the housekeeping sweeper (ADR 0018) never deletes it because it only deletes published rows. - An operator re-arms a row with
UPDATE outbox_events SET attempts = 0 WHERE id = ...; the relay claims it on its next pass. cmd/pathmgmtpasses the cap fromOUTBOX_MAX_ATTEMPTS(default20,0= unlimited; an unparseable or negative value falls back to 20 with a warning) and logs it on thekafka event publishing enabled (transactional outbox)line. The chart exposes it asconfig.outboxMaxAttempts.- No migration:
attemptsandlast_errorexist since the outbox was introduced. - Sensor: the architecture fitness test
TestOutboxRelaysPassAttemptCapfails when a non-test file undercmd/callsNewOutboxRelaywithout aWithMaxAttempts(...)argument, so the cap is always a deliberate setting at the composition root.
Per-key ordering
ADR 0003 promised that a later event of a path never overtakes an earlier
one. With the cap that holds only until the earlier row is parked: from then
on later rows with the same key publish ahead of it, and a re-armed row is
delivered late, after newer events of that path. This is accepted on
purpose. Twenty consecutive failures of one row (at the default 1 s idle
interval that is at least twenty passes) are not a transient broker problem,
and the alternative is that every consumer stops receiving every change.
Consumers already treat the topic as replayable and key their caches by
pathId; an operator who re-arms a parked row should prefer re-publishing
the path's current state (revise it through the API) when a late, older
event could overwrite newer cached state.
Consequences
Easier
- One poison row can no longer stop the relay: healthy events keep flowing
after at most
OUTBOX_MAX_ATTEMPTSfailed passes. - The parked row is visible (ERROR log with its identity, the row itself) and recoverable with one statement.
- Tests:
TestOutboxRelay_MaxAttempts_PoisonRowIsExcludedAndTheNextRowPublishesandTestOutboxRelay_WithoutMaxAttempts_RetriesWithoutBound(testcontainers Postgres),TestOutboxMaxAttemptsFromEnv,TestOutboxRelaysPassAttemptCapand its fixture test.
Harder
- Per-path ordering is no longer absolute (see above).
- A broker outage longer than twenty passes parks every row that failed
twenty times; after the outage those rows need re-arming. The ERROR log
and the query in the runbook find them. Raise
OUTBOX_MAX_ATTEMPTS(or set0) in environments where long broker outages are expected. outbox.lag_secondskeeps measuring the oldest unpublished row, so a parked row keeps the gauge high until it is re-armed or resolved. That is intended: the gauge must not hide a lost event.