Repository navigation
fix(bin): read session-lock owner identity without the ps binary - #7609
Conversation
44b1fb2 to
0ffc012
Compare
|
Speaking as Kun's firstmate: thank you @kesslerio. This is careful work on a nasty failure mode. A home that's permanently lock-refused, or a live owner that gets taken over, is exactly the kind of thing that should never happen quietly. I read head What I checked:
Contract-class (mine): restore. The session lock is an existing default path, and its promise is to refuse a live owner and reclaim a dead one. On a host where VISION.md, rule by rule
One warm ask, no rush (waiting on you): #5238 was reported on a hardened macOS host, and the macOS provider is the one part nothing has exercised yet. Your body says so, and the pipeline's live verdict is 1 of 4. When you get the chance, could you run this head on a macOS host where |
|
A note for the rebase over #6300 (merged 2026-10-23): main's session lock can now hold a Windows-tagged owner, At head A tagged value probably needs its own branch: validity from |
|
Speaking as Kun's firstmate: a quick update on where this stands, @kesslerio. Two things changed on main's side since my 10-21 note:
Still open from 10-21: the macOS ps-denied live trace (a fresh session takes the lock, a second session is refused while the first is alive, and Please rebase, cover the tagged owner, and re-raise with Status: waiting on you. |
01b6a3c to
a447924
Compare
|
Speaking as Kun's firstmate: thank you @kesslerio, this round covers both things from my 10-24 note. What I checked at
The conflict is ours to fix, and you don't need to rebase. Main moved to Contract-class (mine): restore, unchanged. The session lock's existing promise is to refuse a live owner and reclaim a dead one, and on a ps-denied host that promise was broken. VISION.md: it aligns on every rule, the same as 10-21. Authority is explicit: no platform now lets a live owner be taken over. Status: on our side, not waiting on you. Once the conflict is resolved, CI needs to go green on the merged head. Then it's on the auto-merge path. |
|
Speaking as Kun's firstmate: thank you @kesslerio for sticking with this. I tried to land it through a port of your change, resolved against main after #7746 (#7845), and CI turned up a few things that come from the current head here (
Could you take a look at those when you have a moment? Two other failures on the port are on our side and not yours: the test coverage guard's shard budget (fixed by a pending shard change), and a serial job hitting the time cap. The merge conflict with main is also ours to resolve; you don't need to rebase. Once the three items above pass, we'll take it from there. I'm closing the port #7845 so there's one place to work: this PR. |
|
Fixed in db73c9d8. Root cause of the three CI failures at a4479244.
The same commit added a Windows-tagged pre-block that decided The fix decides the verdict once. The Evidence:
The merge conflict and the rebase are untouched, since those are owned here. Failures that predate this diff, reproduced both at a4479244 with the fix stashed and on upstream main in this checkout, so not caused by it: the pty-host reparent assertion in fm-session-lock-ancestry, the dead-steal-owner reclaim in fm-watcher-lock, harness resolution in fm-secondmate-harness, and fm-backlog-read-bound, fm-claude-stop-autoarm, fm-omp-harness, fm-session-start. Each fails because of this host's process and environment shape, not the session-lock change. The exact patch, for a port that does not take the branch: diff --git a/bin/fm-session-lock-lib.sh b/bin/fm-session-lock-lib.sh
index de057dd4..b3eb8e51 100644
--- a/bin/fm-session-lock-lib.sh
+++ b/bin/fm-session-lock-lib.sh
@@ -840,7 +840,7 @@ FM_LOCK_INSPECT_STATE=unknown
FM_LOCK_INSPECT_PID=
FM_LOCK_INSPECT_LIVE_HARNESS=unknown
fm_session_lock_inspect() { # <state>
- local state=$1 lock pid winpid win_rc
+ local state=$1 lock pid
# shellcheck disable=SC2034 # Output globals, read by lock status and inbox ready.
FM_LOCK_INSPECT_STATE=unknown
# shellcheck disable=SC2034 # Output globals, read by lock status and inbox ready.
@@ -865,14 +865,10 @@ fm_session_lock_inspect() { # <state>
# shellcheck disable=SC2034 # Output global, read by lock status and inbox ready.
FM_LOCK_INSPECT_PID=$pid
fm_session_pid_valid "$pid" || return 0
- if winpid=$(fm_win_untag_pid "$pid"); then
- # The same verdicts as a local pid below, read from the Windows table.
- if fm_harness_pid_alive "$pid"; then
- FM_LOCK_INSPECT_STATE=held
- FM_LOCK_INSPECT_LIVE_HARNESS=true
- return 0
- fi
- fi
+ # One verdict for every identity form. A tagged Windows pid is resolved by
+ # this same call through the Windows table, so the match below is the single
+ # place "live verified harness" is decided; deciding it a second time ahead
+ # of this one is what let a holder read as held there and unknown here.
fm_session_lock_pid_verdict "$pid"
case "$FM_SESSION_LOCK_PID_VERDICT" in
dead)
@@ -882,8 +878,15 @@ fm_session_lock_inspect() { # <state>
FM_LOCK_INSPECT_LIVE_HARNESS=false
;;
readable)
- FM_LOCK_INSPECT_STATE=unknown
- FM_LOCK_INSPECT_LIVE_HARNESS=false
+ if fm_harness_process_matches "$FM_PROC_COMM" "$FM_PROC_ARGS"; then
+ # shellcheck disable=SC2034 # Output globals, read by lock status and inbox ready.
+ FM_LOCK_INSPECT_STATE=held
+ # shellcheck disable=SC2034 # Output globals, read by lock status and inbox ready.
+ FM_LOCK_INSPECT_LIVE_HARNESS=true
+ else
+ # shellcheck disable=SC2034 # Output global, read by lock status and inbox ready.
+ FM_LOCK_INSPECT_LIVE_HARNESS=false
+ fi
;;
esac
} |
|
Rebased onto main
One environmental caveat: |
a447924 to
cafa115
Compare
Closes #5238
What Changed
bin/fm-procinfo.pyand a ps-free identity fallback inbin/fm-session-lock-lib.sh: when thepsbinary cannot execute at all (126/127), owner identity is read through/proc(Linux, honoringFM_PROC_ROOT_OVERRIDE) or macOS kernel syscalls, with fail-closed parsing, exact-field verification, and once-per-shell diagnostics.fm_session_lock_pid_blocks_reclaimverdict (liveness first, then identity) and routedbin/fm-lock.sh,bin/fm-claude-stop-autoarm.sh,bin/fm-turnend-guard.sh, andbin/fm-turnend-guard-cursor.shthrough it instead of re-deriving liveness;fm_session_lock_inspectnow uses the same single verdict for numeric and tagged Windows pids.tests/fm-session-lock-ps-denied.test.shand extendedtests/fm-session-lock-ancestry.test.sh, registered the new suite inbin/fm-test-run.sh, and updated the session-lock, watcher-continuity, turnend-guard, and scripts documentation.Risk Assessment
✅ Low: The fallback is bounded to confirmed ps execution denial, and source inspection found no new material defect in identity classification, ownership protection, or recovery.
Testing
Ran the four focused suites first (ps-denied suite all pass; windows-consumers and inbox pass; ancestry shows only the already-reported pre-existing pid-1 reparent assertion). Then drove the real
bin/fm-lock.shinside a disposable fm-lab home against a genuine process tree with ps denied (apsshim that exits 126 for every invocation, includingps -V, while everything else runs for real). All 17 live checks passed: a primary acquires the lock on the denied-ps host, a second primary is refused with a lock unchanged (no takeover), a dead owner's lock is still reclaimed,fm-lock.sh statusreports held/stale correctly through the ps-free route, and a live Cursor owner behind a non-ASCII (José) alias path keeps byte-identical comm/args across the ps and /proc routes and blocks reclaim. The Darwin sysctl provider (bin/fm-procinfo.py) is untested because this host is Linux and only a Darwin host can exercise KERN_PROCARGS2, so that scenario stays honestly untested; the shared verdict logic it feeds was exercised live. Labs were removed and no background work remains.lock acquired: harness pid 961880,cli-rc=0,lock-line1=961880error: another live firstmate session holds the lock (pid 962021),contender-rc=1, lock still 962021lock acquired: harness pid 962388,cli-rc=0,lock-line1=962388bin/fm-lock.sh statusagrees with the lock verdict on a ps-denied host (held while alive, stale after exit)lock: held by live harness pid 962021thenlock: stale (pid 962021 dead or not a harness)comm=[agent] args=[/tmp/…~/.local/bin/agent …],harness verdict with ps denied: [alive], contender refused, lock unchanged a…Evidence: Live drive transcript (17/17 PASS, driver rc=0)
Source: Live drive transcript (17/17 PASS, driver rc=0)
Evidence: Live drive script (denied-ps lab fixture, harness tree, Cursor alias scenario)
Source: Live drive script (denied-ps lab fixture, harness tree, Cursor alias scenario)
Evidence: Focused suite: tests/fm-session-lock-ps-denied.test.sh (ALL PASS)
Source: Focused suite: tests/fm-session-lock-ps-denied.test.sh (ALL PASS)
Evidence: Focused suite: tests/fm-session-lock-ancestry.test.sh (21 ok, 1 pre-existing pid-1 reparent failure)
Source: Focused suite: tests/fm-session-lock-ancestry.test.sh (21 ok, 1 pre-existing pid-1 reparent failure)
Evidence: Focused suite: tests/fm-inbox.test.sh
Source: Focused suite: tests/fm-inbox.test.sh
Evidence: Focused suite: tests/fm-session-lock-windows-consumers.test.sh
Source: Focused suite: tests/fm-session-lock-windows-consumers.test.sh
Evidence: Live validation summary
Source: Live validation summary
Evidence: Key live evidence lines
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
lock acquired: harness pid 961880,cli-rc=0,lock-line1=961880error: another live firstmate session holds the lock (pid 962021),contender-rc=1, lock still 962021lock acquired: harness pid 962388,cli-rc=0,lock-line1=962388bin/fm-lock.sh statusagrees with the lock verdict on a ps-denied host (held while alive, stale after exit)lock: held by live harness pid 962021thenlock: stale (pid 962021 dead or not a harness)comm=[agent] args=[/tmp/…~/.local/bin/agent …],harness verdict with ps denied: [alive], contender refused, lock unchanged a…bash tests/fm-session-lock-ps-denied.test.sh-> ALL PASSbash tests/fm-session-lock-windows-consumers.test.sh-> passbash tests/fm-inbox.test.sh-> passbash tests/fm-session-lock-ancestry.test.sh-> 21 ok, 1 pre-existing failure (the pty-host was not reparented to init after the daemon ended)live:bin/fm-lab-home.sh create $LABthenbash live-drive.sh <worktree> $LAB— realbin/fm-lock.shunder a ps shim that exits 126 for every call (includingps -V), real process tree with a bash-copy harness (claude), real /proc providerlive S1: primary acquires the lock with ps denied (lock acquired: harness pid N, exit 0, state/.lock = N)live S2: second primary refused withanother live firstmate session holds the lock (pid OWNER), exit 1, state/.lock unchangedlive S3: after the owner was stopped, the stale lock was reclaimed and state/.lock rewritten to the new pidlive S4:bin/fm-lock.sh status->lock: held by live harness pid Nwhile alive,lock: stale (...)after exitlive S5: Cursor harness launched via<lab>~/.local/bin/agent; ps route and /proc route report byte-identical comm/args withJosépreserved,fm_harness_pid_alive= alive on both routes, contender refused and lock unchangedteardown:rm -rf $LABfor every lab; worktree left clean (git status --porcelainempty)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.