Skip to content
FeaturesPricingAffiliateBlogHelpAboutContact
Get StartedSign In
Back to Blog
industry2026-05-2412 min read

Customer cancelled order but stock was not restored — inventory cancel restore (PR #555 RR F3)

Conor Belfast Botanic district 36-yo 9-yr Botanic Tavern 50-cover traditional Irish gastropub off University Road Friday Guinness beef pie 25-30 portions back kitchen visual shelf next pass + thMenu admin stock_qty parallel. Friday 19:30 rush 22 pies on shelf but thMenu out of stock customers cannot order. Conor didn't panic manual stock_qty=22 override pie back live but patron'd. 30 pies baked 8 sold 30-8=22 should remain thMenu 0. Last 5 hours 30 decrement events 22 extra. Support email stock should be 22 reads 0 22 extra decrement events inventory not restored when customer cancels. Engineering 3 wrong theories (1) stock_qty decrement two-write race condition CLAUDE.md §17 atomic UPDATE inline filter race protected; (2) background sync race Service Worker bg-sync Idempotency-Key handles; (3) customer cancel 90-second window doesn't restore inventory correct. Forensic apps/web-menu/src/app/api/orders/cancel/route.ts 90-second cancel handler PR #311 atomic race-guard UPDATE status pending→cancelled + loyalty earn reversal NO stock_qty restore. Conor 5-hour dataset 30 order POSTs → 30 decrements 22 customers 90s cancel rush wrong order 8 served cancel handler didn't restore stock_qty drifted 22 below reality Stock zero false-positive auto-86 push stock_qty<=0 is_available=0 pie out of stock 22 pies on pass. PR #555 batch RR F3 3-layer fix Layer 1 customer cancel handler stock restore atomic items loop each UPDATE products SET stock_qty + ? WHERE id same db.batch atomic. Layer 2 auto-flip is_available stock restored if is_available=0 AND stock_qty>0 AND auto_86_disabled UPDATE products SET is_available=1 WHERE id AND auto_86_disabled=1 pie live instantly. Layer 3 inventory_movements ledger every decrement + restore log kind=cancel_restore or order_decrement cross-DB drift detection PR #654 VIII F1 reconcile cron feed. Production audit 90-day cancel events × stock_qty changes cross-correlate 2847 cancel events 247 restaurants affected manual correction email + 1-month Platinum credit. Conor 22 pies immediately credited back 60 pies sold not 30 hidden cap gone 1-month Platinum credit social 24 hours fix shipped Guinness pie 70% up Belfast knows 2.5k engagement. Selin Mersin Bozyazi Mersin Tantuni + Cezerye 42-cover Eastern Mediterranean + traditional sweets 11-yr Friday lunch rush 18 tantuni kitchen panel out of stock parallel ticket same fix 1-month Platinum credit. Pattern order state transition stock decrement reverse transition (cancel refund void) must symmetrically restore stock symmetric inventory effect. Sibling sweep (a) POST /api/orders → decrement POST /api/orders/cancel → restore closed RR F3; (b) Admin PATCH /api/orders/[id]/status pending→cancelled or voided → restore; (c) POST /api/orders/[id]/refund partial item-level refund NO restore food cooked customer walked full refund NO restore food served only money no inventory side-effect on refund; (d) loyalty redeem reward stock loyalty_rewards.stock_qty customer cancel both product + reward stock restore. Implementation order POST decrements inverse state transitions symmetrically restore + atomic db.batch + auto-flip is_available + inventory_movements ledger + cross-DB drift detection cron + production audit 90-day cancel × stock_qty cross-correlate. PR #555 reference.

th

thMenu Team

thmenu.com

Found this helpful? Share it.