Conversation
There was a problem hiding this comment.
Pull request overview
Resolves the demo app’s checkout-race-condition by adding a post-delay inventory availability guard and adjusting concurrent checkout handling so an expected OutOfStock outcome doesn’t fail the entire scenario run.
Changes:
- Add a post-delay
record.availablecheck inreserveStockto prevent inventory from going negative under concurrent reservations. - Update reservation metadata to reflect the committed
snapshotVersion. - Switch concurrent checkout flow to
Promise.allSettled, treatingOutOfStockas a non-fatal outcome while still surfacing unexpected failures.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| demo_app/src/inventory/reserve-stock.ts | Adds a post-delay availability guard and returns committed version/token to prevent negative inventory under concurrency. |
| demo_app/src/checkout/submit-order.ts | Uses Promise.allSettled to tolerate expected OutOfStock in concurrent mode while rethrowing other failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Intentional bug: this delay makes the pre-check stale under concurrent checkout attempts. | ||
| await delay(25); | ||
|
|
||
| const record = getInventoryRecord(sku); | ||
|
|
There was a problem hiding this comment.
The comment about an "Intentional bug" (stale pre-check under concurrent checkout) is now outdated because a post-delay guard (record.available < quantity) was added. Please update or remove the comment so it reflects the current behavior/fix; otherwise it will mislead future readers when diagnosing race conditions here.
| const hardFailure = settled.find( | ||
| (result) => | ||
| result.status === "rejected" && | ||
| !(result.reason instanceof Error && result.reason.message.startsWith("OutOfStock:")) | ||
| ); |
There was a problem hiding this comment.
runCheckoutRaceScenario is treating OutOfStock as a "soft" failure by inspecting Error.message.startsWith("OutOfStock:"). This is brittle (message text is not a stable contract) and duplicates the sentinel string across modules. Prefer a typed error (e.g., class OutOfStockError) or a stable discriminator (error code/name) exported from the inventory module and checked here.
Summary
Resolve
checkout-race-conditionforcheckout-apiwith a validated ReplayX patch candidate.Changed Files
Validation
Rollback
Revert the live inventory guard and concurrent checkout settlement handling.