mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 04:50:59 +00:00
A delegate retrying with one `Idempotency-Key` across two people's records met itself in one cell. The cache tuple was `(caller, key, method, path)`, so the second record's request replayed the first record's cached 201: the handler never ran, no row was written for the second person, and the caller was told it had been — with the other person's id in the body. Nothing errored and nothing logged a conflict, and five of the write verbs about to become delegable are wrapped here. Fold the claimed record into the `key` component, centrally, once. Not into `userId`: that column is a foreign key to `users` with a cascade behind it and cannot hold a composite. It keeps naming the caller, which is what makes two delegates on one record two cells for free. The separator is a byte the key validator refuses, so a caller cannot hand-craft a key into a cell belonging to a request they are not making. A request with no acting account keys byte-for-byte as it did before, so a client that never heard of sharing cannot be affected. Accepted and pinned by test: the fold uses the CLAIM, before the grant check, so within the 24h window a delegate whose access has ended can still replay a key they had already completed. They receive bytes they already had, nothing new is written, and a fresh key from them is refused because that request reaches the handler. Both frozen surfaces move in this diff. The claim reader gains a guard leg freezing its consumers, since an unchecked claim is exactly the value a future caller must not mistake for permission.