mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 04:32:42 +00:00
Review of the slot-convergence change surfaced gaps that could mis-record a dose. Fold the write logic into one shared `applyCanonicalSlotWrite` used by both intake routes and close them: - Concurrency: catch the unique-key race on insert and converge by re-finding the slot row and updating it, instead of returning 500 (and dropping the tap) or leaving a duplicate. - No downgrade: a pending projection echo replayed onto a slot already marked taken or skipped is a no-op — it never clears `takenAt`. A recorded dose is immutable, so an offline re-sync cannot flip a taken dose back to missed. - Inventory: decrement a medication's remaining count only on a genuine pending→taken transition, not on an idempotent re-post. - Deterministic slot-row selection: prefer an existing actioned row, then the pending row, ordered by createdAt then id. - Snap instant: derive the canonical instant via the same `localHmAsUtc` the projector and reminder worker mint with, so the value is identical by construction across a DST transition rather than only test-pinned. - Cleanup job: isolate each slot's collapse in its own try/catch and guard the instant-normalisation against a tombstone collision, so one slot can no longer dead-letter a user's whole dedup pass.