ADR-0130 — A magnitude quota is checked against what a write would add
Status: Accepted · Date: 2026-08-30 · Track: 010 phase 04, second slice · Supersedes: nothing · Builds on: ADR-0129
Context
ADR-0129 made what a workspace stores a number the product knows. Nothing
bounded it. The quota registry had fourteen axes and every one of them was a
count of things: links_limit, domains_limit, teams_limit. The machinery
that enforces them is shaped for that — a CountFunc per key, and one
comparison, current >= max.
Bytes are not a count, and the difference is not cosmetic.
Decision
storage_bytes_limit joins models.PlanQuotas as a magnitude axis:
registry-shaped and unseeded, since the ladder and its numbers are 011's. Four
things follow from the unit.
1. The comparison is current + incoming > max, not current >= max.
A count arrives one at a time, so "are you already at the limit" is the whole
test. A magnitude arrives in one piece. Under the count's comparison a workspace
one byte under its allowance accepts a fifty-megabyte archive, because at the
moment of asking it was not yet at the limit. So the check is handed what the
write would add, and refuses the write that would take the workspace past —
never the write that lands exactly on it.
2. The measurement is of the workspace; the allowance is the writer's plan.
Bytes are held by a workspace, which several accounts may write into. A plan is
a property of an account. So MagnitudeFunc takes a scope where CountFunc
takes a user, and CheckStorageBytes takes both. The consequence is worth
stating plainly rather than discovering: in a shared workspace, a member whose
plan sells more storage can fill a workspace whose other members' plans sell
less. That is the same shape every other quota already has — the acting
account's plan gates the acting account's write — and making the workspace's
bound a property of some other account's plan would be a product call this
track does not own.
3. The amount is measured by the product, before the first byte is written.
010's rule holds here as everywhere: nothing the artifact contains decides
anything. A file link is charged header.Size, which is the multipart reader's
own count of bytes taken off the wire, not a length the sender declared. A
bundle is charged the archive plus what InspectBundle measured its entries
coming to when it read them — the directory's UncompressedSize64 is already
refused where it disagrees with the read, and it is not what is charged. So
InspectBundle now returns that total, and the bound is asked before
ExpandBundle writes anything: a refusal is the whole upload, with no row, no
archive and no expansion.
4. A replacement is charged the difference. The write swaps bytes rather
than adding them — the row's recorded figure is overwritten and the old
expansion is freed on the same path — so the resource's current stored_bytes
is credited, read before the write. Without it, a workspace at its allowance
could never replace a document with one the same size.
The gate is widened to follow the family rather than the spelling:
check-entitlement-parity's Q1/Q2 anchor becomes planLimitSvc.Register\w*(
and Q4's becomes .check\w*(. A magnitude axis registered and checked is
exactly as listed, consulted and callable as a count, and one that is not is
exactly as much a failure.
The ceiling ValidatePlanQuotas enforces becomes per axis. maxPlanQuota
is a billion for a narrowing reason — the count path narrows to int, and a
value past MaxInt64 converts to a negative one — and neither the reason nor
the scale carries over: a billion is a generous number of short links and a
small allowance of storage. The bytes axis states its own, 1 TiB, and the whole
magnitude path is int64.
What is not decided here
What a plan may store. No number is seeded anywhere. An unset quota
unlimits, which is the quota family's settled fail-open (004, and
services/plan_limits.go's own comments) and the deliberate opposite of a
capability's default deny: the owner has not sold a ceiling yet, and a ceiling
this track invented would be one. The charter's Blocker 2 stands.
Freeing on delete. The bound reads a derived sum, so it corrects itself the moment the rows do. Making a DELETE move that number is phase 04's third slice.
Consequences
- A deployment that sets
storage_bytes_limiton a plan bounds every hosted kind at once, because all five arelinksrows withstored_bytes. PlanLimitError.Current/Maxwiden toint64. The JSON shape is unchanged; a byte figure narrowed tointwould report a different number than the one it refused on whereverintis 32 bits.- The two handlers that write bytes take
StorageLimiter, notPlanLimiter: the only axis they can reach is the one they must consult. - Unwired, the bound does not apply. That is the quota family's behaviour, not
this axis's choice, and it is why
requireCapabilityrefuses when unwired while this does not.
Source: docs/decisions/0130-a-magnitude-quota-is-checked-against-what-a-write-would-add.md