Repository navigation
fix(gc): #784 review fixes: tombstones only on confirmed stop, PostgreSQL release once, keyset audit - #787
Merged
Conversation
…e start write (#784 review) A Sandbox's retired tombstone proves its generation's mounts dead once the home record is gone, so it is now written only where the runtime is confirmed stopped, gone or never started: - lifecycle::close no longer writes it for a retired docker record (its container is left for the user) or a record this build does not read (forget_unread: its daemon may still run). - sandbox.remove: the unread-local, foreign, retired-docker and nameless-machine forgets write none (Worker::Ask / Skip); a gone VM or a machine recorded stopped (Worker::Gone) still does. After the close its side ran, only a `Closed` answer or `NoSuchSandbox` writes it; a `Forgotten` answer (with or without `left`) writes none. A forget whose worker refused or was unreachable writes none. - Kept: the normal close, force::close, reclaim and remove_unstarted. - reclaim reports a tombstone it could not write in its answer's `left`; close carries it in the gone refusal's `left` detail and sandbox.remove's NoSuchSandbox arm adds it to `left` (it was dropped). A worker's record now gets its place in the same write that records it started (files::write_started, called by save_sandbox; save_place removed): the caller's place always wins, and a worker record sent no place drops any machine/generation a leftover record kept, so a failure leaves no evidence, never an older generation. lifecycle::start, launch::local::start and save_sandbox take the place with the host and platform. family::create_on runs sandbox.create with a stand-in for the side that starts it on a machine whose calls run in this process; create calls it with dispatch::call. Tests: new tests/retired_tombstone.rs (unread record and retired docker forget through sandbox.remove and lifecycle::close write no tombstone; a forget whose worker keeps its record writes none; gone VM writes one, nameless machine none; a recreate through create_on drops the older tombstone and sends its side the recorded place). half_created.rs: the forced remove's confirmed stop leaves the tombstone; new reclaim test (tombstone written, or its failure in the refusal's `left`). place_evidence.rs: the save_place test is replaced by write_started tests (new place in the start write; a leftover worker record never keeps its older generation; a home record keeps its place). No test deleted. Production LOC: 214259 -> 214288 (delta +29) scope: tools/production_loc.py (repo-pinned counter), first-parent tree vs committed tree reference absent (retired R9c; last counted 65,417 at tree 498dd19) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ner release (#784 review) - audit pages by (updated_ms, op_id): `gc_done_intents_branch` takes the last row's place and reads `LIMIT limit+1` for the next cursor (no lookahead read); the cursor place `<updated_ms>:<op>` is validated (malformed is `InvalidInput`) and travels to the worker unchanged as `after`. - a retained done row is stamped max(now, the scope's newest done time + 1) (new `gc_intent_done_newest`, one read through the existing scope index prefix), and the cap never deletes the op it just retained. - PostgreSQL: the owner's release reads its row whatever its state (`gc_intent_get_any`), so after an operator retained it as done the owner still unlocks its own session keys; the done row is neither deleted nor revived. - `gc_mark_uncertain` answers whether a live row was marked; `settle` of a row released since the listing is `NotFound`, and `settle_legacy` counts only marked rows. - `gc_liveness` judges with the supplied view alone (as a removal admits), not the holder's own recorded generation as the current record. No Store format change (two new query files only). Tests added: gc_intent_done a_release_between_audit_pages_neither_skips_nor_repeats_a_row, a_release_stamped_behind_the_newest_row_is_kept_and_listed_last; gc_place_view liveness_with_a_tombstone_only_view_matches_admission; postgresql_gc_fence an_owner_release_after_an_operator_release_unlocks_its_session_keys; store_repair_worker the_worker_judges_with_the_sent_view_and_pages_the_audit_by_key. Changed: a_release_keeps_at_most_the_newest_done_rows_of_its_branch now holds a live and an uncertain intent in the Branch and asserts both survive. None deleted. Production LOC: 214259 -> 214318 (delta +59) scope: tools/production_loc.py (repo-pinned counter), first-parent tree vs committed tree reference absent (retired R9c; last counted 65,417 at tree 498dd19) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- store.md: PostgreSQL rows are never `dead` from place evidence, so most PostgreSQL settles need `--force`; audit pages by (updated_ms, op); the done stamp, the cap keeping the retained row and the PostgreSQL owner release; `settle` of a released row is `NotFound`; `NoSuchStore`, `NoSuchProject` and `NoSuchBranch` in the error table. - GC spec: `store.diagnose` forwards only the typed holder view, not `liveness`/`safe`. - gc_intent_insert.sql: a done row is not revived while retained; once the cap deletes it, its op id can register again. - the call's one-line summary (and the CLI help test) names `settle_legacy`. Production LOC: 214318 -> 214318 (delta 0) scope: tools/production_loc.py (repo-pinned counter), first-parent tree vs committed tree reference absent (retired R9c; last counted 65,417 at tree 498dd19) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…which removals write a tombstone - `calls_table::a_migrated_entry_declares_its_forms_and_the_others_declare_none` failed on layerfs_v2_0_0 since #784: the call declared `Paging::Cursor` but has no 2.0 answer form, and only entries with a form may declare paging. Declaring a form would reshape its answers (a separate migration), so the entry declares no paging; it still pages by `limit`/`cursor`. - GC spec: a removal writes the retirement tombstone only when the runtime is confirmed stopped, confirmed gone or never started; a forget that sent no signal writes none. Production LOC: 214,347 -> 214,346 (delta -1) scope: tools/production_loc.py (repo-pinned counter), first-parent tree vs committed tree reference absent (retired R9c; last counted 65,417 at tree 498dd19) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bstone (#784 review) sandbox.remove treated every `NoSuchSandbox` answer from the close its side ran as "confirmed gone" and wrote the Sandbox's retired tombstone. Some of those answers inspect no runtime: `files::reopen` answers "Sandbox <id> has no daemon keys" and `lifecycle::close` answers "no Sandbox <id> runs on this machine" without looking at the daemon. A tombstone there could prove a still-running daemon's mounts dead. Now only a `NoSuchSandbox` whose detail says `containerGone` (its side found the daemon gone or stopped and reclaimed it) writes the home tombstone; any other is removed with no tombstone, which is only "no proof". The spec's Place writers paragraph says so. Test: retired_tombstone a_sandbox_without_daemon_keys_is_removed_without_a_tombstone (macOS: a native record this build reads, no daemon keys); it fails with the old arm. The recreate test's Store setup moved to a shared helper. Production LOC: 214,346 -> 214,349 (delta +3) core 42,486 -> 42,486 (0) engine 98,258 -> 98,258 (0) control 63,227 -> 63,230 (+3) layerfs-sandbox +3 api 10,375 -> 10,375 (0) reference absent (retired R9c; last counted 65,417 at tree 498dd19) Method: tools/production_loc.py --detail on parent a1503aa and the staged tree Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…once (#784 review) PostgreSQL session advisory keys are reference-counted, one level per op a session registered. `release` read the keys from the row whatever its state, so an op released twice in the same session (an operator `release_done` in the owner's own session, then the owner's release; or a repeated release) unlocked twice and dropped the level a second live mount of that session held on the same Branch. The Session now records the ops it registered (`held_ops`): `register` records the op once its keys are taken, and `release` and `release_done` unlock only when `take_op` finds the op still held, so each registered op unlocks exactly once and an op another session registered unlocks nothing. SQLite is unchanged. Test: postgresql_gc_fence a_repeated_release_unlocks_its_op_once (two mounts in one session on one Branch; operator release, owner release and a repeat of the first; the Branch key stays held until the second is released); it fails with the old unlock. Production LOC: 214,349 -> 214,367 (delta +18) core 42,486 -> 42,486 (0) engine 98,258 -> 98,276 (+18) layerfs-persistence +18 control 63,230 -> 63,230 (0) api 10,375 -> 10,375 (0) reference absent (retired R9c; last counted 65,417 at tree 498dd19) Method: tools/production_loc.py --detail on parent 9f58434 and the staged tree Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in the PostgreSQL connect/attach change (#786). Both sides edit control/crates/layerfs-sandbox/src/create.rs and docs/architecture/api/sdk/store.md in separate hunks; no conflict. Production LOC (first parent 657212d against the merged tree; the change is #786's): 214,367 -> 213,947 (delta -420) core 42,486 -> 42,486 (0) engine 98,276 -> 98,276 (0) control 63,230 -> 62,873 (-357) layerfs-control -35, layerfs-machine +12, layerfs-platform +5, layerfs-sandbox +45, layerfs-store -384 api 10,375 -> 10,312 (-63) layerfs-api -62, layerfs-cli -1 reference absent (retired R9c; last counted 65,417 at tree 498dd19) Method: tools/production_loc.py --detail on parent 657212d and the staged merge tree Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…review) sandbox.remove of a Sandbox on a machine whose record is `gone()` took `Worker::Gone` when the machine was not nameless, i.e. when a live read had recorded the VM `missing`, and wrote the home's retired tombstone `machine/<m>/sandbox-retired/<name>.json`. `missing` is only that a provider listing showed no VM of that name: a listing glitch or a VM that comes back (a live read mends the record then) can leave its daemon running, and the tombstone would let GC admission judge its live mounts dead. Now a missing VM takes `Worker::Skip`, as a nameless machine already did: the records go, the worker is not reached and no tombstone is written. `left` says why the mounts are not proven dead and names `layerfs store repair-mount-holders <project> <branch> list` and `settle --op <op> --force` once the VM is known gone. `Worker::Gone`'s only producer is now `stopped_on` (a machine recorded stopped). The GC spec's Place writers paragraph, the sandbox.remove API page and the control Sandboxes page say so; the spec also records an open gap: a docker live read records a paused worker container stopped. Tests: retired_tombstone `a_gone_vm_writes_the_tombstone_and_a_nameless_machine_does_not` is renamed `a_missing_vm_and_a_nameless_machine_write_no_tombstone` and its missing-VM half now expects no tombstone and the repair `left`, because the required behaviour changed; the nameless half is unchanged. It fails without the fix (on the `left` text, and with only the worker choice reverted, on the tombstone assertion). New `a_machine_recorded_stopped_writes_the_tombstone` keeps the stopped path writing one. No test deleted. Production LOC: 213,947 -> 213,951 (delta +4) core 42,486 -> 42,486 (0) engine 98,276 -> 98,276 (0) control 62,873 -> 62,877 (+4) layerfs-sandbox +4 api 10,312 -> 10,312 (0) reference absent (retired R9c; last counted 65,417 at tree 498dd19) Method: tools/production_loc.py --detail on parent 3477a5c and the staged tree Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…review) The #787 review found the "neither skips nor repeats" claim of the Branch-scoped done audit (`gc_done_intents_branch`) too strong in two cases. Checked against the source: 1. PostgreSQL concurrent releases: already ordered, no code change. Every PostgreSQL `provider.write` begins with `write_begin(true)`, which locks the Store lane row (`SELECT 1 FROM store_lane WHERE id = 1 FOR UPDATE`) in the BEGIN round trip under READ COMMITTED. A second release therefore waits for the first one's commit, and its `gc_intent_done_newest` read (a new statement snapshot) sees the first row. A writer nested in a held lane runs only while its thread owns the lane row. Stamps of one Branch follow commit order, so no row of it is skipped. A transaction-scoped advisory lock would add nothing. New test `a_release_behind_a_concurrent_writer_is_stamped_after_its_row` (postgresql_gc_fence) pins this. With the lane removed from `Mode::Write` (temporary revert), it fails: the release is stamped before the concurrent writer's row, which is the skip. 2. A Branch (or its project) removed and created again under the same names: real, and documented rather than fixed. The audit selects by recorded project/Branch names, but the stamp floor is per Branch identity. Flooring by names would scan every retained row inside the write transaction, because no index covers the names and the Store format may not change. The doc comments, SQL comments, SDK reference and GC spec now state the exact guarantee: no row is ever repeated; no row of the identity it was retained under is skipped; a row the cap deletes first is not returned; and across identities, a newer Branch's row stamped at or below the earlier identity's rows is missed by a cursor already past them, while a read from the first page returns it. New test `a_recreated_branch_is_paged_by_its_own_stamps` (gc_intent_done) pins that stated behavior. No Store format change, no new lock, no retry. Production code changes are comments only. Production LOC: 213,947 -> 213,947 (delta 0) core 42,486 -> 42,486 (0) engine 98,276 -> 98,276 (0) control 62,873 -> 62,873 (0) api 10,312 -> 10,312 (0) reference absent (retired R9c; last counted 65,417 at tree 498dd19) Method: tools/production_loc.py --detail on parent 3477a5c and the staged tree Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tone Brings in a2f3117. A Sandbox on a machine whose VM a live read recorded missing is removed without a tombstone (the VM may come back, so its daemon is not proved stopped); `left` names the repair call. A machine recorded stopped still writes one. Production LOC (first parent 3477a5c against the merged tree; the change is a2f3117's): 213,947 -> 213,951 (delta +4) core 42,486 -> 42,486 (0) engine 98,276 -> 98,276 (0) control 62,873 -> 62,877 (+4) layerfs-sandbox +4 api 10,312 -> 10,312 (0) reference absent (retired R9c; last counted 65,417 at tree 498dd19) Method: tools/production_loc.py --detail on parent 3477a5c and the staged merge tree (equal to a2f3117's tree) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in cc93b07 (comments, docs and tests only). Concurrent PostgreSQL releases already stamp in commit order: every write waits for the Store's lane row at BEGIN (new test a_release_behind_a_concurrent_writer_is_stamped_after_its_row). A Branch removed and created again under the same names can sort its newer rows among the earlier Branch's; fixing it needs a name scan in the write or a new index (a format change), so the docs and spec state the exact guarantee and a_recreated_branch_is_paged_by_its_own_stamps pins it. Production LOC (first parent, the merge of claude/gc-787-vm, against the merged tree): 213,951 -> 213,951 (delta 0) core 42,486 -> 42,486 (0) engine 98,276 -> 98,276 (0) control 62,877 -> 62,877 (0) api 10,312 -> 10,312 (0) reference absent (retired R9c; last counted 65,417 at tree 498dd19) Method: tools/production_loc.py --detail on the first parent and the staged merge tree Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the bugs found in the review of #784 (merged into
layerfs_v2_0_0with #783). The rule throughout: missing evidence is never death, so when in doubt a mount holder stays held.Fixes
ForgottenanswersNoSuchSandboxanswer that inspected no runtime ("has no daemon keys", "no Sandbox … runs on this machine") was taken as "gone" and tombstonedNoSuchSandboxwithcontainerGone(the daemon was found gone or stopped) writes itreclaimdropped a tombstone it could not writeleftthroughcloseandsandbox.remove(updated_ms, op)max(now, newest + 1); the cap never deletes the row it just keptdonerowsettleon a missing op, thegc_livenessview, docsNotFound; view and reference fixedcalls_tablefailed onlayerfs_v2_0_0:store.repair_mount_holdersdeclaredPaging::Cursorwithout an answer formlimit/cursor)missing(a live read; the VM may come back) got a tombstoneleftnamesstore repair-mount-holders … listandsettle --op … --forceNo Store format change. The GC spec's place-writers paragraph states exactly which removals write a tombstone.
Production LOC
Range 834f4bb → 657212d (this PR's own commits): 214,259 → 214,367 (+108): engine +77 (layerfs-persistence), control +32 (layerfs-sandbox), api −1, core 0. The two internal merges (d78565c, 0cdb08e) only join this PR's sub-branches and carry no LOC line of their own; each joined commit has its block. 3477a5c merges the new base (#786) in: its −420 is #786's. Fixes 11–12: a2f3117 +4 (layerfs-sandbox), cc93b07 0; head c5aee8d is 213,951. Method:
tools/production_loc.py --detailon parent and staged tree, per commit.Tests
New tests, each confirmed to fail without its fix:
layerfs-sandboxretired_tombstone::a_sandbox_without_daemon_keys_is_removed_without_a_tombstone(macOS only: it needs a native record this build reads)layerfs-persistencepostgresql_gc_fence::a_repeated_release_unlocks_its_op_onceRun on macOS (host cargo 1.85.1), on the merged tree 3477a5c unless noted:
--workspace --all-targets -D warnings: clean.lp176_image_recovery(6 of 16 fail: "machine native … has no Sandbox images", tar and real-docker checks). That target does not callremove, and no commit here touches image code. Not checked on the base.calls_table26.Linux (launcher's rust:1.85.1 container, at 3477a5c): every layerfs-sandbox target passes (lp176_image_recovery 16/16; its real-Docker sections skip without a Docker CLI); SQLite GC suites; PostgreSQL postgresql_compact 33, diagnostic 9, gc_fence 21, gc_mark 15, status 8, repair_postgresql 1, project_delete_store 4, project_delete_worker 14, store_repair_live 2, store_repair_worker 2, gc_calls 11; store-service admission 10; cli gc 5; Linux Clippy
--workspace --all-targets -D warningsclean. NOT_RUN: the FUSE mount lane (no GC target in it; the container has no FUSE flags).macOS
lp176_image_recovery: the same 6 tests fail on the base 834f4bb, so they predate this PR.After fixes 11–12 (at c5aee8d, macOS): retired_tombstone 7, stopped_machine 2, place_evidence 4, gc_intent_done 9, admission 8, sqlite_compact_done 2; Clippy on persistence/sandbox/store clean. The fix branches also ran: all sandbox targets, layerfs-machine
--features machine, postgresql_gc_fence 22, postgresql_compact 33, postgresql_status 8.cargo fmt --checkdrift is only in files this PR does not touch.Still open (not fixed here)
stopped, so a forcedsandbox removethere writes a tombstone; afterdocker unpauseits daemon resumes with mounts already judged dead. Narrow (needs an outsidedocker pause); the fix is in the platform's state mapping. Recorded in the spec.🤖 Generated with Claude Code