Skip to content

fix(bin): reclaim dead checkpoint session locks - #6182

Open
maruthiprithivi wants to merge 4 commits into
kunchenguid:mainfrom
maruthiprithivi:fm/firstmate-supervision-reconnect-deepseek
Open

maruthiprithivi wants to merge 4 commits into
kunchenguid:mainfrom
maruthiprithivi:fm/firstmate-supervision-reconnect-deepseek

Conversation

@maruthiprithivi

@maruthiprithivi maruthiprithivi commented Sep 30, 2026 •

Copy link
Copy Markdown

Intent

Restore checkpoint supervision when the recorded session-lock owner is provably dead, while preserving exclusion of live owners and safe handling of uncertain lock state.

What Changed

  • Added Codex checkpoint recovery for a provably dead session-lock owner, delegating reclaim through fm-lock.sh before supervision host activation.
  • Preserved existing safety boundaries so checkpoints leave live foreign owners, owned locks, malformed locks, and absent locks untouched.
  • Documented the arm-owner reclaim behavior and added checkpoint regression coverage for dead-owner reclaim, live-owner refusal, and unchanged owned/absent locks.

Risk Assessment

✅ Low: The change is narrowly scoped to Codex checkpoint stale-lock recovery, delegates mutation to the existing lock owner, preserves live-owner and absent/malformed-lock behavior, and the added tests exercise observable checkpoint behavior rather than source text.

Testing

Ran the targeted fm-watch-checkpoint product-level test script against isolated disposable homes, covering dead-owner reclaim, live-owner no-steal, absent/owned-lock no-op behavior, and existing supervision-host checkpoint behavior; all scenarios passed and the worktree stayed clean.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
A replacement Codex checkpoint finds a dead recorded session-lock owner, reclaims through the real lock writer, and runs a bounded supervision-host park instead of standing down. ✅ pass live tests/fm-watch-checkpoint.test.sh in fm-watch-checkpoint-targeted.log: ok - checkpoint: a replacement session reclaims a provably dead session-lock owner
A checkpoint encountering a live foreign harness owner leaves the lock byte-identical and reports the supervision-host stand-down. ✅ pass live tests/fm-watch-checkpoint.test.sh in fm-watch-checkpoint-targeted.log: ok - checkpoint: a live session-lock owner is never reclaimed by the checkpoint
A checkpoint with an already-owned lock or no lock does not rewrite ownership or claim an uncertain home. ✅ pass live tests/fm-watch-checkpoint.test.sh in fm-watch-checkpoint-targeted.log: ok - checkpoint: an owned or absent session lock is never rewritten or claimed
Existing checkpoint host behavior still bounds real host parks, preserves watcher environments, passes handbacks, and honors supervision-host opt-in/off controls. ✅ pass live tests/fm-watch-checkpoint.test.sh in fm-watch-checkpoint-targeted.log: existing host checkpoint cases remained green
Evidence: Focused fm-watch-checkpoint test transcript

Source: Focused fm-watch-checkpoint test transcript

ok - quiet checkpoint exits 124 with a clean checkpoint line and no live lock
ok - checkpoint passes through a real watcher wake and leaves the queue for drain
ok - checkpoint preserves watcher environment for registered custom checks
ok - checkpoint rejects an existing watcher singleton as unowned
ok - checkpoint: an opted-in home runs the host for the checkpoint's bound, raised only while away
ok - checkpoint: a handed-back wake passes through, and a host stand-down is a failure
ok - checkpoint: a Codex home without config/supervision-host, or with an off file, never runs the host
ok - checkpoint: the real host ends its park at the checkpoint bound as a quiet checkpoint
ok - checkpoint: a replacement session reclaims a provably dead session-lock owner
ok - checkpoint: a live session-lock owner is never reclaimed by the checkpoint
ok - checkpoint: an owned or absent session lock is never rewritten or claimed

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • 🚨 bin/fm-watch-checkpoint.sh:75 - The checkpoint now unconditionally sources fm-session-lock-lib.sh, but the host fixture used by the existing make_host_home tests only copies fm-watch-checkpoint.sh and fm-supervision-engine-lib.sh into its fake root. A concrete run of test_host_checkpoint_bounds_the_park_by_posture uses $hometask-local-workspace; before it can invoke the stub host, line 75 sources a file that is absent in that fixture root, so the test harness exits before exercising the behavior it is meant to cover. The same fixture affects test_host_checkpoint_passes_a_handback_and_reports_a_stand_down and test_host_checkpoint_needs_the_file_and_honors_off in tests/fm-watch-checkpoint.test.sh:96. Copy the new sourced lock helper and its direct dependency, or keep the fixture using the repository script root for shared libs.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
A replacement Codex checkpoint finds a dead recorded session-lock owner, reclaims through the real lock writer, and runs a bounded supervision-host park instead of standing down. ✅ pass live tests/fm-watch-checkpoint.test.sh in fm-watch-checkpoint-targeted.log: ok - checkpoint: a replacement session reclaims a provably dead session-lock owner
A checkpoint encountering a live foreign harness owner leaves the lock byte-identical and reports the supervision-host stand-down. ✅ pass live tests/fm-watch-checkpoint.test.sh in fm-watch-checkpoint-targeted.log: ok - checkpoint: a live session-lock owner is never reclaimed by the checkpoint
A checkpoint with an already-owned lock or no lock does not rewrite ownership or claim an uncertain home. ✅ pass live tests/fm-watch-checkpoint.test.sh in fm-watch-checkpoint-targeted.log: ok - checkpoint: an owned or absent session lock is never rewritten or claimed
Existing checkpoint host behavior still bounds real host parks, preserves watcher environments, passes handbacks, and honors supervision-host opt-in/off controls. ✅ pass live tests/fm-watch-checkpoint.test.sh in fm-watch-checkpoint-targeted.log: existing host checkpoint cases remained green
  • mkdir -p ~/.no-mistakes/evidence/validation-run && tests/fm-watch-checkpoint.test.sh | tee ~/.no-mistakes/evidence/validation-run/fm-watch-checkpoint-targeted.log
  • git status --short
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A Codex home that runs the supervision host loses supervision for good once
its harness process is replaced: state/.lock line 1 still records the
predecessor's anchor pid, which is no longer a live verified harness, so
bin/fm-supervision-host.sh refuses ownership before activation
("supervision-host stood down: this session does not own supervision"),
starts no watcher cycle, and every later checkpoint in that session repeats
the refusal. The watcher beacon cannot advance because nothing is beating,
and only a manual bin/fm-lock.sh run restores supervision.

The checkpoint is that home's arm owner, but it was the only shell arm owner
that neither reclaimed a provably dead owner nor named the recovery. The
Claude Stop auto-arm (bin/fm-claude-stop-autoarm.sh) and the Cursor stop hook
(bin/fm-turnend-guard-cursor.sh) both delegate a lock whose recorded pid is
not a live verified harness to bin/fm-lock.sh, the single acquisition owner,
before they touch supervision state. This change gives the Codex checkpoint
that same guarded step before it runs the host.

Fail-closed behavior is unchanged: a live owner this session does not own is
never reclaimed, an absent or malformed lock stays uncertain, and the reclaim
uses bin/fm-lock.sh's own claim lock so lock exclusion has one owner. Homes
without config/supervision-host have no ownership gate and are untouched.

Tests cover the replacement-session reclaim (fails before this change), that
a live session-lock owner is never stolen, and that an owned or absent lock
is never rewritten or claimed.
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Adds session lock reclamation to checkpoint supervision.

The PR appears safe to merge, with a non-blocking correction needed to the arm-owner documentation.

Reviews (2) · Last reviewed commit: "no-mistakes(ci): Fixed ci-1/ci-2. `fm-wa..."

Comment thread bin/fm-watch-checkpoint.sh Outdated
Comment thread docs/supervision-host.md Outdated
…ms only when `fm_session_lock_inspect` classifies the lock as `stale`, so absent, malformed, held, and unknown/live non-harness owners fail closed. Added a regression that writes a live unrelated process PID to `state/.lock`, runs the checkpoint through a fake Codex harness, and verifies the host stands down while the lock remains unchanged. Updated `docs/supervision-host.md` to distinguish absent/malformed/unknown/live-foreign stand-downs from provably dead-owner reclaim. Verified with `bash tests/fm-watch-checkpoint.test.sh`, `bash bin/fm-lint.sh`, and `bash bin/fm-doc-audience-check.sh`
Comment thread docs/supervision-host.md
Grok's model-owned call relies on primary detection.
The host pins dispatched work to the primary's crew harness rather than the engine's.

The Claude auto-arm, the Cursor stop hook, and the Codex checkpoint own a home the way `bin/fm-lock.sh` records it, so before they run the host they reclaim a lock whose shared inspection proves a dead recorded owner through that same writer; absent, malformed, unknown, and live foreign locks are left untouched, and the OpenCode, omp, and Pi adapters instead refuse to arm a home with no live owner and name the recovery.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Unknown lock behavior misstated If a lock records a live non-harness PID, this paragraph says Claude Stop and Cursor leave it untouched. Both hooks instead pass any numeric PID that is not a live verified harness to fm-lock.sh, which can reclaim the lock. Codex does leave it untouched. This difference matters when operators diagnose ownership or decide whether an unknown lock is safe from takeover.

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