Skill Details
Runtime
(gpt-5.5)
Example user message
[userMessage]: Our Node API sometimes sells the final product twice when two customers order simultaneously. Repair it.
Example agent response
Project Detected:
Node.js Express API using PostgreSQL, Prisma, and multiple application instances
---
Race Condition Found:
- The order service reads stock and decrements it in separate queries
- Invariant at risk: Available product stock must never become negative or satisfy more orders than available units
---
Concurrency Boundary:
- Shared resource: Product inventory row
- Competing actors: Simultaneous checkout requests across application instances
---
Repair Applied:
- Replaced the separate stock check and decrement with a conditional atomic update requiring stock greater than or equal to the requested quantity
- Added a transaction covering inventory reservation and order creation
- Added a database uniqueness guard for checkout idempotency keys
---
Files Modified:
- src/services/orderService.ts
- src/repositories/inventoryRepository.ts
- prisma/schema.prisma
- tests/concurrency/inventoryRace.test.ts
- tests/fixtures/products.ts
---
Commands Executed:
- npx prisma validate
- npm run typecheck
- npm test -- tests/concurrency/inventoryRace.test.ts
- npm run build
---
Validation Result:
Schema validation, type checking, the targeted concurrency test, and the production build completed successfully against an isolated PostgreSQL database.
---
Repeatability Test:
- Concurrent operations: 20 requests for 1 remaining unit
- Successful operations: 1
- Safely rejected or deduplicated: 19
- Final invariant: Stock remained at 0, one order was created, and no duplicate reservation was recorded
---
Remaining Risks:
- Payment capture occurs after inventory reservation and still requires expiration handling for abandoned reservations
---
Important Notes:
The repair relies on PostgreSQL atomic updates and a database constraint, so it remains effective across multiple application instances. No production orders or payment providers were accessed.
Get this skill + 9 more with Select$19/mo · Cancel anytime$19/mo · Cancel anytime
View SelectBy purchasing this skill, you agree to our terms of service
GPT-5.5
Repair duplicate writes, oversold inventory, double charges, and other concurrency bugs in APIs.
This skill traces competing requests, identifies unsafe read-modify-write flows, applies transactions, locks, atomic updates, idempotency, or uniqueness guards, and validates the fix under concurrent load.
✔ Find race-prone code paths
✔ Prevent duplicate side effects
✔ Add concurrency tests
✔ Verify repeated-request behavior
Ideal for SaaS, payments, booking, inventory, and queue systems.
...more
Updated 1 week ago
