Skip to content

Harden blob authority and crash-safe reclamation - #4149

Merged
Sinity merged 17 commits into
masterfrom
feature/storage/blob-authority-foundation
Aug 25, 2026
Merged

Sinity merged 17 commits into
masterfrom
feature/storage/blob-authority-foundation

Conversation

@Sinity

@Sinity Sinity commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • centralize blob liveness across durable and rebuildable ownership surfaces
  • make GC crash recovery durable and bind every intent to a namespace identity
  • remove direct blob deletion routes and route physical effects through one fail-closed GC seam
  • make archive backups complete across historical schemas without treating unbound namespace markers as authority

Problem

The live blob store contains historical residue and cannot serve as desired-state authority. Cleanup still needs to preserve every currently owned byte while safely concentrating unexplained residue. Existing GC paths could lose exact intent across crashes, omit ownership surfaces, infer absence from unreadable tiers, or redirect a delayed pathname unlink after a namespace swap. Several direct deletion routes duplicated that authority.

Solution

One liveness model now classifies canonical raw, attachment, hook, sidecar, reservation, and legacy references. Destructive GC commits exact members before unlink, rechecks source and index ownership under the writer window, binds the intent to a durable namespace marker, and performs final observation and unlink through no-follow directory handles. Interrupted intents resume idempotently or remain blocked for audited offline abandonment, which never unlinks or rebinds bytes. Durable source migrations 034 and 035 carry the intent and namespace fields. Backup verification handles historical schema generations and deliberately excludes an unbound marker from ordinary evidence copies.

Verification

  • critical native review selectors: 4 passed in 1.96s after restacking on current master
  • focused blob GC, CLI, backup, and operation suite: 262 passed
  • operation/audit, schema, and oracle suite: 103 passed
  • schema versioning, schema roundtrip, oracle integrity, and quick gates succeeded in the implementation workspace
  • exact-head AgentCTL quick gate succeeded, receipt ff598e05-c4de-48b7-9616-a10e8bdd8923

No live archive cleanup or mutation was performed by this PR.

@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b6b73c12-bad2-4e16-9d03-4146fffa7ade


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e3713aca8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/storage/blob_gc.py Resolved
Comment thread polylogue/storage/blob_gc.py Resolved
Comment thread polylogue/storage/blob_integrity.py Resolved
Comment thread polylogue/storage/blob_gc.py Resolved
@Sinity

Sinity commented Aug 25, 2026

Copy link
Copy Markdown
Owner Author

Addressed all four inline review findings on fix/blob-foundation-final (commit 1203496, pushed to origin/fix/blob-foundation-final).

(a) Namespace marker not fsynced before GC intent commit — polylogue/storage/blob_gc.py:_blob_namespace_identity — Fixed. The marker-creation branch now os.fsyncs the marker file's own fd and fsyncs the containing directory (new _fsync_directory helper) before the marker can be read back and its identity recorded in a durable gc_generations row. Test: tests/unit/storage/test_blob_gc_durable_intent.py::test_marker_creation_fsyncs_file_and_containing_directory (monkeypatches os.fsync to record fd calls; asserts >= 2 calls — one for the marker, one for the directory).

(b) dry_run=True creates the namespace marker — polylogue/storage/blob_gc.py:run_blob_gc_report — Fixed. namespace_identity is now only fetched (and only creates the marker) when not dry_run; the dry-run path never needed it (it resolves candidate paths directly via _sharded_blob_path in its final recheck, never through _read_blob_object/_open_blob_namespace). A read-only preview against a marker-less archive no longer writes anything. Test: tests/unit/storage/test_blob_gc.py::test_run_blob_gc_dry_run_does_not_create_namespace_marker.

(c) blob_integrity.py RuntimeError uncaught by probe caller — polylogue/operations/daemon_workload_probe.py:_blob_reference_debt_state — Fixed. The except clause now also catches RuntimeError, which scan_blob_reference_debt (via _historical_projection) raises when the canonical blob liveness projection is blocked (missing index tier, unsatisfiable source schema). Returns the documented {checked: false, ok: false, error: ...} state instead of aborting the whole workload probe. Test: tests/unit/operations/test_daemon_workload_probe.py::test_daemon_workload_probe_blob_reference_debt_survives_blocked_projection.

(d) _candidate_blobs shortlists invalid non-64-hex names — polylogue/storage/blob_gc.py:_candidate_blobs — Fixed. Both the two-char shard-prefix name and the full combined blob_hash are now validated as lowercase hex, and the combined hash must be exactly 64 characters, before a candidate is shortlisted; malformed entries (short names, uppercase, non-hex) are silently skipped, consistent with BlobStore.iter_namespace's classification of them as invalid namespace entries, and left for the integrity workflow instead of reaching _commit_gc_generation_intent/the blob_hash CHECK constraint. Test: tests/unit/storage/test_blob_gc.py::test_candidate_blobs_filters_invalid_namespace_entries. (Also updated two pre-existing _candidate_blobs tests — test_candidate_blobs_skips_dotfiles and test_candidate_blobs_skips_non_two_char_prefix_dirs — whose fixtures used non-64-char fake hashes that the new length check would otherwise now correctly filter out; they now use realistic 64-char hex blob hashes so they keep testing what they were meant to test.)

Verification

  • devtools test tests/unit/storage/test_blob_gc.py tests/unit/storage/test_blob_gc_durable_intent.py tests/unit/operations/test_daemon_workload_probe.py tests/unit/storage/test_blob_integrity.py — 108 passed
  • devtools test tests/unit/daemon/test_blob_gc_periodic.py tests/unit/cli/test_archive_maintenance_cli.py — 151 passed
  • devtools verify --quick — all gates ok (format, lint, mypy, render all, layering, ci-commands, doc-commands, schema-roundtrip, schema-versioning, oracle-integrity, schema promotion audit, schema privacy registry)

Diffstat: 5 files changed, 191 insertions(+), 14 deletions(-) — polylogue/storage/blob_gc.py, polylogue/operations/daemon_workload_probe.py, tests/unit/storage/test_blob_gc.py, tests/unit/storage/test_blob_gc_durable_intent.py, tests/unit/operations/test_daemon_workload_probe.py.

Note on branch topology: This PR's headRefName is feature/storage/blob-authority-foundation, but the assigned correction worktree tracks fix/blob-foundation-final, whose blob-authority files were byte-identical to this PR's head before this fix. There is a separate active worktree already integrating feature/storage/blob-authority-foundation (/realm/worktrees/blob-authority-foundation-integration), so I did not push there myself to avoid colliding with that lane — the fix commit (12034962e) is on origin/fix/blob-foundation-final for that integration lane to pull in.

- fsync the namespace marker file and its containing directory before its
  identity can be recorded in a durable gc_generations row, closing a
  power-loss window that could leave a pending generation pointing at a
  marker that never reached disk.
- stop dry-run GC previews from creating the namespace marker; a read-only
  preview must not mutate the archive or fail against read-only backup
  media, and the namespace identity was never used on the dry-run path.
- filter _candidate_blobs shortlist entries to exactly 64 lowercase-hex
  characters, so a foreign or partially-written shard entry can no longer
  reach _commit_gc_generation_intent and violate the blob_hash CHECK
  constraint; such entries are left for the integrity workflow instead.
- catch RuntimeError (not just OSError/sqlite3.Error) in
  _blob_reference_debt_state so a blocked canonical blob liveness
  projection returns a typed blocked probe state instead of aborting the
  whole daemon workload probe.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA
@Sinity
Sinity merged commit 6f0daba into master Aug 25, 2026
3 checks passed
@Sinity
Sinity deleted the feature/storage/blob-authority-foundation branch August 25, 2026 19:10

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a82f34842

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/storage/blob_gc.py Resolved
Comment thread polylogue/daemon/backup.py Resolved
Comment thread polylogue/storage/blob_liveness.py Resolved
Comment thread polylogue/storage/blob_publication.py Resolved
Sinity added a commit that referenced this pull request Aug 25, 2026
## Summary
Crash-regression test for polylogue-piyqz: monkeypatched unlink failure
mid-batch; durable generation/member intent rows survive and attribute
the partial batch. The write-ahead implementation itself was found
already present on master (landed via the #4149/#4152 line); this PR
pins it against regression.

## Verification
Focused: 49 passed. verify --quick clean. (Luna lane job b46dd19e.)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA
Sinity added a commit that referenced this pull request Aug 26, 2026
## Summary
Corpus run 4 fix lane (surfaces/storage/daemon cluster): 3 real
regressions fixed, 5 stale expectations updated, from the 18-failure
residual set against frozen master `34ddfe09d`.

## Problem (evidence)
- #4201's shared row projection dropped
`terminal_state`/`total_cost_usd`/`relative_time` from the daemon list
payload, breaking direct/daemon JSON parity and the summary display
label (2 tests).
- #4149 regressed `_repair_superseded_raw_snapshots` to open the index
tier read-write even when absent — a destructive cleanup consulting a
just-created empty authority instead of failing closed (1 test).
- Stale expectations (5): synthetic-wire transport representation
(#4184), readiness fixtures pinned at index v72 (now v74),
protocol-message expectations (#4173), topic-caveat fixture (#4173).

## Solution
- Daemon summary payload routes through the shared `session_row`
projection; `display_label` joins the title fallback chain.
- Destructive raw cleanup requires a readable existing index tier;
otherwise returns a typed skipped-unsuccessful result naming the missing
authority.

## Verification
- The 9 target tests: 9 passed; full containing files: 335 passed.
- `devtools verify --quick` + pre-push quick baseline: green.

## Residuals
- `test_clock_guard` (in the corpus-18 set) passed at this lane's
baseline and was left untouched; it fails under some collection orders
and is being diagnosed separately by the overseer.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA
Sinity added a commit that referenced this pull request Sep 29, 2026
)

## Summary
Works the 15 unrecorded Codex P1 findings on `polylogue/maintenance`
(bead polylogue-1tyq5.196). One real defect is fixed here; 13 are
already fixed on master or cite deleted code; one is real but needs a
durable owner-resolution reason and is tracked in its own bead.

## Problem
`_source_exists` only understood the snapshot's `archive!member`
coordinate. The ZIP readers (`decoder_zip.py:304-380`,
`import_explain.py:648`) record `archive:member`, so a raw whose blob
reference was absent was typed blocking `source_lost` while its archive
and member were still on disk.

## Solution
Resolve the colon form through
`polylogue.core.raw_coordinates.zip_member_coordinate`, which tries each
colon and accepts only a prefix that is a real ZIP, so a loose file with
a colon in its name still resolves literally.

## Verification
AgentCTL: `verify_quick` job 2727, `pytest_focused` job 2728 (passed).

## Self-review
- **Sibling sites:** The other consumer of member coordinates in this
module is the frontier join, which already builds `root:member`
(source_conservation.py:895); `_source_exists` was the only `!`-only
parser.
- **Fail closed:** A colon prefix counts only when it is a real ZIP; a
missing ZIP or member returns False, and an unreadable ZIP keeps the
existing container-existence rule.
- **Tests prove the production route:** The tests call `_source_exists`,
the function `audit_source_conservation` uses; the first fails on master
because the colon form returned False.
- **Unbounded work / compatibility / identity:** No new I/O beyond one
namelist per container (cached); no shim or dual path; no hashed or
derived-identity file touched.

## Findings
| Finding | Disposition | Evidence | Test |
|---|---|---|---|
| F001 | fixed-already | Already fixed on master: the blob-integrity
owner passes `active_index_context` through to `_check_blob_integrity`
(polylogue/maintenance/archive_verification.py:1047), introduced in
#4149. | |
| F002 | stale | The browser-capture export-denominator branch and
`_iter_chatgpt_conversations` were removed when #4188 rebased ChatGPT
conservation on the real denominator; nothing on master still runs this
code. | |
| F003 | stale | `polylogue/maintenance/assertion_transition.py` was
deleted in #5079 (9d5a020, the durable-reference transition
actuator). | |
| F004 | stale | `polylogue/maintenance/assertion_transition.py` was
deleted in #5079 (9d5a020), including the successor-manifest holdout
path. | |
| F005 | stale | The closure repair planner
(`plan_blob_reference_closure`, `_acquired_attachment_ids`) was deleted
with the generic repair product in #4698 (cfc4c73);
blob_reference_closure.py is now a read-only law whose predicate
excludes ref_count 0. | |
| F006 | stale | `polylogue/maintenance/cursor_authority_reconcile.py`
was deleted in #4618 (63f2043) with the historical source control
planes. | |
| F007 | fixed-already | Already fixed on master: a present parent with
unresolved references is classified `materialized_unresolved`
(parent_session_accounting.py:397-402) and those references count in
`unresolved_reference_total`, which is part of `blocking_count` (:144,
:493-498). | |
| F008 | tracked | Still real: the writer stores a metadata-only
attachment whose named owner message is absent with ref_count 0 and no
ref, and conservation classifies every such row as the non-blocking
`attachment_unowned`; the owner-resolution reason (`MESSAGE_MISSING` vs
`OWNER_AMBIGUOUS`) is not durable, so the check cannot tell them apart.
| polylogue-3ezec |
| F009 | fixed-already | Already fixed on master:
`acquired_attachment_missing_ref_predicate` requires `ref_count != 0`
(polylogue/storage/blob_liveness.py:27-34), so typed-unowned rows
(ref_count 0) no longer trip attachment-coverage or
blob-reference-closure. | |
| F010 | fixed-already | Already fixed on master: a raw at a configured
path whose digest is not the member's current one is skipped as an
ordinary historical revision (source_conservation.py:930-943). | |
| F011 | fixed-already | Already fixed on master: the content witness is
per membership, matched against any session the raw materialized, so
sibling sessions of a grouped raw no longer report `content_mismatch`
(source_conservation.py:947-970). | |
| F012 | fixed-already | Already fixed on master: mutable-SQLite members
compare the logical-revision digest; the path-only disjunct is gone
(source_conservation.py:899-913). | |
| F013 | fixed-already | Already fixed on master: raws are indexed by
canonical source path once, making the member loop linear
(source_conservation.py:863-872). | |
| F014 | fixed | `_source_exists` now also resolves the
`<container>:<member>` coordinate the ZIP readers record, through the
shared `zip_member_coordinate` parser, so a present member of a present
ZIP is conserved instead of reported `source_lost`. |
tests/unit/maintenance/test_source_conservation_zip_coordinates.py::test_colon_member_coordinate_of_a_present_zip_is_conserved
|
| F015 | fixed-already | Already fixed on master:
`build_wanted_source_receipt` raises when no source is declared
(source_manifest_continuity.py:508-513). | |

## Residuals
F008 stays open in its own bead: telling a missing owner message apart
from an ambiguous owner needs the writer to persist the owner-resolution
reason.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 64a9bd0):

  • P1 polylogue/daemon/backup.py:984: Fixed on master (checked at 64a9bd0): Verification now re-derives the source-owned hashes from the restored source.db through the liveness projection (polylogue/daemon/backup.py:594-600) and requires them to equal the evidence set before resolving canonical blobs (polylogue/daemon/backup.py:1926-1927).

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 5ebcfe5):

Resolving every thread listed; confirmed defects are fixed under the named bead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant