Stop compensation retries when a replacement has already shipped
A shipment-create response was lost, so the return entered compensation. A later status lookup confirms the replacement shipped; the queued compensation still plans to release stock and refund the customer.
- Focused work estimate
- 5h + prerequisites
- Priority in the scenario
- High
- Engineering practice
- Compensation policy · Race conditions · Operational resolution
Estimated field mix
- Distributed systems60%
- System design20%
- Backend20%
Field percentages are editorial estimates of the ticket's engineering focus. They total 100%; they are not measured time, proficiency scores, or ownership evidence.
Pattern topics
- SagaRefactor
Make compensation conditional on current durable and provider-confirmed facts, including irreversible progress and a visible unresolved state.
Review it, then add it to your workspace.
The board opens an editable draft; nothing is saved until you confirm it. Sign-in and workspace permissions apply, and Demo boards remain ephemeral.
Project context
A fictional equipment retailer lets customers choose a refund or replacement after inspection. Its payment and stock providers can time out after accepting an operation, so retrying the whole return is unsafe. Create a local TypeScript application, PostgreSQL state/outbox tables, and synthetic provider doubles with controllable outcomes; no starter code or fixtures are supplied. Use invented orders and integer minor-unit amounts only, with no real payments or external provider calls.
Setup prerequisites
- SQL transactions
- Idempotent commands
- Async failure handling
- State modeling
Preceding work
Complete these dependencies, or supply their agreed outputs before taking this ticket.
- PRECOVER-101 · Reject return decisions that skip inspection or reverse a completed refund
- PRECOVER-102 · Bind a repeated refund request to its original merchant and intent
- PRECOVER-103 · Commit approved return work and its dispatch record together
- PRECOVER-104 · Persist replacement progress across stock reservation and shipment creation
- PRECOVER-105 · Open the refund circuit without declaring timed-out refunds failed
- PRECOVER-106 · Keep stalled stock calls from consuming every refund execution slot
Acceptance criteria
- Revalidate confirmed external progress and the workflow revision before each compensation step; a stale plan cannot execute against newer shipment state.
- Represent irreversible shipment completion and conflicting provider facts explicitly, moving unresolved cases to needs-review with a bounded reason trail.
- An authorized resolution records its cited synthetic provider references and chosen next action without deleting earlier uncertainty or issuing an unapproved second benefit.
Implementation constraints
- Compensation must follow the declared return policy and current confirmed facts; never model an external shipment as a reversible local transaction.
Verification to include
- Queue compensation, then reveal a confirmed shipment before its next step; assert the stale compensation is stopped and no refund is issued.
- Race two resolution attempts and return contradictory provider status responses; verify one revision wins and unresolved contradictions remain visible.
Deliverables
- Compensation guards, conflict-resolution contract, and late-confirmation race cases
Rollout and recovery
Enable automatic compensation only for confirmed reversible states; keep conflict resolution explicit and retain a pause control for all pending compensation.
Value of the work
For the engineer: Practice durable workflow state, ambiguous provider outcomes, compensation, concurrency isolation, and recovery that survives process restarts.
For the team: Inspect whether a proposed workflow preserves refund and inventory invariants, contains provider failures, and gives operators a bounded recovery path.
Evidence boundaries
Outcome Evidence: Tests, patches, and runbooks are requested deliverables. They become Outcome Evidence only through a qualified Mission and immutable Evidence IDs.
Ownership Evidence: Independent adaptation must be observed under a declared verification policy and cite immutable Evidence IDs. Completing a planning ticket establishes no Ownership Evidence.