Conversation
There was a problem hiding this comment.
Pull request overview
Resolves the checkout-race-condition repro path in the demo checkout API by preventing over-reservation under concurrent requests and by handling expected “out of stock” failures without failing the whole concurrent scenario.
Changes:
- Add a live inventory availability re-check right before committing the reservation to avoid stale pre-checks under concurrency.
- Return reservation metadata (token + snapshot version) from the committed inventory record rather than the stale snapshot.
- Switch concurrent checkout scenario execution to
Promise.allSettled, surfacing only “hard” failures while tolerating expectedOutOfStockrejections.
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 post-delay availability guard and returns committed snapshot/version info. |
| demo_app/src/checkout/submit-order.ts | Uses allSettled to tolerate expected OutOfStock failures during concurrent scenario runs. |
💡 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 concurrency window comment above the delay now reads like a still-present bug, but the new post-delay record.available guard changes the behavior. Update the comment to reflect that the delay is only simulating a race window and that availability is re-validated against the live record before commit (or remove the delay if it’s no longer intended).
| const hardFailure = settled.find( | ||
| (result) => | ||
| result.status === "rejected" && | ||
| !(result.reason instanceof Error && result.reason.message.startsWith("OutOfStock:")) | ||
| ); |
There was a problem hiding this comment.
This treats expected failures by parsing error.message (prefix match) which is brittle and easy to break during refactors/localization. Consider introducing a typed OutOfStockError (or an error.code field) and switching this logic to a helper like isOutOfStockError(reason: unknown) so control flow isn’t coupled to the exact message text.
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.