Skip to content

feat(migration): apply reviewed graph layer manifests transactionally - #181

Merged
Cipher208 merged 1 commit into
masterfrom
feat/migrate-apply
Nov 2, 2026
Merged

Cipher208 merged 1 commit into
masterfrom
feat/migrate-apply

Conversation

@Cipher208

Copy link
Copy Markdown
Owner

Scope

This PR completes the apply half of the graph-layer migration tool. It does not touch Hermes, Mimocode, CowAgent, or any live database.

The operator flow is now:

  1. inventory — read-only snapshot + evidence manifest;
  2. human edits candidate decision values in the exact manifest;
  3. confirm-token --manifest PATH — token from the exact reviewed bytes;
  4. apply --confirm TOKEN — snapshot + lock-time fingerprint + transactional move.

Safety properties

  • exact manifest-byte confirmation, separate from DB freshness fingerprint;
  • schema/layer/label/user/node/decision preflight before writes;
  • BEGIN IMMEDIATE before the authoritative snapshot;
  • exclusive private 0600 snapshot reservation, SQLite backup including WAL, file+directory fsync;
  • report recovery file fsynced before SQLite commit;
  • rollback on pre-commit report/snapshot failure;
  • recovery report retained and named when final report installation fails after commit;
  • all unapproved node IDs/layers checked, not only manifest candidates;
  • only approved user → agent node layer changes; epi_edges never modified;
  • cross-layer edge count and sample reported after the move;
  • chunked node lookups work beyond SQLite's 32,766-variable limit;
  • output/report/snapshot aliases of DB, WAL, SHM and journal refused;
  • snapshot directory must be outside the live data directory;
  • apply is explicitly rejected when there is no move set.

Verification

The blind verifier exercised 22 preflight/postcondition guards with mutation probes. The final cleanup verifier additionally proved:

  • final snapshot directory fsync errors preserve the original error;
  • installed snapshot remains valid for recovery;
  • staging directories and reserved FDs are cleaned on parent-fsync/fchmod errors;
  • no live database was touched.
pytest -q            2818 passed
ruff check / format  clean / 750 files
mypy source dirs     clean; repository baseline remains 63 errors outside touched source

Explicit non-goal

No live apply is performed by CI or this PR. After merge, we will run inventory with the approved marker/exclusion files, review the three manifests, then request a separate explicit write authorization before applying to each base.

The read-only inventory can now be applied only through an exact-manifest
confirmation token and an explicit decision policy. Apply verifies the DB
fingerprint, candidate ownership, layer and IDs before any write; takes a
private 0600 SQLite snapshot under BEGIN IMMEDIATE; verifies the snapshot
matches the reviewed fingerprint; moves only approved node layers in one
transaction; and checks every moved and unapproved node's layer before commit.
Edges are never rewritten — resulting cross-layer links are reported.

Recovery is part of the commit boundary: a fsynced recovery report is staged
before SQLite commits; if final installation fails the path is reported, and
if writing or fsyncing the report fails the DB transaction rolls back. Snapshot
reservation is exclusive and atomic, and all snapshot/report destinations are
checked against the DB, WAL/SHM/journal and each other.

No live base is touched by this PR. The tool is exercised only against temporary
copies; running it on Hermes/Mimocode/CowAgent still requires a reviewed
manifest and the separately approved MIGRATE-<database>-<manifest-sha> token.
@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Important

  • Trigger review

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

Run configuration
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@Cipher208
Cipher208 merged commit 5f2656d into master Nov 2, 2026
19 checks passed
@Cipher208
Cipher208 deleted the feat/migrate-apply branch November 2, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant