Space quota (v0.6.300): cap overshoot under encryption; delete refused in a full space #806

Closed
opened 2026-09-28 05:58:34 +00:00 by Cordy · 1 comment
Owner

Found in the live check of #802 on Bao (cap 1 MiB on app-owned-space, test files since deleted, cap cleared).

  1. Overshoot:
    • 600 KiB fit; the next 600 KiB was correctly refused (507); a same-size overwrite passed.
    • But then 400 KiB + 30 KiB were both accepted, leaving 1,054,720 plaintext bytes (1,068,217 stored) under a 1,048,576 cap.
    • Cause: the usage walk counts stored bytes (encryption overhead and sidecars, ~1.3% here), while writes were credited in plaintext bytes, and overwrite netting subtracted a stored size. Within one 30 s cache window the cache undercounted by ~25 KiB. The per-user cap had the same drift before #802.
  2. Delete refused in a full space (507):
    • Space trash lives at /spaces/<d>/.trash/ and the trash layer writes a .meta file before moving the data. That write counted as growth, so a full space could not delete anything. This is the worst possible trap.

Fix:

  • Credit writes in stored units (stat after write).
  • Treat /spaces/<d>/.trash like personal trash, which is already uncharged: excluded from the space's usage and not capped.
  • A move into trash frees the room immediately.
  • A restore from trash into the space is checked like any move in.

Remaining bound, to be documented in #804: a single write can overshoot by the storage overhead of that write, because the stream is measured in plaintext.

Found in the live check of #802 on Bao (cap 1 MiB on `app-owned-space`, test files since deleted, cap cleared). 1. **Overshoot:** - 600 KiB fit; the next 600 KiB was correctly refused (507); a same-size overwrite passed. - But then 400 KiB + 30 KiB were both accepted, leaving 1,054,720 plaintext bytes (1,068,217 stored) under a 1,048,576 cap. - **Cause:** the usage walk counts *stored* bytes (encryption overhead and sidecars, ~1.3% here), while writes were credited in *plaintext* bytes, and overwrite netting subtracted a stored size. Within one 30 s cache window the cache undercounted by ~25 KiB. The per-user cap had the same drift before #802. 2. **Delete refused in a full space (507):** - Space trash lives at `/spaces/<d>/.trash/` and the trash layer writes a `.meta` file before moving the data. That write counted as growth, so a full space could not delete anything. This is the worst possible trap. **Fix:** - Credit writes in stored units (stat after write). - Treat `/spaces/<d>/.trash` like personal trash, which is already uncharged: excluded from the space's usage and not capped. - A move into trash frees the room immediately. - A restore from trash into the space is checked like any move in. Remaining bound, to be documented in #804: a single write can overshoot by the storage overhead of that write, because the stream is measured in plaintext.
Cordy closed this issue 2026-09-28 06:02:09 +00:00
Author
Owner

Verified live on Bao, v0.6.301 (cap 1 MiB on app-owned-space; test files deleted and cap cleared afterwards):

  • Usage starts at 0 even though the space's trash holds the earlier test files (trash not charged).
  • 600 KiB → 201 (usage 621,108 stored bytes, credited in stored units) · second 600 KiB → 507 · same-size overwrite → 201 · 400 KiB → 201 · 30 KiB → 507 (previously accepted past the cap).
  • Delete in the full space → 204. Usage dropped at once by exactly the file's stored size; the 30 KiB upload then fit (201).
  • After the 30 s cache window, a fresh walk gave 655,174 vs the cached ~652 K: within a few KiB (sidecars). Consistent.
Verified live on Bao, **v0.6.301** (cap 1 MiB on `app-owned-space`; test files deleted and cap cleared afterwards): - Usage starts at 0 even though the space's trash holds the earlier test files (trash not charged). - 600 KiB → 201 (usage 621,108 stored bytes, credited in stored units) · second 600 KiB → **507** · same-size overwrite → 201 · 400 KiB → 201 · 30 KiB → **507** (previously accepted past the cap). - Delete in the full space → **204**. Usage dropped at once by exactly the file's stored size; the 30 KiB upload then fit (201). - After the 30 s cache window, a fresh walk gave 655,174 vs the cached ~652 K: within a few KiB (sidecars). Consistent.
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#806
No description provided.