Unreferenced attachments are listed and collected after a week #16

Merged
backmeupplz merged 8 commits from board/977-d199dc into main 2026-11-27 22:03:59 +00:00
Owner

Ticket: https://agentboard.icefish-betta.ts.net/#977 (follow-up from the PR #12 review).

Built on #12, which has merged. This PR is now rebased on main, including #17 (padded attachments), and Forgejo retargeted it there.

What changes

  • GET /v1/vaults/{id}/files lists a vault's uploaded files with their ids and sealed sizes (the bytes the quota counts), whether or not an item lists them. Writers and above can call it; readers get 403, and non-members get 404 as on every other vault route.
  • Unreferenced attachments are collected after a week. Each writer's device does this right after a pull in sync, including a sync that ends in 409 or 413, since both come after a pull.
    • Over quota, collecting is what makes room for a change the server refused.
    • The device lists the vault's files and notes the ones no item refers to.
    • "Refers to" covers current fields, earlier versions in history, and the server's copy of an item with an edit or delete still pending here (Vault::base_files).
    • Each note keeps the time this device first saw the file unreferenced.
    • A file is deleted once it has stayed unreferenced for FILE_GRACE (7 days).
    • If the device hasn't looked for more than two graces, all notes start over, so old notes never count.
    • The notes live in the vault snapshot. The new fields use #[serde(default)], so old snapshots restore. An old snapshot with a pending change and no base files skips collection.
    • Readers never collect. Short-lived agent runs, which keep no snapshot, don't either.
    • Collection errors never fail sync.
    • The rule is in core (Vault::collect_files, Item::file_ids). The client adds Session::files and pub(crate) Session::collect_files(vault, now).
  • delete_item no longer deletes attachments right away. Another device that brings the item back with an unpushed edit (local edits win the merge) now keeps its files.
  • CLI attach deletes the fresh upload only after a 4xx. After a network error or a proxy's 5xx the push may have landed, so a later sync collects the file instead.
  • The 413 message and DESIGN.md now say that attachments are freed a week later. DESIGN.md has a new "Attachments" section, which states the one-week limit cases, and a new API row. PARITY.md has a note too.

Trade-offs

  • Quota: over quota, deleting an item frees its blob at once but its attachments only after the grace.
  • Requests: collecting costs one more request per writable vault on every sync.
  • Tuning: FILE_GRACE is one constant.

Tests

  • New file_garbage_collection test in client/src/tests.rs:
    • Writers can list. Readers get 403 and non-members 404.
    • An unpushed upload is collected only after the grace, and a note survives the snapshot round trip.
    • A gap of more than two graces resets the notes.
    • Files in history and in current fields survive, and readers don't collect.
    • A pending local delete keeps the server copy's files.
    • Another device's unpushed edit restores a deleted item, and its attachment still downloads afterwards.
    • Snapshots without the new fields restore.
  • storage_quota:
    • After delete_item the file stays.
    • A sync that hits a 413 still notes the file, and it's collected past the grace.
    • The refused change then goes through.
  • Mutation checks: removing the 413-arm collection, the pending base files or the gap reset each fails a test.
  • Review: three rounds of Opus review on the exact head. Every finding is fixed.
  • CI: green, check and wasm.

🤖 Generated with Claude Code

Ticket: https://agentboard.icefish-betta.ts.net/#977 (follow-up from the PR #12 review). Built on #12, which has merged. This PR is now rebased on `main`, including #17 (padded attachments), and Forgejo retargeted it there. ### What changes - **`GET /v1/vaults/{id}/files`** lists a vault's uploaded files with their ids and sealed sizes (the bytes the quota counts), whether or not an item lists them. Writers and above can call it; readers get 403, and non-members get 404 as on every other vault route. - **Unreferenced attachments are collected after a week.** Each writer's device does this right after a pull in `sync`, including a sync that ends in 409 or 413, since both come after a pull. - Over quota, collecting is what makes room for a change the server refused. - The device lists the vault's files and notes the ones no item refers to. - "Refers to" covers current fields, earlier versions in `history`, and the server's copy of an item with an edit or delete still pending here (`Vault::base_files`). - Each note keeps the time this device first saw the file unreferenced. - A file is deleted once it has stayed unreferenced for `FILE_GRACE` (7 days). - If the device hasn't looked for more than two graces, all notes start over, so old notes never count. - The notes live in the vault snapshot. The new fields use `#[serde(default)]`, so old snapshots restore. An old snapshot with a pending change and no base files skips collection. - Readers never collect. Short-lived agent runs, which keep no snapshot, don't either. - Collection errors never fail `sync`. - The rule is in core (`Vault::collect_files`, `Item::file_ids`). The client adds `Session::files` and `pub(crate) Session::collect_files(vault, now)`. - **`delete_item` no longer deletes attachments right away.** Another device that brings the item back with an unpushed edit (local edits win the merge) now keeps its files. - **CLI `attach`** deletes the fresh upload only after a 4xx. After a network error or a proxy's 5xx the push may have landed, so a later sync collects the file instead. - **The 413 message and DESIGN.md** now say that attachments are freed a week later. DESIGN.md has a new "Attachments" section, which states the one-week limit cases, and a new API row. PARITY.md has a note too. ### Trade-offs - **Quota:** over quota, deleting an item frees its blob at once but its attachments only after the grace. - **Requests:** collecting costs one more request per writable vault on every sync. - **Tuning:** `FILE_GRACE` is one constant. ### Tests - New `file_garbage_collection` test in `client/src/tests.rs`: - Writers can list. Readers get 403 and non-members 404. - An unpushed upload is collected only after the grace, and a note survives the snapshot round trip. - A gap of more than two graces resets the notes. - Files in `history` and in current fields survive, and readers don't collect. - A pending local delete keeps the server copy's files. - Another device's unpushed edit restores a deleted item, and its attachment still downloads afterwards. - Snapshots without the new fields restore. - `storage_quota`: - After `delete_item` the file stays. - A sync that hits a 413 still notes the file, and it's collected past the grace. - The refused change then goes through. - **Mutation checks:** removing the 413-arm collection, the pending base files or the gap reset each fails a test. - **Review:** three rounds of Opus review on the exact head. Every finding is fixed. - **CI:** green, check and wasm. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Attachments no item refers to are listed and collected after a week
Some checks failed
CI / check (pull_request) Successful in 1m14s
CI / wasm (pull_request) Failing after 1m17s
e1b3f84566
GET /v1/vaults/{id}/files lists a vault's files with their sealed sizes.
A writer's device notes files no item refers to (current or earlier
versions) as it syncs and deletes them once they've stayed unreferenced
for a week. delete_item no longer deletes files right away, so another
device restoring the item with an unpushed edit keeps its attachments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collection survives pending changes and stale notes; listing is for writers
Some checks failed
CI / check (pull_request) Successful in 1m17s
CI / wasm (pull_request) Failing after 1m21s
74dd6c4541
- A pending edit or delete keeps the files of the version it started from
  in use, so a refused change no longer stops collection in its vault.
- Notes start over after more than a grace without a look.
- GET /v1/vaults/{id}/files needs a writer.
- CLI attach cleans up only after a 4xx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
backmeupplz force-pushed board/977-d199dc from 74dd6c4541
Some checks failed
CI / check (pull_request) Successful in 1m17s
CI / wasm (pull_request) Failing after 1m21s
to 2f5a97e7e9
All checks were successful
CI / wasm (pull_request) Successful in 3m14s
CI / check (pull_request) Successful in 4m28s
2026-11-27 19:48:55 +00:00
Compare
backmeupplz force-pushed board/977-d199dc from 2f5a97e7e9
All checks were successful
CI / wasm (pull_request) Successful in 3m14s
CI / check (pull_request) Successful in 4m28s
to cdd1448ced
All checks were successful
CI / wasm (pull_request) Successful in 1m17s
CI / check (pull_request) Successful in 2m16s
2026-11-27 19:56:23 +00:00
Compare
backmeupplz changed target branch from account-delete-quotas-rate-limits to main 2026-11-27 19:57:38 +00:00
storage_quota: take the collect time after the sync that stamps
All checks were successful
CI / wasm (pull_request) Successful in 1m42s
CI / check (pull_request) Successful in 2m7s
dd15600748
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
backmeupplz force-pushed board/977-d199dc from dd15600748
All checks were successful
CI / wasm (pull_request) Successful in 1m42s
CI / check (pull_request) Successful in 2m7s
to e1f711e4f5
Some checks failed
CI / wasm (pull_request) Successful in 2m3s
CI / check (pull_request) Has been cancelled
2026-11-27 20:34:38 +00:00
Compare
backmeupplz force-pushed board/977-d199dc from e1f711e4f5
Some checks failed
CI / wasm (pull_request) Successful in 2m3s
CI / check (pull_request) Has been cancelled
to a4d38ae535
All checks were successful
CI / wasm (pull_request) Successful in 1m41s
CI / check (pull_request) Successful in 2m27s
2026-11-27 20:36:54 +00:00
Compare
Time file collection by the server's clock; test snapshot notes, old snapshots and conflicts
All checks were successful
CI / wasm (pull_request) Successful in 2m3s
CI / check (pull_request) Successful in 2m31s
afeb3f72df
GET /v1/vaults/{id}/files now returns {now, files}, and collection uses the
server's now, so a device clock set ahead can't make an upload due early.
New tests pin the snapshot persistence of the notes, the old-snapshot guard,
the conflict base files and the two-grace reset bound. DESIGN.md states the
sampling limits, the sync cadence collection needs and plaintext mcp; the
413 message no longer promises a week.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Test that collection follows the server's clock; agent runs, not CLI runs, skip it
All checks were successful
CI / check (pull_request) Successful in 4m6s
CI / wasm (pull_request) Successful in 2m49s
c605fb8eda
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merge main into board/977-d199dc
Some checks failed
CI / check (pull_request) Failing after 3m59s
CI / wasm (pull_request) Successful in 2m6s
cd31c1179f
Merge main into board/977-d199dc
All checks were successful
release / build (macos-latest, true, aarch64-apple-darwin) (pull_request) Successful in 2m8s
release / build (macos-latest, true, x86_64-apple-darwin) (pull_request) Successful in 2m33s
CI / check (pull_request) Successful in 4m13s
CI / wasm (pull_request) Successful in 2m29s
release / build (ubuntu-24.04, false, x86_64-pc-windows-gnu) (pull_request) Successful in 8m52s
release / build (ubuntu-24.04, true, aarch64-unknown-linux-musl) (pull_request) Successful in 10m24s
release / build (ubuntu-24.04, true, x86_64-unknown-linux-musl) (pull_request) Successful in 9m49s
release / release (pull_request) Has been skipped
release / forgejo (pull_request) Has been skipped
release / homebrew (pull_request) Has been skipped
release / docker (pull_request) Has been skipped
1ce496de37
backmeupplz deleted branch board/977-d199dc 2026-11-27 22:04:00 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
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
backmeupplz/plaintext!16
No description provided.