Skip to content

Fix managed-block metadata CAS and preview partial recovery - #203

Open
Yehonal wants to merge 7 commits into
mainfrom
pr/cas-block-hash
Open

Yehonal wants to merge 7 commits into
mainfrom
pr/cas-block-hash

Conversation

@Yehonal

@Yehonal Yehonal commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Managed instruction metadata transactions compared a recorded block hash with the whole live file hash, rejecting valid files containing surrounding guidance. Compute the CAS hash from the selected live block, preserve exact snapshot and inventory checks, and resolve older block guards from their verified inventory. Entire-file guards retain file hashing.

Add mutation recover-runtime --dry-run and matching previews on mutation recover and mutation finalize for guarded zero-operation metadata partials. The preview reads receipt-bound journals and guards without locks, writes, or revision-provider calls; it identifies runtime recovery as the required next command and leaves normal partial-finalization refusal intact.

Regression coverage includes 8,593 bytes before a managed block, block/file hash separation, altered blocks and snapshots, legacy journals without a selector, and API/CLI previews with unchanged files and rejected write calls. Validation runs in CI (typecheck, build, full test suite and CLI smoke checks).

No merge or runtime installation is included.

@Yehonal Yehonal left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not ready: 2 blocking findings at head 58b57be. The CAS change looks right on reading, but CI test is red and the new tests do not run, so none of it is proven yet.

Blocking

  1. The new regression test fails on every case (11/11). test/managed-block-metadata-cas.test.ts:27 writes the install manifest with revision: "pending", and writeInstallManifest rejects it (ZodError: revision … >=16 characters, src/install/manifest.ts:124). I reproduced it locally on this head and CI shows the same. Other fixtures use e.g. "pending-fixture-revision" (run-as-metadata.test.ts:54). Because the fixture never gets past setup, there is currently no evidence that the 8,593-byte case fails on main and passes here.
  2. Two ownership-handoff-audit tests fail in CI. vi.spyOn(fs, "open") at test/ownership-handoff-audit.test.ts:78 throws Cannot spy on export "open". Module namespace is not configurable in ESM. The "preview is read-only" proof therefore does not run. Use vi.mock("node:fs/promises", …) with a passthrough, or compare tree snapshots plus an strace-free check such as a read-only directory, instead of spying on the namespace.

What I checked by reading (looks correct, pending green tests)

  • CAS block vs block. Guards with managedBlock compare exactManagedInstructionBlockSnapshot(...).hash with guard.hash. The snapshot digest, the sha format checks, the full canonical managedBlock comparison and the inventory revision guard are all still there.
  • No weakening elsewhere. Whole-file and no-block guards still use transport.hashPath. retire-stale, migrate-legacy, handoff-audit and release never set managedBlock, so they keep the whole-file path. Only adopt-legacy now stores the block hash.
  • Preview. previewMetadataJournal refuses journals with operations or completions, runs the guards with readOnly, and takes no lock or write in the code I read. This is the part to re-check once the test actually runs.

Question, not blocking by itself. A journal created before this change (like the existing partial 28e2a9b0) holds a whole-file guard.hash together with managedBlock. After this PR the CAS compares that value with the block hash and would still fail. The PR text mentions resolving older block guards from the verified inventory, but that logic is not in this head (maybe in the expected b9c4c19). Please make sure the final head covers it, with a test that loads such a legacy journal.

Re-review on the next head once test is green.


Generated by Claude Code

This branch has not been deployed

No deployments
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