0036. The outbox relay stops claiming a row after OUTBOX_MAX_ATTEMPTS failures
Status
Accepted. Implemented by the change that introduces this record (fleet gap-fix wave 2026-10-12, decision D12).
Amends the relay behaviour of
ADR 0016, which retried a failing row
without bound. The semantics are the fleet convention that
inventory-storage's relay introduced first (WithMaxAttempts).
Context
postgres.OutboxRelay (internal/adapters/outbound/postgres/outbox_relay.go)
claims unpublished outbox_events rows oldest first and stops a pass at the
first send failure, so a later row never overtakes an earlier failed one. A
row the broker will never accept (a message over the broker's size limit, a
topic that cannot be created) therefore failed on every pass, forever, and
every event written after it waited behind it, on BOTH topics
(warehouse.workforce.events and warehouse.workforce.analytics share the
table and the relay). workforce_outbox_lag_seconds grew without bound and
nothing published until an operator deleted or fixed the row by hand.
Decision
- Attempt cap.
postgres.WithMaxAttempts(n)makes the claim query skip a row whoseattemptsalready reachedn(AND ($2::int <= 0 OR attempts < $2::int)).n = 0keeps the old unlimited behaviour. - Configuration.
cmd/workforcereadsOUTBOX_MAX_ATTEMPTS(default20,0= unlimited; a negative or non-numeric value logs a warning and uses20) throughenvNonNegativeIntOrDefault, carries it incomposition.PublisherConfig.MaxAttempts, andcomposition.BuildEventPublisherpasses it to the relay. The chart exposes it asconfig.outboxMaxAttempts(ConfigMap, mounted withenvFrom).cmd/mcpbuilds no relay, so the setting does not apply there. - Nothing is deleted. A capped row stays in
outbox_eventswithpublished_at IS NULL, itsattemptsand itslast_error, for inspection. The housekeeping sweeper (ADR 0028) only deletes published rows, so it never removes it. - One ERROR line. The failure that brings a row to the cap is logged at
ERROR after the pass commits:
outbox relay: row reached the attempt cap and is no longer claimed, withoutbox_id,topic,event_type,key,attempts,max_attempts, the senderrorand the re-arm statement. - Re-arm. An operator re-arms a row after fixing the cause with
UPDATE outbox_events SET attempts = 0 WHERE id = ...; the next pass claims it again. - Sensor.
TestOutboxRelaysPassAttemptCap(internal/architecture/outbox_relay_cap_fitness_test.go) fails when a non-test file undercmd/orinternal/composition/(where this repo builds the relay for its composition roots) callsNewOutboxRelaywithoutWithMaxAttempts;TestOutboxRelayCapSensorFailsOnBadFixturesproves it can fail.
Consequences
- Per-key ordering has an exception. Once a row is capped, later rows
with the same Kafka key (the same associate, path or shift plan) publish
before it, and it may never publish at all. A consumer can therefore see,
for example,
AssociateCertifiedwithout theAssociateShiftStartedthat preceded it, and the analytics projection under-counts until the row is re-armed. That is the price of the cap, and it is accepted: without it one poison row stops every event of this context, not just one aggregate's. The capped row is visible (the ERROR log, the row itself, the lag gauge) and can be re-armed. - A transient broker outage longer than 20 relay passes also caps rows. The
relay sleeps
OUTBOX_RELAY_INTERVAL(1 s) between failing passes, so 20 attempts is about 20 s of continuous failure for the head row. Re-arm the rows after the outage (UPDATE outbox_events SET attempts = 0 WHERE published_at IS NULL AND attempts >= 20), or raiseOUTBOX_MAX_ATTEMPTSwhere outages are expected to last longer. workforce_outbox_lag_secondsstill measures the oldest unpublished row, so a capped row keeps the gauge growing. That is intended: the gauge is the alert that a row needs an operator.- Tests:
TestOutboxRelay_MaxAttempts_PoisonRowIsExcludedAndTheNextRowPublishesandTestOutboxRelay_WithoutMaxAttempts_RetriesWithoutBound(testcontainers Postgres,outbox_integration_test.go),TestOutboxMaxAttemptsFromEnvandTestPublisherConfigFromEnv_CarriesTheOutboxCap(cmd/workforce), the fitness test above and the chart render test (charts/workforce-management/tests/render_test.sh).
Alternatives considered
- Dead-letter the row to a Kafka DLQ topic. Rejected: the row failed because Kafka would not take it, so a DLQ on the same broker usually fails too, and the fleet convention keeps the row in Postgres.
- Skip the failed row within the same pass. Rejected: it would break per-key ordering on every transient failure, not only for a poison row.
- Keep unlimited retries and alert. Rejected: one row still stops all publishing until a human acts.