noCV
PRECOVER-104 · Handle partial and uncertain outcomes

Persist replacement progress across stock reservation and shipment creation

Practice briefStoryAdvanced

A replacement reserves the last unit, then shipment creation fails. Retrying from the beginning makes another reservation, while immediately issuing a refund would ignore stock still held for the customer.

Focused work estimate
4h + prerequisites
Priority in the scenario
High
Engineering practice
Workflow orchestration · Compensation · Uncertain outcomes

Estimated field mix

  • Distributed systems60%
  • Integrations20%
  • 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

  • SagaApply

    Coordinate durable replacement steps and fallible compensation so a partial provider success can be resumed or reconciled without repeating earlier effects.

  • StateApply

    Represent uncertain provider outcomes separately from confirmed failures so workflow transitions cannot invent a successful rollback or completed refund.

Your next step

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.

Acceptance criteria

  • Persist separate reservation and shipment steps with stable provider operation keys and explicit pending, confirmed, failed, and uncertain outcomes.
  • Resume from recorded progress after restart; a confirmed reservation is reused instead of repeated when shipment creation is retried.
  • On a confirmed shipment failure, schedule release of the reservation before offering the declared refund fallback; uncertain effects remain unresolved until checked.

Implementation constraints

  • Use a durable orchestrated workflow in the local application; compensation is another fallible operation, not a database rollback of an external effect.

Verification to include

  • Reserve stock, crash before shipment confirmation, and resume; assert one reservation lineage and the correct next step.
  • Return a confirmed shipment rejection and then a reservation-release timeout; verify the workflow remains visible and does not silently refund or reserve again.

Deliverables

  • Replacement step model and reservation/shipment recovery cases

Rollout and recovery

Enable the replacement path for one synthetic order type; pause new workflows while allowing existing recorded steps to reconcile on rollback.

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.