Skip to content

fix(persistence): a late release cannot delete a retained done row - #782

Closed
mengmengmengqiang wants to merge 1 commit into
Ephemeral-AI-Lab:mainfrom
tokenaissance:fix/sqlite-release-done-row
Closed

mengmengmengqiang wants to merge 1 commit into
Ephemeral-AI-Lab:mainfrom
tokenaissance:fix/sqlite-release-done-row

Conversation

@mengmengmengqiang

Copy link
Copy Markdown
Contributor

Bug

An operator settle + release keeps a mount row as the durable done audit row (Inv7: done rows are only added, never removed).

SQLite's release deleted by op_id alone:

DELETE FROM gc_intent WHERE op_id = $1 RETURNING op_id;

So when the original owner's BoundWorkspace::close later released the same op_id, it deleted the retained done row and its audit evidence.

PostgreSQL never did: its release reads the intent through gc_intent_get, which filters state <> 'done', so the late release finds nothing to release.

Fix

  • engine/crates/layerfs-persistence/sql/sqlite/queries/history/gc_intent_release.sql: add AND state <> 'done' to the release DELETE (the shared statement text PostgreSQL also runs).
  • The late release is now a no-op that reports the same nothing-to-release outcome as a release of a missing op — not an error — and the done row and its evidence stay untouched.
  • Regression test a_late_release_cannot_delete_a_retained_done_row in engine/crates/layerfs-persistence/tests/gc_intent_done.rs, against the real SQLite catalog: register a mount, operator settle+release it to done, then the owner's late gc_release; assert the done row still exists with unchanged evidence, state and updated_ms.

Found during the review of #770.

Verification

  • cargo test -p layerfs-persistence --test gc_intent_done — 7 passed, 0 failed
  • cargo test -p layerfs-store-service --test admission — 10 passed, 0 failed
  • cargo check --offline --workspace --all-targets — pass (exit 0)
  • Full cargo test -p layerfs-persistence (no-fail-fast): the same four suites fail on the base merge commit 2f9cb974 without this change (diagnostic_overwrite, kept_node_closure, postgresql_statement_schema, sqlite_compact_matrix); everything else passes.
  • tools/production_loc.py --detail: 214081 -> 214081 (delta 0)

An operator settle+release keeps a mounted intent as the durable `done`
audit row. When the original owner's BoundWorkspace::close later released
the same op_id, SQLite's release DELETE matched on op_id alone and removed
that retained row, breaking the add-only done-row invariant (Inv7).
PostgreSQL never did: release reads the intent through the done-filtering
`gc_intent_get` first, so the late release finds nothing.

Filter `state <> 'done'` in the release DELETE, so a late release is a
no-op that reports the same nothing-to-release outcome as a missing row
rather than an error, and the audit row and its evidence stay untouched.

Regression: a_late_release_cannot_delete_a_retained_done_row.

Production LOC: 214081 -> 214081 (delta 0)
mengmengmengqiang added a commit to tokenaissance/layerfs that referenced this pull request Nov 24, 2026
…wner fallback, H3/H4 and docs

Ordered keeps the raw token (raw-first equality; two spellings of the same
label/ms/nonce are .unordered); parseToken accepts only non-empty ASCII
decimal digits below 2^64; ownerVerdict threads the Store kind (oldBoot is
Dead only on a local SQLite Store) and the witness snapshots it; H3 is the
existence form (a tombstone/incarnation may be replaced, never silently
dropped) and H4 covers every map row; README documents H0/H2d/H-done-op-id/
H-no-prune, the corrected witness matrix, the actual LOC command and the
Ephemeral-AI-Lab#782 dependency for Inv7. Examples gain raw-parse and auditWitness guards.

Verified locally from the Branch: lake build green (0 warnings), 23 axiom
receipts OK, step_preserves on [propext, Classical.choice, Quot.sound],
no sorry/admit/axiom/native_decide.
mengmengmengqiang added a commit to tokenaissance/layerfs that referenced this pull request Nov 24, 2026
…wner fallback, H3/H4 and docs

Ordered keeps the raw token (raw-first equality; two spellings of the same
label/ms/nonce are .unordered); parseToken accepts only non-empty ASCII
decimal digits below 2^64; ownerVerdict threads the Store kind (oldBoot is
Dead only on a local SQLite Store) and the witness snapshots it; H3 is the
existence form (a tombstone/incarnation may be replaced, never silently
dropped) and H4 covers every map row; README documents H0/H2d/H-done-op-id/
H-no-prune, the corrected witness matrix, the actual LOC command and the
Ephemeral-AI-Lab#782 dependency for Inv7. Examples gain raw-parse and auditWitness guards.

Verified locally from the Branch: lake build green (0 warnings), 23 axiom
receipts OK, step_preserves on [propext, Classical.choice, Quot.sound],
no sorry/admit/axiom/native_decide.
@yifanxuaaa
yifanxuaaa changed the base branch from layerfs_v2_0_0 to main December 1, 2026 17:00
@yhcedpn yhcedpn added bug Something isn't working engine/store The global Store: SQLite and PostgreSQL backends, one writer, the publish lane labels Dec 3, 2026
@yifanxuaaa

Copy link
Copy Markdown
Contributor

Closing as superseded by #783, merged in 96f27a61fc. The bug and the proposed fix are both confirmed. The SQLite owner-release statement on main already excludes retained done audit rows.

I verified the SQL from this PR's parent, this PR's head (a0a00a9484), and current main (cb52c3c7b4) with a Normal/WAL SQLite fixture. Both this PR and current main preserved the audit row, including its evidence and timestamp. All nine retained-audit tests passed on Linux at the current main commit.

Thanks for identifying the late-release case and writing a focused regression test.

@yifanxuaaa yifanxuaaa closed this Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working engine/store The global Store: SQLite and PostgreSQL backends, one writer, the publish lane

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants