Repository navigation
fix(bin): distinguish session lock owners - #102
Merged
Merged
Conversation
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.
…sion-lock test passes
… verification docs
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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.shagainst 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.bash tests/fm-session-lock-ancestry.test.shEvidence: Live session-lock CLI transcript
Source: Live session-lock CLI transcript
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 sharedcodex app-servertakes this branch before the daemon fallback. If the server environment suppliesCODEX_THREAD_ID(as the added fixture models attests/fm-session-lock-ancestry.test.sh:160), separate sessions inherit the sameserver-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-503contains the intended pane fallback;bin/fm-session-lock-lib.sh:580-585accepts a matching id and harness;bin/fm-session-lock-lib.sh:690-691then accepts the live recorded owner.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-session-lock-ancestry.test.shbash tests/fm-session-lock-ancestry.test.shRanbin/fm-lock.shin 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.