Documentation Index
Fetch the complete documentation index at: https://docs.laportenard.com/llms.txt
Use this file to discover all available pages before exploring further.
How conflicts happen
Even with leases, version conflicts can occur:- A terminal sends
ORDER_SNAPSHOT { baseVersion: 3 }but the hub already has version 4 - A terminal reconnects after a network drop and sends a stale snapshot
- Two terminals briefly hold overlapping leases during the disconnect grace period
Version tracking
Every order in the hub has an auto-incrementing version number:ORDER_SNAPSHOT { baseVersion }:
- Hub compares
baseVersionagainst the stored version - If
baseVersion >= storedVersion: accept, increment version, broadcast - If
baseVersion < storedVersion: reject, sendCONFLICT { hubVersion, hubSnapshot }
Hub-side conflict detection
Innu_pos_hub/src/handlers/orderHandler.ts:
Frontend reconciliation
When the terminal receives aCONFLICT message, reconcile() in nu_pos_react/src/realtime/sync/reconcile.ts decides what to do.
Strategies
| Strategy | When used | Action |
|---|---|---|
accept_remote | No local changes, paid orders, far behind | Replace local state with hub snapshot |
merge | Local has new line additions, 1 version behind | Append local-only lines to hub snapshot |
keep_local | (Reserved for future use) | Re-send local version (requires version bump) |
Decision flow
Merge logic
When a merge is possible (terminal is exactly 1 version behind with local-only line additions):Find local-only lines
Find local lines whose IDs are not in the remote set (these are new additions)
Example
UI integration
When a conflict occurs, theSyncUIProvider shows a ConflictDialog:
- “Load Latest” — Calls
reconcile()withaccept_remote, replaces local order state - “Keep Mine” — User decides to discard the remote and try to re-send (rare)
Conflict prevention
The best conflict resolution is prevention. The system minimizes conflicts through:- Leases — Only the lease holder can submit snapshots
- Heartbeats — Keep leases alive during active editing
- Optimistic versioning — Send
baseVersionwith every snapshot so the hub can detect staleness - Instant broadcast — Other terminals see changes in real-time, reducing the window for stale edits