Skip to content

fix(checkout): generate bills from a consistent order snapshot #254

Closed as not planned

Description

@khaira777

Summary

Bill generation can use an order snapshot read before its transaction, allowing a concurrent order mutation to produce a bill that does not match the committed order totals.

Current behavior

main/routes/bills.ts:163-245 reads the order before acquiring the transaction and creates or synchronizes the bill from that object. Concurrent discount, item-add, or cancellation work can commit between the read and bill write.

Expected behavior

Bill generation must snapshot the authoritative order state atomically and preserve a consistent subtotal, tax, discount, and total relationship.

Acceptance criteria

  • Re-read or version-check the order inside the bill transaction.
  • Define behavior for concurrent item, discount, cancellation, and payment mutations.
  • Add concurrency tests asserting that the generated bill matches the committed order snapshot.
  • Preserve existing tax snapshot and rounding contracts.

Relevant files

main/routes/bills.ts, main/routes/orders.ts

Activity

  1. added
    area:backend
    on Aug 11, 2026
  2. khaira777 commented on Aug 12, 2026

    @khaira777
    ContributorAuthor

    Investigated against main at 241d6ca / FloCafe 3.0.5.

    The reported race could not be reproduced. Bill generation does read the order before withTxn(), but the current runtime uses a single synchronous better-sqlite3 connection, with no event-loop yield between that read and the transaction. Concurrent HTTP mutation attempts were therefore serialized and did not produce a mixed bill/order snapshot.

    Relevant existing suites also pass:

    • test:integration-reconciliation — 22/22
    • test:integration-payments — 33/33
    • test:integration-lifecycle — 18/18

    Reading the order inside the transaction would be cleaner as defense-in-depth, but it does not fix a demonstrated production bug in the current architecture. If FloCafe later introduces async DB access, multiple writer connections, or multiple writer processes, transaction and locking semantics should be reviewed as part of that architecture change.

    Closing as not reproducible under the current supported runtime.

  3. self-assigned this
    on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:backend

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions