Skip to content

fix: preserve concurrent charge waivers during item void async PIN check - #1258

Merged
khaira777 merged 3 commits into
mainfrom
fm/remediate-n1-void-charges
Oct 21, 2026
Merged

khaira777 merged 3 commits into
mainfrom
fm/remediate-n1-void-charges

Conversation

@khaira777

@khaira777 khaira777 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1253

Intent

Fix finding N1 (GitHub issue #1253) in FreeOpenSourcePOS/FloCafe: when voiding an in-progress (preparing or ready) order item via PATCH /api/orders/:orderId/items/:itemId/cancel, preserve any charge waivers or delivery charge updates that were applied concurrently while the route was awaiting asynchronous manager PIN verification (withPinVerificationLock / verifyPinAsync). Inside the withTxn transaction in main/routes/orders.ts, charge resolution (resolveEngineCharges), fallback charge columns (service_charge, packaging_charge, charges_breakdown), and unpaid bill synchronization (syncUnpaidBillsForOrder deliveryCharge) must read from the fresh transaction-local currentOrder snapshot rather than the stale pre-await order snapshot, and regression tests must verify that concurrent waivers of service_charge and packaging_charge during async item-void PIN verification remain waived on both orders and unpaid bills.

What Changed

  • Updated PATCH /api/orders/:orderId/items/:itemId/cancel in main/routes/orders.ts to source charge engine resolution (resolveEngineCharges), fallback charge fields (service_charge, packaging_charge, charges_breakdown), and unpaid bill synchronization (deliveryCharge) from the transaction-local currentOrder snapshot instead of the pre-await order snapshot.
  • Preserved concurrent charge waivers and delivery charge modifications made while awaiting asynchronous manager PIN verification on both the order and unpaid bills.
  • Added regression tests in tests/order-item-cancel-restore.test.ts verifying that concurrent service charge, packaging charge, and delivery charge modifications during asynchronous PIN verification persist after item cancellation.

Risk Assessment

✅ Low: The change is a surgical and well-tested 5-token correction replacing stale pre-await order snapshots with the fresh transaction-local currentOrder snapshot inside withTxn during item voids.

Testing

Executed full reproduction of finding N1 on base commit 0818717 (failing on stale order snapshot), followed by live validation against the running product with target commit 3a35742 across 5 live scenarios covering concurrent service charge waiver, packaging charge waiver, delivery charge sync on order cancellation, invalid manager PIN guard, and non-void pending item cancellation; all passed and captured to evidence files.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Concurrent Service Charge Waiver during In-Progress Item Void: cashier voids preparing item with manager PIN while manager concurrently waives service charge on unpaid bill; order and unpaid bill both… ✅ pass live ~/.no-mistakes/evidence/01M5EFSYGRA80KNFSNRJP5M1BM/live-scenarios-execution.log
Concurrent Packaging Charge Waiver during In-Progress Item Void: cashier voids preparing item with manager PIN while manager concurrently waives packaging charge on unpaid bill; order and unpaid bill… ✅ pass live ~/.no-mistakes/evidence/01M5EFSYGRA80KNFSNRJP5M1BM/live-scenarios-execution.log
Concurrent Delivery Charge Update & Charge Waiver on Last Active Item Void: voiding last active item marks order cancelled, zeroes charges on order and unpaid bill, and synchronizes delivery charge fr… ✅ pass live ~/.no-mistakes/evidence/01M5EFSYGRA80KNFSNRJP5M1BM/live-scenarios-execution.log
Adversarial Guard - Invalid Manager PIN Rejection: cashier attempts to void preparing item with invalid manager PIN; request is rejected with 403 Forbidden, item remains preparing, and order/bill stat… ✅ pass live ~/.no-mistakes/evidence/01M5EFSYGRA80KNFSNRJP5M1BM/live-scenarios-execution.log
Non-Void Boundary - Pending Item Cancellation by Manager: manager cancels pending item without manager PIN override; stock is restored, item status becomes cancelled, and order is cancelled ✅ pass live ~/.no-mistakes/evidence/01M5EFSYGRA80KNFSNRJP5M1BM/live-scenarios-execution.log
Evidence: Live Scenario Execution Log

=== FLO-CAFE LIVE VALIDATION: ISSUE #1253 (N1) CONCURRENT CHARGE WAIVERS ON ITEM VOID Execution timestamp: 2026-10-21T05:51:27.364Z === Server running live on http://127.0.0.1:62663&#10;&#10;>>> SCENARIO 1: Concurrent Service Charge Waiver during In-Progress Item Void <<< Order ID: 1, Bill ID: 1, Initial bill service_charge: 20 [Action] Cashier voids preparing item with manager PIN 1234 [Event Loop] Manager concurrently waives service_charge while PIN verification is awaiting bcrypt... [Verification] Order subtotal: 100, service_charge: 0 [Verification] Order charges_breakdown service_charge: waived=true, amount=0 [Verification] Bill subtotal: 100, service_charge: 0 [Verification] Bill charges_breakdown service_charge: waived=true, amount=0 ✓ SCENARIO 1 PASSED: Service charge waiver preserved across orders and bills >>> SCENARIO 2: Concurrent Packaging Charge Waiver during In-Progress Item Void <<< Order ID: 2, Bill ID: 2, Initial bill packaging_charge: 10 [Action] Cashier voids preparing item with manager PIN 1234 [Event Loop] Manager concurrently waives packaging_charge while PIN verification is awaiting bcrypt... [Verification] Order subtotal: 100, packaging_charge: 0 [Verification] Order charges_breakdown packaging_charge: waived=true, amount=0 [Verification] Bill subtotal: 100, packaging_charge: 0 [Verification] Bill charges_breakdown packaging_charge: waived=true, amount=0 ✓ SCENARIO 2 PASSED: Packaging charge waiver preserved across orders and bills >>> SCENARIO 3: Concurrent Delivery Charge Update & Charge Waiver on Last Active Item Void <<< [Action] Voiding last active item with manager PIN 1234 [Event Loop] Concurrently waiving packaging charge and updating delivery_charge to 15... [Verification] Order status: cancelled, subtotal: 0, delivery_charge: 15 [Verification] Bill subtotal: 0, delivery_charge: 15 ✓ SCENARIO 3 PASSED: Order cancellation zeroes charges and syncs delivery charge from fresh transaction snapshot >>> SCENARIO 4: Adversarial Guard - Invalid Manager PIN on In-Progress Item Void <<< [Action] Cashier attempts void with incorrect PIN 9999 ✓ SCENARIO 4 PASSED: Invalid manager PIN safely rejected without state mutation >>> SCENARIO 5: Non-Void Item Cancel - Pending Item Cancelled by Manager <<< [Action] Manager cancels pending item without override PIN ✓ SCENARIO 5 PASSED: Pending item cancellation correctly restores stock and cancels order === ALL 5 SCENARIOS COMPLETED AND PASSED WITH VERIFIED PERSISTED STATE ===

================================================================================
FLO-CAFE LIVE VALIDATION: ISSUE #1253 (N1) CONCURRENT CHARGE WAIVERS ON ITEM VOID
Execution timestamp: 2026-10-21T05:51:27.364Z
================================================================================

Server running live on http://127.0.0.1:62663

>>> SCENARIO 1: Concurrent Service Charge Waiver during In-Progress Item Void <<<
Order ID: 1, Bill ID: 1, Initial bill service_charge: 20
  [Action] Cashier voids preparing item with manager PIN 1234
  [Event Loop] Manager concurrently waives service_charge while PIN verification is awaiting bcrypt...
  [Verification] Order subtotal: 100, service_charge: 0
  [Verification] Order charges_breakdown service_charge: waived=true, amount=0
  [Verification] Bill subtotal: 100, service_charge: 0
  [Verification] Bill charges_breakdown service_charge: waived=true, amount=0
  ✓ SCENARIO 1 PASSED: Service charge waiver preserved across orders and bills

>>> SCENARIO 2: Concurrent Packaging Charge Waiver during In-Progress Item Void <<<
Order ID: 2, Bill ID: 2, Initial bill packaging_charge: 10
  [Action] Cashier voids preparing item with manager PIN 1234
  [Event Loop] Manager concurrently waives packaging_charge while PIN verification is awaiting bcrypt...
  [Verification] Order subtotal: 100, packaging_charge: 0
  [Verification] Order charges_breakdown packaging_charge: waived=true, amount=0
  [Verification] Bill subtotal: 100, packaging_charge: 0
  [Verification] Bill charges_breakdown packaging_charge: waived=true, amount=0
  ✓ SCENARIO 2 PASSED: Packaging charge waiver preserved across orders and bills

>>> SCENARIO 3: Concurrent Delivery Charge Update & Charge Waiver on Last Active Item Void <<<
  [Action] Voiding last active item with manager PIN 1234
  [Event Loop] Concurrently waiving packaging charge and updating delivery_charge to 15...
  [Verification] Order status: cancelled, subtotal: 0, delivery_charge: 15
  [Verification] Bill subtotal: 0, delivery_charge: 15
  ✓ SCENARIO 3 PASSED: Order cancellation zeroes charges and syncs delivery charge from fresh transaction snapshot

>>> SCENARIO 4: Adversarial Guard - Invalid Manager PIN on In-Progress Item Void <<<
  [Action] Cashier attempts void with incorrect PIN 9999
  ✓ SCENARIO 4 PASSED: Invalid manager PIN safely rejected without state mutation

>>> SCENARIO 5: Non-Void Item Cancel - Pending Item Cancelled by Manager <<<
  [Action] Manager cancels pending item without override PIN
  ✓ SCENARIO 5 PASSED: Pending item cancellation correctly restores stock and cancels order

================================================================================
ALL 5 SCENARIOS COMPLETED AND PASSED WITH VERIFIED PERSISTED STATE
================================================================================
Evidence: Concurrent Void Charges Verification Report
# Verification Report: Issue #1253 (Finding N1)

## Executive Summary
This report documents the live verification of the fix for **Issue #1253 (Finding N1)** in FloCafe POS.
The issue concerned concurrent charge waivers (such as service charge or packaging charge waivers) or delivery charge updates being overwritten by stale pre-await `order` snapshot data when an in-progress item was voided after awaiting asynchronous manager PIN verification.

The change rebinds charge resolution (`resolveEngineCharges`), fallback charge columns (`service_charge`, `packaging_charge`, `charges_breakdown`), and unpaid bill synchronization (`syncUnpaidBillsForOrder`) to read from the fresh transaction snapshot `currentOrder`.

## Scenarios Driven Live Against Running Server
1. **Scenario 1 - Concurrent Service Charge Waiver during In-Progress Item Void (Pass)**
   - Initial multi-item order with $20 (10%) service charge.
   - Cashier initiated void on preparing item with manager PIN.
   - Concurrently during async bcrypt PIN verification, manager waived service charge on the unpaid bill.
   - Result: Both `orders` and `bills` preserved `service_charge = 0` and `charges_breakdown` with `waived: true, amount: 0`.

2. **Scenario 2 - Concurrent Packaging Charge Waiver during In-Progress Item Void (Pass)**
   - Initial multi-item order with $10 (5%) packaging charge.
   - Cashier initiated void on preparing item with manager PIN.
   - Concurrently during async PIN verification, manager waived packaging charge on the unpaid bill.
   - Result: Both `orders` and `bills` preserved `packaging_charge = 0` and `charges_breakdown` with `waived: true, amount: 0`.

3. **Scenario 3 - Concurrent Delivery Charge Update & Charge Waiver on Last Active Item Void (Pass)**
   - Single-item order with preparing item.
   - Concurrently during async PIN verification, packaging charge was waived and delivery charge was set to $15.
   - Item void triggered entire order cancellation (`orderCancelled === true`).
   - Result: Subtotals and charges zeroed on orders and bills; unpaid bill `delivery_charge` accurately synced to $15 from `currentOrder`.

4. **Scenario 4 - Adversarial Guard: Invalid Manager PIN on In-Progress Item Void (Pass)**
   - Cashier attempted void with invalid PIN '9999'.
   - Result: Rejected with HTTP 403 "Invalid manager PIN", no state mutation, item remains 'preparing'.

5. **Scenario 5 - Non-Void Path: Pending Item Cancellation by Manager (Pass)**
   - Manager cancelled pending item without PIN override.
   - Result: HTTP 200 OK, stock restored to inventory, order cleanly marked 'cancelled'.

## Reproduction & Regression Check
- Reverting `orders.ts` to base commit reproduces failure: `order service_charge remains 0 (waived) - expected 0, got 10` (stale snapshot re-calculated service charge from remaining item, discarding waiver).
- Applying target commit passes all 5 live scenarios and all 84 test assertions in `tests/order-item-cancel-restore.test.ts`.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Concurrent Service Charge Waiver during In-Progress Item Void: cashier voids preparing item with manager PIN while manager concurrently waives service charge on unpaid bill; order and unpaid bill both… ✅ pass live ~/.no-mistakes/evidence/01M5EFSYGRA80KNFSNRJP5M1BM/live-scenarios-execution.log
Concurrent Packaging Charge Waiver during In-Progress Item Void: cashier voids preparing item with manager PIN while manager concurrently waives packaging charge on unpaid bill; order and unpaid bill… ✅ pass live ~/.no-mistakes/evidence/01M5EFSYGRA80KNFSNRJP5M1BM/live-scenarios-execution.log
Concurrent Delivery Charge Update & Charge Waiver on Last Active Item Void: voiding last active item marks order cancelled, zeroes charges on order and unpaid bill, and synchronizes delivery charge fr… ✅ pass live ~/.no-mistakes/evidence/01M5EFSYGRA80KNFSNRJP5M1BM/live-scenarios-execution.log
Adversarial Guard - Invalid Manager PIN Rejection: cashier attempts to void preparing item with invalid manager PIN; request is rejected with 403 Forbidden, item remains preparing, and order/bill stat… ✅ pass live ~/.no-mistakes/evidence/01M5EFSYGRA80KNFSNRJP5M1BM/live-scenarios-execution.log
Non-Void Boundary - Pending Item Cancellation by Manager: manager cancels pending item without manager PIN override; stock is restored, item status becomes cancelled, and order is cancelled ✅ pass live ~/.no-mistakes/evidence/01M5EFSYGRA80KNFSNRJP5M1BM/live-scenarios-execution.log
  • npm run test:order-item-cancel-restore
  • node tests/run-electron-node-test.cjs /tmp/n1-live-scenarios-driver.ts
  • Reproduction check on base commit 08187174bfa47f08154e2b9b64cdb17b0ef2c459 (reproduced failure: order service_charge remains 0 (waived) - expected 0, got 10)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Summary by CodeRabbit

  • Bug Fixes
    • Order item cancellations now use the latest order information when recalculating item, service, packaging, delivery, and charge breakdown amounts.
    • Improved accuracy of order and bill totals when order charges are updated during cancellation or PIN verification.
    • Delivery charges are preserved correctly during item cancellation and restoration.

Read charge resolution and sync parameters from currentOrder instead of stale pre-await order snapshot during item cancel. Fixes #1253.
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 08a65697-047c-4944-9a6c-574a8b51d9a4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: edb6d90f-46dd-4e0f-9b29-090f939b5318
📥 Commits

Reviewing files that changed from the base of the PR and between 0818717 and ec62481.

📒 Files selected for processing: 2
  • main/routes/orders.ts
  • tests/order-item-cancel-restore.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

Order item cancellation now uses the transaction’s current order record to resolve charges and recalculate unpaid bill totals. The expanded tests cover concurrent charge updates during manager-PIN verification and cancellation, restore, authorization, inventory, audit, and transaction behavior.

Changes

Order item cancellation

Layer / File(s) Summary
Use the current order for cancellation charges
main/routes/orders.ts, tests/order-item-cancel-restore.test.ts
Cancellation charge resolution and unpaid bill recalculation use currentOrder. Tests cover concurrent charge updates during manager-PIN verification and characterize cancellation, restore, authorization, inventory, audit, and transaction behavior.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to ec624

No actionable issue remains from this review; the change is mergeable after normal checks.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description clearly explains the fix, scope, risk, and verification results, but it does not follow the repository template. It omits or does not explicitly complete Related work, Summary, Scope, … Reformat the description using the repository template. Add each required heading and complete the missing sections. State the database, migration, user-visible, and offline/network impact; mark applicable cross-cutting surfaces; select the…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes preserving concurrent charge waivers during asynchronous PIN verification, which matches the primary code change.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the fix, scope, risk, and verification results, but it does not follow the repository template. It omits or does not explicitly complete Related work, Summary, Scope, Compatibility & data safety, Screenshots, Cross-cutting surfaces, Developer documentation, and the Contributor checklist.

Resolution

Reformat the description using the repository template. Add each required heading and complete the missing sections. State the database, migration, user-visible, and offline/network impact; mark applicable cross-cutting surfaces; select the appropriate developer-documentation and contributor-checklist items; and state whether screenshots are not applicable.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

@greptile-apps

greptile-apps Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Item cancellation now reads charge decisions and delivery fees from currentOrder, loaded inside withTxn after asynchronous PIN verification.

  • Item voids keep charge changes made during manager PIN checks.

Diagram

sequenceDiagram
  participant Cashier
  participant Void as Item cancellation
  participant PIN as PIN verification
  participant Manager
  participant DB as SQLite
  Cashier->>Void: Void an in-progress item
  Void->>DB: Read initial order
  Void->>PIN: Await approval
  Manager->>DB: Save charge waiver or delivery fee
  PIN-->>Void: Approval succeeds
  Void->>DB: Begin transaction and read currentOrder
  Void->>DB: Void item and recalculate charges
  Void->>DB: Update order and unpaid bills
  Void->>DB: Commit
Loading

Reviews (1) · Last reviewed commit: "no-mistakes(document): Verify docs and f..." · Reviewed by Greptile

@khaira777
khaira777 merged commit f82092c into main Oct 21, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/remediate-n1-void-charges branch October 21, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(orders): preserve concurrently waived charges when voiding an in-progress item

1 participant