bug: dispense result mapping uses wrong index (amounts order vs cassette position) #6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
brain.jsmaps dispense results by iterating over the requested amounts array and indexing into the hardware result array by the same index. But these two arrays use different ordering:amounts(the input): ordered by whatever the state machine sends (denomination order)result.value(from hardware): always ordered by physical cassette positionIf the amounts array and cassette positions don't align (e.g. cassette 0 = $5, cassette 1 = $20, but amounts requests $20 first), the dispensed/rejected counts get swapped between denominations.
Affected Code
lamassu-machine
lib/brain.js—_physicalDispenseand_batchesFinished:The dispense result from the hardware driver (e.g. F56) returns an array indexed by cassette position. When mapping back to denominations, the code assumes the input amounts array has the same ordering as the cassette positions — which is only true when denominations happen to be requested in cassette order.
Impact
dispensed_1/dispensed_2incash_out_txsmay show swapped countsIn practice this is often masked because many deployments use a single denomination or cassettes happen to be loaded in the same order as the sort. But multi-denomination setups with non-ascending cassette loading will silently misattribute results.
Fix
Map results by cassette position (matching the hardware driver's indexing), then look up which denomination each cassette holds:
Context
Found and fixed in lamassu-next (
feat/record-failed-dispensebranch) in bothapps/machine/src/services/hal.tsandapps/machine/electron/hal-service.ts. The same pattern exists in lamassu-machine's brain.js.