Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses the demo app’s checkout-race-condition by ensuring inventory reservations re-validate against live state at commit time, and by adjusting the concurrent checkout repro flow to tolerate expected out-of-stock outcomes.
Changes:
- Add a post-delay availability guard in
reserveStockto prevent overselling under concurrent requests. - Return committed
snapshotVersion/reservationTokenvalues from the live inventory record (instead of the stale snapshot). - Update the concurrent race scenario to use
Promise.allSettledand only fail on non-out-of-stock errors.
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 commit-time stock validation and returns committed version/token values to eliminate stale snapshot usage. |
| demo_app/src/checkout/submit-order.ts | Treats out-of-stock as an expected concurrent outcome by settling requests and filtering soft failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| await delay(25); | ||
|
|
||
| const record = getInventoryRecord(sku); | ||
|
|
||
| if (record.available < quantity) { |
There was a problem hiding this comment.
The comment above this block says the delay is an “Intentional bug”, but with the new post-delay record.available check this function is no longer relying on a stale pre-check. Please update/remove that comment so it doesn’t mislead future readers about the current behavior.
| 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 treats out-of-stock as a soft failure by parsing error.message (startsWith("OutOfStock:")). This is brittle and couples callers to a specific error string; consider using a dedicated error type (e.g., class OutOfStockError) or a structured discriminator (e.g., error.name/code) exported from the inventory layer so the check remains stable if the message changes.
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.