Skip to content

fix(main): include closing-second unpaid bills in shift-close guard - #1278

Merged
khaira777 merged 4 commits into
mainfrom
fm/ship-r4-cash-session-close-guard
Oct 21, 2026
Merged

khaira777 merged 4 commits into
mainfrom
fm/ship-r4-cash-session-close-guard

Conversation

@khaira777

@khaira777 khaira777 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1275

Intent

Fix the closing-second unpaid bill guard defect from the FloCafe 3.13.1 release-readiness audit at 36575453 (Issue #1275):

  • [P2] Include already-committed bills in the closing-second unpaid guard (main/routes/cash-sessions.ts:125, Issue fix(cash-sessions): include closing-second unpaid bills in shift-close guard #1275): Shift closing can miss unpaid bills created in the closing second. now() in main/db.ts uses 1-second timestamp strings (YYYY-MM-DD HH:MM:SS). In closeSessionTxn (main/routes/cash-sessions.ts:125), the unpaid-bill guard checks b.created_at >= ? AND b.created_at < ? (closedAt). Because closeSessionTxn runs inside a serialized SQLite transaction (withTxn), any bills row visible to that query was already committed before the close transaction began, so < closedAt excludes unpaid or partially paid bills committed during the same wall-clock second (b.created_at === closedAt), allowing POST /api/cash-sessions/:id/close to return 200 and close the shift with an open balance. Change the unpaid-bill close guard upper bound to b.created_at <= ? (closedAt) while keeping financial reporting period intervals half-open (< closedAt) or cash_session_id-attributed so adjacent shifts never double-count.

What Changed

  • Updated the unpaid-bill close guard query in closeSessionTxn (main/routes/cash-sessions.ts) to use an inclusive upper bound (b.created_at <= ?), preventing unpaid or partially paid bills committed during the closing second from bypassing the shift close block.
  • Updated docs/reference/api.md to document the POST /api/cash-sessions/:id/close request payload, response shape, and 409 unpaid_bills_remaining error condition.
  • Added backend tests in tests/cash-sessions.test.ts covering closing-second and preceding-second unpaid or partially paid bills, and an E2E test in frontend/e2e/cashier-status-bar.spec.ts verifying the shift-close modal displays the 409 error banner and keeps the shift open.

Risk Assessment

✅ Low: The change surgically adjusts the shift-close unpaid-bill query upper bound to inclusive (<= closedAt) to prevent closing-second unpaid bills from slipping through, preserves half-open reporting intervals, and includes focused API and E2E regression tests with proper cleanup.

Testing

Exercised the inclusive closing-second unpaid bill guard across 5 live scenarios against the running FloCafe Express API server and Next.js POS UI in Chromium. Verified same-second unpaid and partial bills trigger HTTP 409 unpaid_bills_remaining and leave the shift open; verified same-second cancelled orders and paid bills permit closure (HTTP 200); verified adjacent shifts remain isolated without double-counting; and verified the POS ShiftCloseModal displays the error banner, captured in evidence screenshot r4-shift-close-unpaid-guard.png. All 5 scenarios passed.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Cashier attempts to close an active shift when an unpaid bill was committed in the exact same closing second (b.created_at === closedAt); the backend rejects closure with HTTP 409 unpaid_bills_remaini… ✅ pass live Live HTTP execution against running FloCafe server (POST /api/cash-sessions/:id/close returned HTTP 409 with display_code: 'unpaid_bills_remaining' when startSec === closeSec === 1792613608 and billCr…
Cashier attempts to close an active shift when a partially paid bill with positive remaining balance was committed in the same closing second; the backend rejects closure with HTTP 409 unpaid_bills_re… ✅ pass live Live HTTP execution against running FloCafe server (POST /api/cash-sessions/:id/close returned HTTP 409 with display_code: 'unpaid_bills_remaining' for partial cash tender with remaining balance 44.2)…
Cashier closes an active shift when bills committed in the closing second are either cancelled orders or fully settled; the backend returns HTTP 200 with closure details and includes same-second cash… ✅ pass live Live HTTP execution against running FloCafe server (POST /api/cash-sessions/:id/close returned HTTP 200 with closure_id: 1, expected_cash_cents: 7420, variance_cents: 0) and `npm run test:cash-session…
Cashier opens and closes an adjacent shift immediately after shift closure at the boundary second; Shift 2 closes cleanly with HTTP 200 and does not double-count or inherit prior shift tenders ✅ pass live Live HTTP execution against running FloCafe server (POST /api/cash-sessions/open and POST /api/cash-sessions/:id/close returned HTTP 200 with expected_cash_cents: 500 matching opening float) and `npm…
Cashier opens the Shift Close modal in the POS UI with an outstanding unpaid bill; the UI renders the 409 error banner preventing shift close and keeping the shift open, and allows closing once the bi… ✅ pass live ~/.no-mistakes/evidence/01M5G14GDPW49WYFWQGQV93AJP/r4-shift-close-unpaid-guard.png and `cd frontend && npx playwright test e2e/cashier-status-bar.spec.ts -g 'shift-close modal surf…
Evidence: Live Server Same-Second Shift Close Execution Log
=== Scenario 1: Same-second Unpaid Bill Close Guard ===
HTTP status: 409
Response body: {
error: 'Cannot close: 1 unpaid bill(s) in this shift',
reason_code: 'cash.session_rejected',
operation: 'cash.session.close',
stage: 'validation',
classification: 'expected_rejection',
outcome: 'not_applied',
correlation_id: '274d1223-2f3b-41fe-a709-6d2901cd7b58',
display_code: 'unpaid_bills_remaining'
}
Timing: {
startSec: 1792613608,
closeSec: 1792613608,
billCreatedAt: '2026-10-21 20:13:28',
sameSecond: true
}
Shift status after unpaid close attempt: open

=== Scenario 2: Partial Payment Close Guard ===
Partial bill close HTTP status: 409
Partial bill close response: {
error: 'Cannot close: 1 unpaid bill(s) in this shift',
reason_code: 'cash.session_rejected',
operation: 'cash.session.close',
stage: 'validation',
classification: 'expected_rejection',
outcome: 'not_applied',
correlation_id: 'baa4a07b-f8b4-461b-9999-05220af3ceaf',
display_code: 'unpaid_bills_remaining'
}
Shift status after partial close attempt: open

=== Scenario 3: Cancelled Order & Paid Bill Permitted ===
Settled shift close HTTP status: 200
Settled shift close response: {
closure_id: 1,
variance_cents: 0,
expected_cash_cents: 7420,
counted_cash_cents: 7420
}
Current shift after successful close: null

=== Scenario 4: Adjacent Shifts Isolation ===
Shift 2 close HTTP status: 200
Shift 2 close response: {
closure_id: 2,
variance_cents: 0,
expected_cash_cents: 500,
counted_cash_cents: 500
}
![POS Shift Close Modal Unpaid Bills Error Banner](https://github.com/user-attachments/assets/c801f4f4-132a-4697-87c1-3f9ed026e04e)

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
Cashier attempts to close an active shift when an unpaid bill was committed in the exact same closing second (b.created_at === closedAt); the backend rejects closure with HTTP 409 unpaid_bills_remaini… ✅ pass live Live HTTP execution against running FloCafe server (POST /api/cash-sessions/:id/close returned HTTP 409 with display_code: 'unpaid_bills_remaining' when startSec === closeSec === 1792613608 and billCr…
Cashier attempts to close an active shift when a partially paid bill with positive remaining balance was committed in the same closing second; the backend rejects closure with HTTP 409 unpaid_bills_re… ✅ pass live Live HTTP execution against running FloCafe server (POST /api/cash-sessions/:id/close returned HTTP 409 with display_code: 'unpaid_bills_remaining' for partial cash tender with remaining balance 44.2)…
Cashier closes an active shift when bills committed in the closing second are either cancelled orders or fully settled; the backend returns HTTP 200 with closure details and includes same-second cash… ✅ pass live Live HTTP execution against running FloCafe server (POST /api/cash-sessions/:id/close returned HTTP 200 with closure_id: 1, expected_cash_cents: 7420, variance_cents: 0) and `npm run test:cash-session…
Cashier opens and closes an adjacent shift immediately after shift closure at the boundary second; Shift 2 closes cleanly with HTTP 200 and does not double-count or inherit prior shift tenders ✅ pass live Live HTTP execution against running FloCafe server (POST /api/cash-sessions/open and POST /api/cash-sessions/:id/close returned HTTP 200 with expected_cash_cents: 500 matching opening float) and `npm…
Cashier opens the Shift Close modal in the POS UI with an outstanding unpaid bill; the UI renders the 409 error banner preventing shift close and keeping the shift open, and allows closing once the bi… ✅ pass live ~/.no-mistakes/evidence/01M5G14GDPW49WYFWQGQV93AJP/r4-shift-close-unpaid-guard.png and `cd frontend && npx playwright test e2e/cashier-status-bar.spec.ts -g 'shift-close modal surf…
  • npm run build
  • npm run build:frontend
  • npm run test:cash-sessions
  • npm run test:cash-closures
  • cd frontend && npx playwright test e2e/cashier-status-bar.spec.ts --project=chromium
  • Live HTTP boundary validation against standalone FloCafe server on http://localhost:3001
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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: 1c6df3dd-a0ce-4e10-a9f2-2d7de793f233

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
  • 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 new actionable issue was found.

Summary

The unpaid-bill check now includes bills created in the closing second, without changing financial reporting ranges.

  • Shift close now catches unpaid bills from its closing second.

Reviews (2) · Last reviewed commit: "fix(cash-sessions): address review feedb..." · Reviewed by Greptile

Comment thread frontend/e2e/cashier-status-bar.spec.ts Resolved
Comment thread frontend/e2e/cashier-status-bar.spec.ts Resolved
Comment thread tests/cash-sessions.test.ts Resolved
…e guard

Include already-committed bills in the closing-second unpaid guard by
changing the upper bound to <= closedAt, preventing shifts from closing
with open unpaid or partially paid balances.

Fixes #1275
@khaira777
khaira777 force-pushed the fm/ship-r4-cash-session-close-guard branch from 28a9915 to 801f5ca Compare October 21, 2026 20:17
@khaira777

Copy link
Copy Markdown
Contributor Author

@greptileai review this at apex

@khaira777
khaira777 merged commit 42d699d into main Oct 21, 2026
24 checks passed
@khaira777
khaira777 deleted the fm/ship-r4-cash-session-close-guard branch October 21, 2026 20:30
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(cash-sessions): include closing-second unpaid bills in shift-close guard

1 participant