mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
The mint's rate limit bounds a burst and does nothing about accumulation: a stuck automation retrying politely inside its 10-per-minute allowance still leaves several hundred live credentials behind in an afternoon, each one to be revoked by hand. Count live rows before the create and refuse at ten. Live, not minted-ever, so revoking frees a slot and an expired token stops occupying one — the ceiling bounds what currently exists rather than what the account has ever done. Scoped to measurements:write for a reason worth stating: signing in mints a wildcard access token per session and those accumulate on their own, so counting every row would let ordinary browser use exhaust the budget and then refuse a mint for a reason invisible to the person hitting it. 409 rather than 429. This is a conflict with the account's current state, not a rate: it does not clear by waiting, it clears by revoking, and a 429 would tell the caller the opposite of what is true. Placed after validation, so a malformed request hears about the malformation rather than the ceiling, and before the create, so hitting the limit costs no credential. Ten is set to catch a loop rather than to ration — a household running Home Assistant, a scale bridge and a couple of scripts sits at three or four, and it is not a security boundary since the holder can revoke and mint freely. Tests pin the boundary, the query shape and the ordering, and were mutation-checked: turning >= into > fails the ceiling case, and dropping the scope filter fails the query-shape case. The integration leg seeds a wildcard and an expired row as decoys, then revokes one live token and asserts exactly one slot opens — the leg that fails if the count is of mints rather than of tokens alive.