openai / gpt-6-luna / max / max effort preferred over openai / gpt-6-luna / low / low effort · close win.
Primary judge: Sol 6.1, requested Low. Effective provider effort and internal attempts were not verified. A close win is still a scored preference; it does not establish a material defect.
Reviewed public evidence
Task goal
Design a durable webhook inbox for one PostgreSQL database and multiple workers. An authenticated source supplies eventID, accountID and payload; deliveries are duplicated and reordered. Persist acknowledgement before returning success, deduplicate by source/account/eventID, process with expiring leases and fencing, preserve per-account dependencies, bound retries and poison events, and recover crashes without claiming exactly-once external effects. Define state transitions, transaction boundaries, backpressure and acceptance failure cases.
Give one coherent design with explicit requirements, assumptions and alternatives, state/invariant/transaction details appropriate to the stated scope, and measurable pass/fail acceptance checks. Do not invent benchmark measurements, provider costs, source inspection, executed tests or objective passes. Every contributor must independently answer the complete identical question; there are no separate roles, files or tool evidence.
openai / gpt-6-luna / max / max effort answer
## Recommended design
Use a durable PostgreSQL inbox with **one serialized processing lane per account**. A successful webhook response means only “this event is durably accepted,” not “its effects have completed.”
**Ordering requirement:** `eventID`, `accountID`, and payload do not reveal causal order. To preserve source order despite reordered delivery, require an additional monotonic account sequence number (or explicit predecessor IDs). For account-wide ordering across sources, sources must share that ordering domain. Without such metadata, the system can preserve arrival order only; it cannot infer the intended order.
Assume authenticated, authorized sources; bounded payload sizes; and a source retry horizon. Use a stable account ordering domain, a source-assigned sequence, and an initial cursor value for each account.
### State and invariants
Store each event under a unique `(source_id, account_id, event_id)` key, with its immutable payload/hash, sequence, state, attempt count, next-attempt time, and lease metadata. Enforce a unique sequence per account ordering domain. Keep an account-lane row with the last completed sequence and a monotonically increasing fencing token.
States:
- `READY`: durably accepted; eligible when it is the next sequence and retry time has arrived.
- `LEASED`: claimed by a worker under a fencing token.
- `WAIT_EFFECT`: processing committed an external-effect request to an outbox; the account cursor has not advanced.
- `DONE`: processing and required ordered effects are durably complete; cursor advanced.
- `DEAD`: retry/age limit reached or a permanent processing error occurred; cursor does not advance.
A sequence gap leaves later events stored but ineligible. An expired lease becomes retryable, or `DEAD` if limits are exhausted. A dead event blocks later events for that account: operators must repair/replay it or make an explicit, audited skip. Never silently skip a dependency.
### Transaction boundaries
1. **Ingest:** Authenticate the request and authorize the source for the account before writing. In one transaction, enforce limits, insert the event and sequence, and commit with durable WAL settings (`synchronous_commit=on`). Return 2xx only after commit. A duplicate with the same immutable content can return 2xx; the same key with different content returns 409 and is audited. An uncertain commit gets no success response; a source retry resolves through the unique key.
2. **Claim:** In a short transaction, lock the account lane and next eligible event (`FOR UPDATE SKIP LOCKED` where appropriate), increment the lane fencing token, and set owner/expiry and `LEASED`. Use the database clock. Do not hold a transaction open while processing.
3. **Process:** Work outside the transaction. Commit local database effects, inbox state, and cursor advancement atomically, conditional on the current token and unexpired lease. A stale worker must affect zero rows and discard its result.
4. **External effects:** Write an outbox entry transactionally. Dispatch it outside the transaction with a stable idempotency key. Keep the account sequence blocked until required effects are confirmed; then atomically mark them delivered, mark the event `DONE`, and advance the cursor. Fence dispatcher state updates too. For true duplicate suppression and protection from stale calls, the receiver must honor idempotency keys (and, where needed, sequence/fencing). Without receiver cooperation, external effects are at-least-once and may duplicate; exactly-once external effects are not promised.
### Retry, poison, and backpressure
Count every claim—including claims lost to worker crashes—against a configured maximum. Apply capped exponential backoff with jitter and a maximum event age. Exhaustion or a permanent processing error moves the event to `DEAD`, records the reason, and alerts; replay is explicit and audited. A poison event blocks its account until repaired or explicitly skipped.
Bound queue rows/bytes globally and per account, request size, and ingress rate. Enforce capacity transactionally. For a new event when PostgreSQL is unavailable, the transaction fails, or capacity is exhausted, return 5xx/429 and do not acknowledge. A known, identical committed duplicate may still receive 2xx even at capacity. Retain deduplication records for at least the source’s maximum retry horizon; longer retention or tombstones are needed if that horizon is unbounded.
### Proposed pass/fail checks
These are acceptance criteria, **not tests performed or results observed**:
- Inject a database/commit failure: no 2xx is returned for an uncommitted new event. Restart after a committed event: it remains present.
- Deliver the same event concurrently many times: exactly one inbox row and one sequence reservation exist. Reuse its key with changed content: 409, with no overwrite.
- Deliver sequences 3, 1, 2: sequence 3 remains unprocessed until 1 and 2 complete; recorded completion/effect order is 1, 2, 3.
- Run multiple workers on one account: at most one current lane lease. After expiry and reclaim, the old token cannot update inbox state, local effects, or cursor.
- Crash a worker after claim: lease expiry makes the event retryable; processing eventually completes or reaches the configured retry/age limit and becomes `DEAD`.
- Crash an outbox dispatcher after receiver acceptance but before recording confirmation: retry uses the same idempotency key. With an idempotent receiver, only one external effect is observed; without one, the test must permit duplicates.
- Make a sequence gap persist: later events remain blocked and an alert fires within the configured gap SLA; no automatic cursor skip occurs.
- Fill the configured queue or make PostgreSQL unavailable: new events receive 429/5xx and are not acknowledged; previously committed identical duplicates can still be acknowledged.
### Alternatives and dependencies
Serializing each account is simple and safe but limits same-account throughput. A dependency DAG or parallel processing of provably independent events can improve throughput, but requires explicit dependency metadata and more complex fencing. If sources cannot provide a sequence or dependencies, the only honest alternative is arrival-order processing with no guarantee of causal order.
Key decisions still needed are the source sequence contract and ordering domain, retry/age limits, retention horizon, queue quotas, durability/failover objectives, and downstream idempotency support. Evidence here is limited to the prompt; no source inspection or tests were performed. **Confidence:** high for the stated guarantees under these assumptions. Next, agree the ordering and downstream-effect contracts, then implement the listed failure-injection checks.
openai / gpt-6-luna / low / low effort answer
## Recommendation
Use a durable inbox table as the acknowledgement boundary and a separate per-account cursor/lock to serialize dependent processing. Acknowledge a delivery only after the inbox insert or deduplication check commits. Workers claim eligible events using short transactions and expiring leases with monotonically increasing fencing tokens. Order events within each account by a defined source ordering key; `eventID` alone is not necessarily an ordering key.
This design provides durable acceptance and at-least-once processing attempts. It does **not** guarantee exactly-once external effects: a worker can perform an effect and crash before recording completion. Require idempotent downstream operations, an outbox, or reconciliation where duplicate effects matter.
## Requirements and assumptions
- Authenticate the source and bind its identity to the deduplication key; do not trust a caller-supplied source identity.
- Key uniqueness by `(source_id, account_id, event_id)`. Retain deduplication records for at least the maximum possible redelivery horizon, or indefinitely if that horizon is unknown.
- Store the payload and required metadata durably in PostgreSQL before returning success.
- Assume the source provides a per-account ordering sequence/version (or define another authoritative dependency relation). If it does not, strict causal ordering cannot be inferred from reordered deliveries; buffer for a bounded gap or reject/quarantine unresolved ordering.
- Define payload size limits, retry policy, poison-event handling, retention, and operational recovery procedures before launch.
## State and invariants
An inbox row includes the deduplication key, ordering key, payload, received time, state, attempt count, `next_attempt_at`, lease expiry, lease owner, fencing token, and error/dead-letter metadata.
States: `pending`, `leased`, `retry_wait`, `succeeded`, `dead_letter`. Terminal states are `succeeded` and `dead_letter`; redrive is an explicit audited transition back to `pending`.
Invariants:
1. A success response implies the authenticated event and deduplication key are committed.
2. One durable row exists per deduplication key. A duplicate with matching content returns success without creating work; a conflicting payload for the same key is recorded/alerted and does not overwrite the accepted event.
3. An account’s next event is not claimable until all earlier required events have succeeded or an explicit operator policy has resolved the blocker. Dead-lettering does not silently advance the account.
4. Only the current lease holder with the current fencing token may change a leased row or mark it complete.
5. Retries and event age are bounded by policy; exhaustion leads to durable dead-letter state, not infinite retry.
## Transactions and crash recovery
**Receive:** In one transaction, insert the inbox row with `ON CONFLICT` handling and commit. Return 2xx only after commit. If PostgreSQL is unavailable, the transaction times out, authentication fails, validation fails, or capacity limits reject the event, do not return success. Return retryable failure for transient storage/backpressure conditions; use appropriate client-error responses for invalid or unauthorized requests. A response lost after commit is safe: redelivery hits the unique key.
**Claim:** In a short transaction, select eligible account heads with `FOR UPDATE SKIP LOCKED`, mark them `leased`, set owner and expiry, increment the fencing token and attempt count, then commit. Never hold a database transaction open while calling an external service. Expired leases become eligible for reclaim; reclaim increments the token so a stale worker cannot update inbox state.
**Process/finish:** Perform work outside the claim transaction. In a new transaction, record success (and advance the account cursor, if used) only with a conditional update matching row ID, `leased` state, owner, and fencing token. On retryable failure, conditionally set `retry_wait` and a bounded backoff time; on permanent failure or exhausted attempts/age, set `dead_letter`. A crash before finish leaves an expiring lease; a crash after an external effect but before finish can cause a duplicate effect. Fencing protects database state, not arbitrary external systems. Pass the token to downstream systems when they can reject stale tokens, and use an idempotency key/outbox for duplicate-effect control.
## Backpressure and acceptance checks
Bound request body size, database connections, queue depth, per-account backlog, and worker concurrency. Apply admission limits before accepting; reject rather than acknowledge events that cannot be durably stored. Alert on oldest pending age, lease expiry/reclaim rate, retry volume, dead letters, storage pressure, and account blockers. Keep dead letters inspectable and redrivable with audit history.
Measurable pass/fail checks:
- **Durability:** After a 2xx, restart the service and database under the declared durability configuration; the event remains queryable. Any acknowledged-but-lost event is a failure.
- **Deduplication:** Submit the same key concurrently and repeatedly; exactly one inbox row exists and every valid duplicate receives the documented response. Conflicting content is not silently substituted.
- **Ordering:** Deliver account sequence numbers out of order and concurrently; later events do not execute before required predecessors. Different accounts may progress independently.
- **Lease/fencing:** Pause a worker past lease expiry, reclaim with another worker, then resume the old worker; its stale completion/update is rejected.
- **Crash recovery:** Crash before processing, during processing, and after an external effect but before completion; work is reclaimed, and duplicate external effects are either prevented by the downstream idempotency mechanism or explicitly accepted and reconciled.
- **Retry/poison:** Inject transient and permanent failures; retries follow configured bounds, and exhausted/permanent failures reach durable dead-letter state without silently unblocking dependent events.
- **Backpressure/failure:** Exhaust configured admission capacity or make PostgreSQL unavailable; the service never returns success without commit and returns the documented failure response within its timeout.
- **Redrive:** Redrive a dead letter; audit data is preserved, and per-account ordering policy remains enforced.
Alternatives include a per-account advisory lock instead of a cursor, or a transactional outbox for downstream publication. Advisory locks can simplify serialization but require careful lease/crash semantics; an outbox makes database-to-message publication atomic but downstream consumers still need idempotency. No source inspection or tests were supplied or performed; actual guarantees depend on PostgreSQL durability settings, source ordering semantics, and downstream capabilities.
Primary judge's stated reason
Prefer A because its explicit atomic, expiry-checked local-effect boundary leaves less ambiguity when implementing crash-safe fenced processing. This is a weak preference between substantially equivalent designs, not an established material quality difference; an independent review could reasonably give more weight to B's recovery checks.
This reason is the judge's assessment. No independent factual-defect finding is asserted by this record.
Battle wave: 1fb32bda-9041-4f2e-818c-0fd4669031e2. Pair: brp1_c1344a0475c2552c44032cf6db9c4f801213e2653c7911b14058f3e1dafd58e2. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.