fix(flow): recover checkpoint locks owned by dead writers
Recover crashed checkpoint writers without stealing a replacement writer’s lock. Writes atomically publish a populated, owner-tagged lock directory. Recovery requires the one-minute grace plus an absent local PID or a different recorded boot/process-start identity. A denied probe (including EPERM), matching live identity or unverifiable live identity preserves the owner. Foreign-host errors and both liveness warnings name the lock path.
Upgrade all writers sharing a checkpoint directory together. The protocol changes from an exclusive file to an owner-tagged directory; old writers do not understand the new ownership/recovery protocol. New writers refuse legacy lock files without modifying the lock or checkpoint. CLI savePause distinguishes that legacy-file error from an unrecognized lock directory: only the file gets stop/verify/remove-only-this-file instructions; a directory containing a future owner format or .DS_Store gets preservation and inspection guidance.
Cleanup removes only the exact owner entry with nonrecursive rmdir. Old, retired local candidate directories left before publication are inspected opportunistically; active, unknown, foreign, recent/future-dated and unrelated entries remain protected.
Validation
Every test command uses systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0, root pnpm/Turbo and already-built siblings. Typecheck and lint: CI, per maintainer instruction; the heavy unused-locals baseline remains deferred to CI. No Rust/WASM rebuild.
pnpm build --filter=@ifc-lite/flow --filter=@ifc-lite/cli --only: both passed.pnpm test --filter=@ifc-lite/flow --filter=@ifc-lite/cli --only -- --maxWorkers=2: flow: 150 passed in 11 files, no skips; CLI: 1,635 passed, 15 skipped (143 passed files, 1 skipped file).- Focused TDD: both unrecognized-directory cases first failed because they received legacy-file removal advice. The new EPERM/path and existing live/foreign-owner cases first failed for missing lock paths. Final focused run: 41 flow checkpoint tests and 18 CLI flow-review tests pass.
node scripts/check-test-revert-oracle.mjs --base origin/main --ci --json --verify-restored: OBSERVED. Both files load with production reverted: 13 flow and 3 CLI behavioral failures; restored witnesses pass (41 and 18 respectively). Independent identity fixtures and filesystem-boundary instrumentation avoid imports/private methods removed by the production revert.pnpm api-surface:update: passed; no exported-symbol snapshot change. Changesets: @ifc-lite/flow minor (0.x on-disk protocol and legacy-error contract change), @ifc-lite/cli patch (actionable file/directory diagnostics).node scripts/pre-handoff.mjs: 13 passed; retained-free viewer skipped because apps/viewer/dist is absent.
Targeted mutation evidence
| Defect / reporting contract | Witness and result |
|---|---|
| Two owners hidden by CAS | #9540 a delayed reaper cannot remove a replacement writer before its CAS parks A at deletion, lets B acquire and park before CAS, then resumes A. Recursive cleanup makes A incorrectly acquire and fails the assertion. |
| PID reuse, host, grace and orphan safety | The previous round killed 17 targeted mutants covering host, boot, birth, unknown capabilities, diagnostics, age, orphan filters, owner parsing and recursive release. The fixtures exercise the store against independent OS-derived on-disk records. |
| EPERM is not death | #9540 EPERM at PID 1 preserves the old owner and reports its lock path uses a real denied process.kill(1,0) as a non-root user; it checks false, surviving owner bytes and a warning. Treating every probe error as ESRCH fails with true instead of false. Removing the warning also fails. |
| Diagnostic lock paths | Removing the path independently from the foreign-host error, denied-probe warning or live-owner warning fails the corresponding identity test. |
| File vs directory advice | .DS_Store and future-format cases drive the real CLI command against the sample model and verify directory/entry preservation and inspection guidance. Broadening the file prefix or removing either classification branch fails these tests or the legacy-file test. |
| Unrelated error preservation | Broadening the directory classifier or dropping the Error type guard fails Error/non-Error identity assertions in the existing pause/resume test. |
All 10 targeted mutants in this round were killed, including the previously surviving EPERM-as-dead mutant. Coverage is not exhaustive; generic I/O/capability errors and every possible interleaving are not independently fault-injected.
Deployment limits and deferred optional work
This coordinates only one host and PID namespace, not NFS/distributed ownership. README now names Kubernetes multi-container pods sharing a volume, Docker host-network setups, WSL2 distros and Windows/WSL sharing when host identities overlap across distinct PID namespaces. A boot identity may be shared or unavailable; hostname plus boot is not a namespace identifier. In such unsupported setups a legitimate writer stopped with SIGSTOP/docker pause for over 60 seconds can be mistaken for a retired owner. Pausing a matching writer in the same supported PID namespace does not expire its lock. Future/clock-skewed mtime may delay recovery. Native Windows EPERM rename handling remains documented but unexecuted; Linux without procfs cannot automatically distinguish a reused live PID.
Optional uniform upgrade formatting for review/resume/updateCheckpoint and the MCP host is deferred: this round changes savePause formatting only, retains their underlying store errors, and adds no MCP source/output-formatting changes or MCP changeset. The CLI guide and flow README cover coordinated upgrades and distinguish unknown directories from legacy files.
🤖 Generated with Claude Code
Summary by CodeRabbit
- Reliability
- Checkpoint saves now use owner-aware locks, helping prevent active writers’ locks from being reclaimed while allowing safe recovery of verified stale locks.
- Unrecognized or unverifiable locks are preserved for inspection rather than removed automatically.
- Important Upgrade Note
- Upgrade all tools that write to a shared checkpoint directory together. For legacy lock files, stop and upgrade all writers before manually removing the file and retrying.
- Documentation
- Added guidance for handling legacy locks and unrecognized lock directories.