mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
The arrival-reaction claim carried its own copy of the reservation upsert so the write could ride the claim transaction. The copy drifted: it learned to write operator_tokens and kept gating on the day's mixed total, at the halved background ceiling. On the row the wave was written for, 1.2 million tokens served by the user's own plan, the reaction was refused all day at half the old ceiling, reproducing the defect the wave exists to remove on the one surface it forgot to convert. reserveBudget now takes the transaction client, so both writes still roll back together and there is no second copy left to drift. The row also remembers who paid for its reservation. The supersede refund in data-arrival has no chain to ask and could only reverse the total, so the operator share of every superseded reservation stayed on the row forever, walking the operator's ceiling upward against spend that never happened. A supersede is routine, not an edge case: any second measurement of the same kind on the same local date before the worker runs. The resume path re-derived the owner from a chain the health ledger may have reordered since, which leaks the same way or drains another request's balance. A structural guard makes the invariant executable. Every INSERT column list, SET clause and RETURNING list that names one counter must name the other, and the set of files holding raw ledger SQL is pinned. Both defects above were a grep away and both would have failed this test.