Per-space quota limits: set, enforce, show remaining #767

Closed
opened 2026-09-26 04:37:33 +00:00 by Cordy · 2 comments
Owner

The server-heavy half of #695 round 13, split out of #765 by design.

Usage display shipped in v0.6.285 (measured bytes from the SpaceSizes background sweep). A limit is a different animal — the number "remaining" is a lie unless writes actually stop at the cap, so this issue owns the whole chain:

  • Model: Quota *int64 on spacestore.Space (nil = unlimited), admin-set only.
  • Admin surface: set/clear per space in the Spaces inventory (the #765 drawer/dialog pattern extends naturally).
  • Enforcement: the write path must refuse when usage + incoming would exceed the cap. Design questions to settle first: which usage number enforces (the background sweep is up to spaceSizeEvery stale — probably a live check on the space subtree at write time, or sweep-value plus a running delta), what tus/multipart uploads do at the boundary, and what the client sees (413 with an honest message; the upload UI should surface it).
  • Display: "X of Y used" / remaining in the space details and admin inventory, replacing the bare usage row where a limit exists.
  • Interaction with per-user quota: a space cap and the owner's personal quota are independent; document which one refuses first.

Design pass before implementation — this touches the hot write path.

The server-heavy half of #695 round 13, split out of #765 by design. Usage display shipped in v0.6.285 (measured bytes from the `SpaceSizes` background sweep). A *limit* is a different animal — the number "remaining" is a lie unless writes actually stop at the cap, so this issue owns the whole chain: - **Model:** `Quota *int64` on `spacestore.Space` (nil = unlimited), admin-set only. - **Admin surface:** set/clear per space in the Spaces inventory (the #765 drawer/dialog pattern extends naturally). - **Enforcement:** the write path must refuse when usage + incoming would exceed the cap. Design questions to settle first: which usage number enforces (the background sweep is up to `spaceSizeEvery` stale — probably a live check on the space subtree at write time, or sweep-value plus a running delta), what tus/multipart uploads do at the boundary, and what the client sees (413 with an honest message; the upload UI should surface it). - **Display:** "X of Y used" / remaining in the space details and admin inventory, replacing the bare usage row where a limit exists. - **Interaction with per-user quota:** a space cap and the owner's personal quota are independent; document which one refuses first. Design pass before implementation — this touches the hot write path.
Author
Owner

Design pass (agreed with Nikola 2026-09-28)

Existing machinery (main @ 5ab87f76): internal/storage/quota already enforces the instance cap and per-user caps at the write chokepoint. It sits below scope, so it sees backend paths. Usage comes from a 30 s-TTL tree-walk cache per prefix, credited on every write, with a stream cap via limitedReader. ErrQuotaExceeded already maps to 507 in REST, WebDAV and tus finalize, and the web tus client already reports it. Both space kinds live at /spaces/<backendDir>. Gap: Copy/Rename bypass the decorator (true for per-user caps today too).

Decisions

  1. Caps live in a new ID-keyed store (spacequota.json, spacemeta shape): they work for app-owned AND directory spaces and survive renames.
  2. Admin-only set/clear; members and owners see it.
  3. Enforcing number = the per-user mechanism (live walk, 30 s cache + write credit), not the 24 h sweep.
  4. Copy/Move into a capped prefix is pre-checked against the room left. The same code closes the per-user hole.
  5. A cap below current usage is allowed. The space refuses growth; deletes work. Overwrites are charged net of the replaced file (see 767a), so editing in a full space works while it doesn't grow.
  6. A backend path is either /home/<u> or /spaces/<d>, so a space write is never charged to the uploader's personal quota. Order: instance cap → the matching prefix cap.
  7. New spaces created through Cairn get a 1 GB (1 GiB) cap (hard-coded for now; #800 makes it an admin setting). Existing spaces and directory spaces first sighted by the registry stay unlimited.

Slices: #802 (767a server) → #803 (767b UI) → #804 (767c upload UX + docs). Out of scope, cut separately: #800 (default-quota setting), #801 (owner limits + notifications research).

## Design pass (agreed with Nikola 2026-09-28) **Existing machinery (main @ 5ab87f76):** `internal/storage/quota` already enforces the instance cap and per-user caps at the write chokepoint. It sits below scope, so it sees backend paths. Usage comes from a 30 s-TTL tree-walk cache per prefix, credited on every write, with a stream cap via `limitedReader`. `ErrQuotaExceeded` already maps to **507** in REST, WebDAV and tus finalize, and the web tus client already reports it. Both space kinds live at `/spaces/<backendDir>`. **Gap:** `Copy`/`Rename` bypass the decorator (true for per-user caps today too). **Decisions** 1. Caps live in a new **ID-keyed store** (`spacequota.json`, spacemeta shape): they work for app-owned AND directory spaces and survive renames. 2. **Admin-only** set/clear; members and owners see it. 3. Enforcing number = the per-user mechanism (live walk, 30 s cache + write credit), not the 24 h sweep. 4. Copy/Move into a capped prefix is pre-checked against the room left. The same code closes the per-user hole. 5. A cap below current usage is allowed. The space refuses growth; deletes work. Overwrites are charged net of the replaced file (see 767a), so editing in a full space works while it doesn't grow. 6. A backend path is either `/home/<u>` or `/spaces/<d>`, so a space write is never charged to the uploader's personal quota. Order: instance cap → the matching prefix cap. 7. **New spaces created through Cairn get a 1 GB (1 GiB) cap** (hard-coded for now; #800 makes it an admin setting). Existing spaces and directory spaces first sighted by the registry stay unlimited. **Slices:** #802 (767a server) → #803 (767b UI) → #804 (767c upload UX + docs). Out of scope, cut separately: #800 (default-quota setting), #801 (owner limits + notifications research).
Author
Owner

All slices shipped and verified live: #802 (v0.6.300, server), #806 (v0.6.301, stored-byte credits + trash uncharged, found in the live check), #803 (v0.6.302, UI), #810 (v0.6.303, "3 GB" not "3.0 GB"), #804 (v0.6.304, up-front all-or-nothing refusals, banner dismiss, handbook spaces-quota.md).

Follow-ups in v0.7: #800 (admin setting for the new-space default, today 1 GB), #801 (owner-set limits + notifications, researched), #808 (multi-select directory spaces; disabled Deactivate with explanation).

**All slices shipped and verified live:** #802 (v0.6.300, server), #806 (v0.6.301, stored-byte credits + trash uncharged, found in the live check), #803 (v0.6.302, UI), #810 (v0.6.303, "3 GB" not "3.0 GB"), #804 (v0.6.304, up-front all-or-nothing refusals, banner dismiss, handbook `spaces-quota.md`). Follow-ups in v0.7: #800 (admin setting for the new-space default, today 1 GB), #801 (owner-set limits + notifications, researched), #808 (multi-select directory spaces; disabled Deactivate with explanation).
Cordy closed this issue 2026-09-28 16:30:09 +00:00
Sign in to join this conversation.
No labels
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#767
No description provided.