Skip to content

fix(bin): distinguish session lock owners - #102

Merged
Ivory2024 merged 18 commits into
mainfrom
fm/session-lock-daemon-anchor-20261007
Oct 7, 2026
Merged

Ivory2024 merged 18 commits into
mainfrom
fm/session-lock-daemon-anchor-20261007

Conversation

@Ivory2024

@Ivory2024 Ivory2024 commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Intent

The per-home firstmate session lock anchored on a single harness pid, which on Codex and OpenCode resolves to the long-lived server every session shares, so a dead session's lock still read as live, two sessions of one server each claimed the same ownership evidence, and a pid the OS had recycled could never be told from a live owner. Make the lock's identity distinguish process identity (the anchor pid plus its own start identity), harness identity (a shared server is never a session), and session identity (Claude's session id, Codex's thread id, or the pane id a shared server passes down to its tool shells), so that a session ended with its server still alive reads the lock as stale, two sessions sharing one server hold distinct ownership evidence, a live owner cannot be reclaimed, and a recycled pid does not pass as a new owner. Claude's model-loop identity is the reference implementation. Judge owner liveness from all three identity parts, never from pid existence alone, and never fix this by swapping the daemon pid for some other arbitrary pid.

What Changed

  • Track session-lock ownership with the session ID, harness identity, and anchor process start token.
  • Exclude shared Codex and OpenCode servers from lock anchors so ended sessions become reclaimable while live sessions remain protected.
  • Extend ancestry tests for shared-server sessions, separate pane identities, and recycled PIDs.

Risk Assessment

✅ Low: The reviewed implementation keeps shared-server identity separate from session identity and adds no source-verifiable defect in the reviewed paths.

Testing

Ran the focused session-lock regression script and drove fm-lock.sh against isolated disposable process trees. The CLI refused a competing session, reported stale after the owner exited while the server remained, and rejected a PID with a mismatched start identity. Transcript saved as evidence.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
End a session while its shared server stays alive; lock reports stale ✅ pass live Live session-lock CLI transcript
A second session tries to claim a live owner's lock; claim is refused and owner identity is reported ✅ pass live Live session-lock CLI transcript
A recorded PID has a different start identity; it does not pass as the recorded owner ✅ pass live Live session-lock CLI transcript; bash tests/fm-session-lock-ancestry.test.sh
Evidence: Live session-lock CLI transcript

Source: Live session-lock CLI transcript

owner_pid=23466
server_pid=23094
status_owner_live: lock: held by live harness pid 23096
second_session_claim: error: another live firstmate session holds the lock (pid 23096, session thread-a); operate read-only until resolved
status_owner_ended_server_alive: lock: stale (pid 23096 dead, recycled, or not a live harness session)
replacement live harness pid=34151; status: lock: stale (pid 34151 dead, recycled, or not a live harness session)
replacement live harness pid=35985; status: lock: stale (pid 35985 dead, recycled, or not a live harness session)

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-session-lock-lib.sh:487 - A Codex shell whose only harness ancestor is the shared codex app-server takes this branch before the daemon fallback. If the server environment supplies CODEX_THREAD_ID (as the added fixture models at tests/fm-session-lock-ancestry.test.sh:160), separate sessions inherit the same server-owned-thread; session B then matches session A’s sidecar and treats A’s live anchor as its own. This violates the required distinct ownership evidence for sessions sharing a server. Resolve the pane identity for daemon processes before accepting a Codex thread id. Related paths: bin/fm-session-lock-lib.sh:496-503 contains the intended pane fallback; bin/fm-session-lock-lib.sh:580-585 accepts a matching id and harness; bin/fm-session-lock-lib.sh:690-691 then accepts the live recorded owner.

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

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
End a session while its shared server stays alive; lock reports stale ✅ pass live Live session-lock CLI transcript
A second session tries to claim a live owner's lock; claim is refused and owner identity is reported ✅ pass live Live session-lock CLI transcript
A recorded PID has a different start identity; it does not pass as the recorded owner ✅ pass live Live session-lock CLI transcript; bash tests/fm-session-lock-ancestry.test.sh
  • bash tests/fm-session-lock-ancestry.test.sh
  • Ran bin/fm-lock.sh in an isolated FM_HOME under a disposable shared-server process tree; checked owner liveness, competing-session refusal, owner exit, and recorded-PID identity mismatch.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

The session lock recorded a single harness pid, which on Codex and OpenCode
resolves to the long-lived server every session shares: `codex app-server` or
`opencode serve` outlives the session that recorded it, so a dead session's
lock still read as live, two sessions of one server claimed the same
ownership evidence, and pid reuse could never be told from a live owner.

Identity now has three separable parts and every liveness question asks all
three: the anchor pid plus its own start time, harness identity (a shared
server is never a session), and session identity (Claude's session id, Codex's
thread id, or the pane id a shared server passes down to its tool shells). The
lock anchor skips shared servers and resolves the session's own process by pane
identity when its ancestry holds only one, and refuses when it cannot resolve
itself rather than anchoring on something that outlives it. The sidecar beside
the lock records all three, so a pid the OS recycled reads as a dead owner.

Regression coverage pins all four reported failures against the real daemon
shapes across Claude, Codex, and OpenCode.
…process_matches`; daemon filtering remains at its direct callers. `bin/fm-lint.sh bin/fm-session-lock-lib.sh`, `tests/fm-session-lock-ancestry.test.sh`, and `git diff --check` pass. Portable shard runs were still in progress, so their full results are unverified
…sts/fm-session-lock-ancestry.test.sh`: it now disables procfs, so the test exercises unavailable process identity on Linux too. The lock ancestry test and `tests/fm-procevent.test.sh` pass; `git diff --check` is clean. Shard 4’s stale-command failure did not reproduce locally
… use the production birth-token reader, matching Linux procfs ticks and the ps fallback. `tests/fm-session-lock-ancestry.test.sh`, `tests/fm-watch-arm.test.sh`, and `git diff --check` pass
@Ivory2024
Ivory2024 merged commit 99ab8ec into main Oct 7, 2026
19 checks passed
@Ivory2024
Ivory2024 deleted the fm/session-lock-daemon-anchor-20261007 branch October 10, 2026 12:36
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