Reject return decisions that skip inspection or reverse a completed refund
The return endpoint accepts a caller-supplied status string. A replacement can be requested before inspection, and a stale browser tab can move a refunded return back to awaiting-inspection.
- Focused work estimate
- 1h 30m + prerequisites
- Priority in the scenario
- High
- Engineering practice
- State modeling · Concurrency control · Authorization
Estimated field mix
- Backend50%
- System design30%
- Security20%
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
- StateCompare
Compare guarded state objects with an explicit transition table for preventing illegal return actions without requiring a class for every status.
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
No earlier ticket is required. Complete the project setup above.
Acceptance criteria
- Define explicit commands and permitted transitions for awaiting inspection, approved, rejected, processing, completed, and needs-review states.
- Require an expected revision and authorized merchant scope for each decision; terminal outcomes cannot be overwritten by a stale command.
- Return stable invalid-transition and revision-conflict errors while preserving an append-only transition history.
Implementation constraints
- Compare a transition table with state objects; choose the representation that makes allowed transitions and guards easiest to inspect.
Verification to include
- Exercise the approved-refund and rejected-inspection paths and compare their recorded transition order.
- Attempt a pre-inspection replacement, a post-refund reversal, and a cross-merchant decision; verify no state or history mutation.
Deliverables
- Return transition contract and invalid-transition regression cases
Rollout and recovery
Route local return decisions through the explicit transition API before adding provider effects; retain transition history when reverting the UI.
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.