Skip to content

fix(store): preserve and rebuild SQLite project manifests across worker init and store move - #751

Merged
yifanxuaaa merged 2 commits into
Ephemeral-AI-Lab:layerfs_v2_0_0from
jiangkoumo:fix/749-move-manifest
Nov 22, 2026
Merged

yifanxuaaa merged 2 commits into
Ephemeral-AI-Lab:layerfs_v2_0_0from
jiangkoumo:fix/749-move-manifest

Conversation

@jiangkoumo

Copy link
Copy Markdown
Collaborator

Tier: P1 (control/crates/layerfs-store) ; risks: risk:store ; gate: yes: risk:store ; de-escalated: none

Refs #749.

Reason

  • When a user runs project init on a worker machine (for example docker), add_project (control/crates/layerfs-store/src/project/add.rs) computes (manifest, installed) in the worker's store directory, but its response omitted those encoded bytes. The host's init_on_worker (control/crates/layerfs-store/src/project/family.rs) therefore wrote an 88-byte {v, name, stack, created} stub without manifest or installed.
  • Running store move back to native transferred store.sqlite and deleted the worker's store directory in retire without populating the host's project records, permanently destroying the only copy of the manifest. Subsequent sandbox create --machine native (and even moving back to docker) failed with NotFound: no complete project manifest (NoSuchProject).
  • project doctor (control/crates/layerfs-control/src/doctor/project_target.rs) only checked whether record.json parsed as JSON and read the text stack field, so project doctor --full still reported ok: true on broken 88-byte records.
  • In review round 1 (f57829a3c -> 9831deab2), propagating ProjectRecord::read / repair errors with ? during store.move's record phase allowed one corrupted project record.json (such as {) to abort store.move after install, leaving op.phase = "record" and uncertain = true and blocking healthy projects on the same Store with Busy.

What changed

  • Return and persist manifests on worker project.init: add_project (control/crates/layerfs-store/src/project/add.rs) now returns encoded manifest and installed bytes (SdkValue::Bytes), and init_on_worker (control/crates/layerfs-store/src/project/family.rs) validates and writes them into the host ProjectRecord while remaining compatible with older workers that omit them.
  • Read-only diagnostic project repair with per-project fault isolation: control/crates/layerfs-store/src/backup/restored.rs exposes complete, adds projects_in_diagnostic (using layerfs_persistence::SqliteHandles::open_diagnostic so no -wal/-shm or byte changes occur), complete_existing, and single-project repair_project. complete_existing skips per-project read, rebuild, or write errors instead of altering corrupted JSON or aborting repair of other valid incomplete projects.
  • Best-effort record repair during store.move: control/crates/layerfs-store/src/sqlite/transfer/phases.rs runs complete_existing during the record phase whenever source or target is Executor::Local, ignoring errors as incidental best-effort work so store.move proceeds cleanly to retire and clears op.
  • On-demand repair during sandbox.create: control/crates/layerfs-sandbox/src/lifecycle.rs catches NoSuchProject: no complete project manifest in installed when local store.sqlite exists, repairs the record via restored::repair_project, and retries discovery::project.
  • Validate SQLite completeness in project doctor: control/crates/layerfs-control/src/doctor/project_target.rs checks restored::complete(&project) for non-init SQLite projects and reports a project.record error when manifest or installed is missing/invalid.
  • Tests and architecture docs: Added regression tests covering worker init persistence, bidirectional store.move and sandbox.create self-repair, project doctor, and skipping unreadable record.json files during store.move; updated architecture docs in the same change.

Scope

  • Production files:
    • control/crates/layerfs-store/src/project/add.rs
    • control/crates/layerfs-store/src/project/family.rs
    • control/crates/layerfs-store/src/backup/restored.rs
    • control/crates/layerfs-store/src/sqlite/transfer/phases.rs
    • control/crates/layerfs-sandbox/src/lifecycle.rs
    • control/crates/layerfs-control/src/doctor/project_target.rs
  • Test files:
    • api/crates/layerfs-api/tests/project_family.rs
    • api/crates/layerfs-api/tests/doctor_targets.rs
    • control/crates/layerfs-store/tests/restored_records.rs
    • control/crates/layerfs-sandbox/tests/installed_repair.rs
  • Architecture docs:
    • docs/architecture/control/stores-and-projects/projects.md
    • docs/architecture/control/stores-and-projects/sqlite-and-postgresql.md
    • docs/architecture/control/sandboxes/README.md
    • docs/architecture/control/doctor/README.md
  • Production LOC (python3 -B tools/production_loc.py --json, ed9118963 -> 9831deab2): 205844 -> 206049 (delta +205) (core: 40988 -> 40988, engine: 95845 -> 95845, control: 58745 -> 58950 (+205), api: 10266 -> 10266; reference absent, retired R9c).

Trade-offs

  • No wire protocol or DaemonSetup format changes: Keeping the fix in control avoids cross-component wire/bundle compatibility breaks and leaves PostgreSQL Stores and native -> docker init paths unchanged.
  • Diagnostic read-only SQLite open and best-effort record-phase repair: Opening store.sqlite with SqliteHandles::open_diagnostic preserves byte-for-byte Store identity across empty Store moves. Treating complete_existing in store.move's record phase as best-effort ensures a corrupt record.json (which is left untouched) cannot stall store.move with op.phase = "record" and uncertain = true.
  • Backward compatibility and project doctor fix: null: Missing manifest/installed from older workers is accepted at init_on_worker and repaired lazily during store.move or sandbox.create. project doctor keeps fix: null because store move <s> native mutates Store placement if the Store still sits on a worker.

Impact

  • Fixes SQLite project init on worker machines, docker <-> native round-trip store move, on-demand sandbox create recovery for pre-existing 88-byte records, fault isolation when another project's record.json on the same Store is unreadable, and project doctor / project doctor --full detection.
  • Not changed / not tested: PostgreSQL Store paths are untouched. Pre-existing SQLite projects lacking a main branch in store.sqlite cannot be reconstructed read-only and still refuse with NoSuchProject. Verification ran on Linux (unit/integration suites, full Linux CI lanes fast/slow/mount/pg, and the Docker E2E suite re-run on 9831deab2 under namespaces runtime) and on real-machine macOS (Apple Silicon: Colima aarch64 docker worker, Apple Container 1.6.1, and Lima 2.2.1 with native loopback NFS sandbox); only Windows remains untested (the 30 s first-time uncached Lima machine create timeout is a pre-existing issue on base ed9118963, tracked in 首次创建 Lima 机器因 limactl create 30 秒超时必失败(无镜像缓存时) #750 and unrelated to this PR).

Verification and how to re-run

  • Static checks, fmt, clippy, and targeted binaries on 9831deab2 (tests built with --no-run first and executed under TMPDIR=/tmp timeout 120):
    • python3 -B tools/check_product_boundary.py (PASS: scanned 1596 production Rust/SQL/JavaScript files)
    • python3 -B -m unittest discover -s tools -p 'test_*.py' (181 tests ... OK)
    • cargo +1.85.1 fmt --all -- --check (passed)
    • cargo +1.85.1 clippy --locked --all-targets -- -D warnings (passed)
    • restored_records (7 passed), store_transfer_recovery (4 passed), project_family (7 passed, including move_skips_unreadable_project_record_and_still_repairs_incomplete_ones which failed with exit 101 before 9831deab2), store_family (5 passed, 1 ignored), doctor_targets (7 passed).
  • Full CI lanes on 9831deab2:
    • fast: 2918 tests run: 2901 passed (2 slow, 1 leaky), 17 failed, 26 skipped (all 17 failures reproduce identically on base ed9118963 in the same environment: machine_power::start_and_stop_a_machine, 10 tests in sandbox_get_no_lease, sandbox::workspace_isolation, plus 5 TMPDIR SUN_LEN/0700 tests that pass on fix749 under TMPDIR=/tmp; 0 new failures).
    • slow: 177 tests run: 176 passed (4 slow), 1 failed, 11 skipped (the sole failure layerfs-persistence::writer_admission read_only_close_does_not_wait_for_a_held_writer_lane fails on ed9118963 for SUN_LEN and passes on fix749 under TMPDIR=/tmp).
    • mount: pass=46 fail=0.
    • pg: layerfs-persistence (29/29), layerfs-store-service (10/10), layerfs-project (1/1), layerfs-api (2/2), layerfs-cli (2/2) passed; layerfs-control [password] exited 101 because doctor_store_postgresql does not exist in layerfs-control (identical on base ed9118963).
    • Re-ran real Docker E2E on 9831deab2 (LAYERFS_SANDBOX=namespaces, real Docker worker): passed 3/3 new-project round trips, 3/3 legacy 88-byte recovery scenarios, the native -> docker -> native control case, plus the new mixed corrupted-record scenario (good + 88-byte legacy + {-corrupted damaged in the same Store: bidirectional store move completed without op/uncertain, damaged/record.json stayed {, legacy was repaired, good/legacy sandboxes mounted and executed ls -la, and project doctor --full reported project.record error on damaged).
    • Real-machine macOS E2E on 9831deab2 (Apple Silicon, Colima aarch64 docker worker + native loopback NFS sandbox): passed the new-project round trip (docker -> native -> docker), both pre-existing 88-byte broken-record repair paths (store move native and direct sandbox create --machine native), and the native -> docker -> native control case.
    • Real-machine macOS Apple Container 1.6.1 and Lima 2.2.1 E2E on 9831deab2 (Apple Silicon M2 Air, with pre-warmed Lima image cache): passed all 4 scenarios on both runtimes (new-project round trip, both pre-existing 88-byte broken-record repair paths, and the native -> vm -> native control case). The uncached first-time Lima machine create 30 s timeout is a pre-existing baseline issue (ed9118963) tracked in 首次创建 Lima 机器因 limactl create 30 秒超时必失败(无镜像缓存时) #750 and unrelated to this PR.
  • Durable: NOT_RUN — disabled by owner until explicit reauthorization.

…r init and store move

project.init on a worker machine now returns encoded manifest and installed bytes so init_on_worker writes the complete host ProjectRecord instead of the 88-byte PostgreSQL stub. store.move completes any existing incomplete SQLite project record read-only via SqliteHandles::open_diagnostic when moving to or from native, and sandbox.create (lifecycle::installed) repairs an existing incomplete local SQLite record on demand. project.doctor fails project.record when a SQLite project without an init op lacks a complete manifest.

Tests: new project_family worker_inited_project_keeps_manifest_across_move_to_native_and_back and move_and_sandbox_repair_an_existing_incomplete_project_record, doctor_targets a_sqlite_project_without_a_manifest_fails_project_doctor, restored_records repair_project_completes_an_incomplete_record_from_sqlite_store, installed_repair sandbox_create_repairs_an_incomplete_sqlite_project_record; updated doctor_targets a_project_s_record_is_checked_against_its_store fixture to carry valid manifests.
Docs: docs/architecture/control/stores-and-projects/projects.md, docs/architecture/control/stores-and-projects/sqlite-and-postgresql.md, docs/architecture/control/sandboxes/README.md, docs/architecture/control/doctor/README.md.
Durable: NOT_RUN — disabled by owner until explicit reauthorization.

Production LOC: 205844 -> 206050 (delta +206)
  core     40988 -> 40988 (0)
  engine   95845 -> 95845 (0)
  control  58745 -> 58951 (+206)  layerfs-store +161, layerfs-sandbox +32, layerfs-control +13
  api      10266 -> 10266 (0)
  reference absent (retired R9c; last counted 65,417 at tree 498dd19)
  Method: tools/production_loc.py --root on parent ed91189 (/data/wt/dshv2-repro) and the staged tree
Make complete_existing skip per-project read, rebuild, and write errors
so a single corrupted project record.json is left untouched and neither
aborts repairing other incomplete records nor breaks healthy projects.
Also treat complete_existing during store.move's record phase as
incidental best-effort so record-repair failure cannot stall store.move
at op.phase = "record" with uncertain = true.

Tests: added project_family
move_skips_unreadable_project_record_and_still_repairs_incomplete_ones;
ran restored_records (7 passed), store_transfer_recovery (4 passed),
project_family (7 passed), store_family (5 passed, 1 ignored),
doctor_targets (7 passed), and lf-ci.sh fast (2901/2918 passed, 17
pre-existing env/baseline failures).
Durable: NOT_RUN — disabled by owner until explicit reauthorization.

Production LOC: 206050 -> 206049 (delta -1)
  core     40988 -> 40988 (0)
  engine   95845 -> 95845 (0)
  control  58951 -> 58950 (-1)  layerfs-store -1
  api      10266 -> 10266 (0)
  reference absent (retired R9c; last counted 65,417 at tree 498dd19)
  Method: tools/production_loc.py --json on parent f57829a and the staged tree
@yifanxuaaa
yifanxuaaa merged commit fae5488 into Ephemeral-AI-Lab:layerfs_v2_0_0 Nov 22, 2026
2 checks passed
yifanxuaaa added a commit that referenced this pull request Nov 22, 2026
fix(store): review follow-ups to #751 project-record repair
yifanxuaaa added a commit that referenced this pull request Nov 22, 2026
…rol-plane fixes)

Brings in the six origin commits (#751, #754, #755 and the store.move manifest repairs) beside the local LF14 commit 712f4d0.

Production LOC: 205907 -> 206226 (delta +319); first-parent comparison (parent 712f4d0 vs the merged tree), counted with tools/production_loc.py --root on git archive extracts of both snapshots; control scope 58808 -> 59068 (delta +260). Reference absent (retired R9c; last counted 65,417 at tree 498dd19).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jiangkoumo pushed a commit to jiangkoumo/layerfs that referenced this pull request Nov 23, 2026
…repair

Review of Ephemeral-AI-Lab#751 (merged as fae5488) found these; each is fixed here.

- project doctor: a SQLite project's record must be complete only where
  this process runs the Store's calls. A worker's Sandboxes read the
  entry that worker keeps, so a host stub there is not a project.record
  fault. A failed project.record no longer skips project.listed or the
  --full project.data walk.
- sandbox.create: the repair is decided by the record (no manifest, no
  installed, or bytes that do not decode), not by one refusal message,
  and is best effort: a repair that fails or cannot complete the record
  leaves the call's own refusal as it was. The repaired record is decoded
  in hand (discovery::project_of) instead of reading the entry again.
- store.move: a record the record phase leaves incomplete is a line of
  log/repair.jsonl (call, store, project, why) instead of a silent drop.
- project.init on a worker: a manifest/installed pair that is not a
  complete Disposable pair (restored::complete) is left out and logged in
  log/repair.jsonl, for a move or Sandbox create to complete.
- restore and record repair share one Store scan, restored::found_in.

Tests: doctor_targets checks project.listed still runs after a
project.record failure; project_family checks store.move logs a record it
cannot rebuild; installed_repair removes a Sandbox it did start instead of
requiring create to fail; restored_records follows repair_project's new
return (the written record). No tests deleted.
Ran (TMPDIR=/tmp, 120 s limit each): restored_records 7, installed_repair
1, doctor_targets 7, project_family 7, backup_family 5, project_doctor_full
3, project_init_worker 7, store_family 5 (1 ignored), store_transfer_crash
6, layerfs-control doctor 12, project_delete_worker 14,
store_transfer_recovery 4, restore_install 3: all pass. fmt, Clippy
(-D warnings) on layerfs-store/-sandbox/-control/-api and the product
boundary guard pass. Not run: a doctor of a project whose Store is on a
ready worker machine (needs a running VM), a restore from a bucket.
Docs: doctor, home, sandboxes, projects, sqlite-and-postgresql.
Durable: NOT_RUN — disabled by owner until explicit reauthorization.

Production LOC: 206,108 -> 206,163 (delta +55)
  core     40,988 -> 40,988 (0)
  engine   95,845 -> 95,845 (0)
  control  58,950 -> 59,005 (+55)  layerfs-store +48, layerfs-control +8, layerfs-sandbox -1
  api      10,325 -> 10,325 (0)
  reference absent (retired R9c; last counted 65,417 at tree 498dd19)
  Method: tools/production_loc.py --detail on parent fae5488 and the staged tree

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants