Repository navigation
fix: Refuse blob deletion a replaced index tier cannot decide - #5085
Conversation
index.db is the only owner of attachments.blob_hash and is rebuildable: a wipe or an index-generation swap leaves a schema-current, row-empty file. Blob GC read that silence as "unreferenced", so the first pass after a wipe unlinked every blob whose only liveness surface was the index, reporting clean success with blocked_reason=None. The decision is now per candidate, not per pass. A candidate the source tier still claims stays live exactly as before; only a candidate whose sole possible referent was the index is blocked, and only while GC's own durable witness says that tier was replaced with a smaller blob population. GC records that witness (the resolved index file identity plus its distinct blob-owner hash count) beside the bytes it protects, in the blob namespace, which no tier reset touches. A population that falls within one tier file is an ordinary deletion and re-anchors the witness. A pass-level preflight refusal was rejected: it blocks archives whose index is legitimately empty and makes GC unable to reclaim source-unreferenced bytes for the whole rebuild. Also converts a schema-skewed reference tier into a GC blocker instead of a propagating exception: _readonly raises SchemaSkewError, which is not a sqlite3.Error, so _reference_tier_blockers and _database_has_table let it escape the functions whose purpose is turning unreadability into a reason. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reachedNext included review available in 1 minute. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
## Summary Reopens the work from #5083, rebased onto current master. The original PR's base branch (#5079) was squash-merged and deleted, which closed it and left the branch conflicting. Deletes `archive-root-relocation` and `source-continuity-recovery` end to end, plus the relocation coupling inside `durable_change_train.py`. ## Problem Both are self-documented as acting on an old archive root: `--old-root` names "the retired pre-move root", and the other is "a one-purpose bridge for a committed **pre-#3868** receipt". Both are dead by construction once the archive is rebuilt with current code. Tracked by `polylogue-2x6xu`, whose earlier "already landed" claim was verified false — all three route groups were fully live, including three `assert_no_prepared_*` calls on the `polylogued run` startup path. ## Solution −8,887/+29 across 23 files: operations modules, registered CLI groups, generated CLI output schemas, docs sections, tests. Also fixes a deletion hazard the sweep caught: the docstring of `_released_train_proven_floor` justified the fresh-bootstrap marker's retirement on evidence that "archive-root relocation already rebinds" — it would have merged clean in a different file and stood as authoritative over a deleted mechanism. ## Verification ``` devtools verify --quick 15/15 gates ok (exit 0) ``` Rebase checked for silent revert: the first rebase attempt was cut against a master predating #5085 and its diff showed 117 deletions in `tests/unit/storage/test_blob_gc.py` — it would have reverted that PR's protection tests. Re-cut against current master; the diff now touches no blob-GC file. ## Timing `devtools schema closure` reports `operations/archive_root_relocation.py` and `storage/sqlite/durable_change_train.py` as **IN** the derived schema closure. Must merge before a fresh rebuild starts, never during one. ## Residuals `_SOURCE_CONTINUITY_REFRESH_V1_FORMAT` and its `_legacy_source_continuity_*` helpers are left in place: they sit on the *retained* refresh path, which `maintenance/blob_ref_liveness_reconciliation.py` still calls. Separate blast radius, separate decision. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Summary
Blob GC no longer reads a replaced index tier's silence as proof that a blob is unreferenced. The decision is made per candidate: a blob the source tier still claims is evaluated exactly as before, and only a blob whose sole possible referent was
index.attachmentsis blocked, and only while GC's own durable witness says the index tier was replaced by a file holding fewer blobs.Problem
index.dbis the only owner ofattachments.blob_hash(storage/blob_liveness.py:68) and it is rebuildable: a wipe or an index-generation swap leaves a schema-current, row-empty file._reference_tier_blockerspasses for any file SQLite can open and_schema_blockerschecks table/column presence only, never rows, so a bootstrapped-empty index yieldedUNREFERENCEDfor every hash only it knew about.Executed on the live archive (read-only,
~/.local/share/polylogue):Those 1,240 payloads (~425 MB) carry no
blob_refsrow, no direct source owner and no publication receipt. They are byte-for-byte indistinguishable, from insidesource.db, from a blob nothing ever referenced. The reproduction in polylogue-kdt2f shows the consequence: with the index moved aside and re-bootstrapped, a pass reportedcandidate_count=1 deleted_count=1 skipped_referenced=0 blocked_reason=Noneand the blob was gone.daemon/blob_gc_periodic.py:26-41runs this every 900s, and the catch-up gate (daemon/cli.py:196-221) is bounded at 1800s, which a from-scratch rebuild exceeds.Solution
inspect_blob_livenesstakesindex_authority_blocker, applied after surfaces are gathered: surfaces present →LIVEunchanged; no surfaces and a blocker →BLOCKEDwith a reason instead ofUNREFERENCED. Every GC route already funnels through_inspect_gc_protection, so all four entry points (run_blob_gc_reportplanning and dry-run recheck,_execute_gc_generation_members, and bothunlink_unreferenced_blob_hashes_*seams) thread one per-pass value into a per-candidate decision._final_gc_member_livenesskeeps its historical signature, so existing fault-injection doubles stay valid.Why not the preflight shape. A blanket refusal when the index "looks unmaterialized" blocks the whole pass, which makes GC unable to reclaim genuinely source-unreferenced bytes for the entire rebuild and turns four correct tests red —
test_run_blob_gc_preserves_archive_source_referenced_blobs,test_run_blob_gc_does_not_stage_again_when_all_candidates_are_referenced,test_run_blob_gc_bounds_final_lock_rechecks_with_many_references,test_run_blob_gc_refuses_when_the_index_tier_cannot_be_read. Those exercise blobs the source tier decides, where index emptiness is irrelevant. None of them is modified here.Why a witness rather than a row-count test. The census above rules out any purely per-candidate data signal: an index-only attachment and a true orphan look identical in
source.db. "Index has no sessions" and "index has no rows" both over-block, because a legitimately empty index is a normal state (the bounds test collects an orphan against exactly that). The only honest discriminator is evidence that the index tier lost what it used to hold, and the index cannot witness its own loss.storage/blob_gc_index_watermark.pyrecords, in the blob namespace next to the bytes it protects (no tier reset touches it), the resolved index file's(st_dev, st_ino)and its distinct blob-owner hash count. A population that falls within one tier file is an ordinary deletion and re-anchors the witness; a population that falls across a tier-file replacement is the wipe/rebuild shape and blocks index-only candidates until the replacement owns at least as many blobs again. The witness is only ever written when it is safe to do so, and a failed write leaves the older, more conservative value in place.Also in scope:
_readonlyraisesSchemaSkewError, which is not asqlite3.Error, so_reference_tier_blockersand_database_has_tablelet it escape functions whose purpose is converting unreadability into a reason. Both now catch it. This was fail-loud, not a data-loss path. Pruningpolylogue/storage/blob_gc.pyfrom thesqlite-error-defaultpattern baseline is the ratchet shrink that follows.Verification
Anti-vacuity, executed rather than asserted. With the gate disabled (
if False and index_authority_blocker is not None) and nothing else changed:The gate was restored and the suites above rerun green.
Two tests are added. The first proves an index-only blob survives a wiped, re-bootstrapped index; its first pass runs against the materialized index and reclaims nothing, which proves the candidate walk, age gate and liveness route are all reached. The second proves an index that never owned a blob is not treated as a wiped one: an orphan is still collected and a source-referenced blob still retained, on the first pass and on a later pass that runs against a witness this code wrote itself.
Derived schema closure:
devtools schema closure polylogue/storage/blob_gc.pyand.../blob_liveness.pyboth reportIN. This moves the index tier's derived identity (verified locally:0f4129a5…atmaster,cf792ff0…here), so it must land before a fresh rebuild starts, never during one.Residuals
blocked_reason; it reclaims nothing further that pass. That is deliberate — during that window no unreferenced-looking blob can be proven dead — but it does mean no reclamation until the index catches up to its previous population.source.dbcolumn is a gated durable change train and this needed to land ahead of the rebuild. Deleting the file fails open to today's behavior.🤖 Generated with Claude Code
https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK