Skip to content

fix(bin): run the session lock, herdr spawns, and claim locks on native Windows - #5419

Open
sjgold wants to merge 3 commits into
kunchenguid:mainfrom
sjgold:fix/windows-session-lock
Open

sjgold wants to merge 3 commits into
kunchenguid:mainfrom
sjgold:fix/windows-session-lock

Conversation

@sjgold

@sjgold sjgold commented Sep 23, 2026

Copy link
Copy Markdown

Intent

Make firstmate run on native Windows (Git Bash / MSYS) with Claude Code inside herdr, then send the fixes upstream as a PR. On this host every session opened read-only because the session-lock harness ancestry walk could not see the native claude.exe process (MSYS ps ignores -o and reports native parents as PID 0/1); this is upstream issues #3396, #3653, #1508. Decision: keep one process-identity primitive in bin/fm-session-lock-lib.sh that reads Win32_Process via one PowerShell Get-CimInstance call when /proc//winpid exists, and keep every recorded pid in the Windows pid namespace that Claude Code already uses for CLAUDE_PID, so liveness checks on the recorded lock pid work (a gap in the competing PR #4616, whose liveness check still used kill -0 and ps). The MSYS part of the chain is climbed through /proc first because a fork child's Win32 ParentProcessId can be transient. POSIX hosts must behave exactly as before. Second fix: native Windows herdr reports C:...\herdr.sock socket paths, which fm_backend_herdr_canonical_socket_path refused, so every herdr spawn failed its launcher-identity proof (issue #3283); drive-letter paths are converted with cygpath first and refused when cygpath is absent. Third fix, found while verifying: Git Bash ln -s deep-copies directories by default, so the symlink claim lock in bin/fm-wake-lib.sh could never be reclaimed from a dead holder and nested .steal directories until session start hit its 120 s bound; fm_lock_symlink requests native Windows symlinks (winsymlinks:nativestrict, which fails instead of copying when Windows refuses, i.e. without Developer Mode), and the owner comparison accepts both MSYS spellings of one Windows path because readlink reports Temp paths as /tmp. Verified live on Windows 11: bin/fm-lock.sh acquires the lock for claude.exe and bin/fm-session-start.sh completes without the read-only banner. Some existing tests (a symlinked-sidecar case, the e2e lock tests, fm-watcher-lock) fail on Windows both before and after this change because they depend on POSIX ps/symlink semantics; making those suites Windows-portable is out of scope.

What Changed

  • Session lock (bin/fm-session-lock-lib.sh): On native Windows (Git Bash / MSYS, detected when /proc/<pid>/winpid exists), the harness ancestry walk now climbs the MSYS part of the chain through /proc. From the topmost process's winpid it continues through Win32_Process rows, read with one Get-CimInstance call, so it can find the native claude.exe ancestor instead of opening the session read-only. Recorded pids stay in the Windows pid namespace, and liveness checks go through the same process-identity primitive instead of kill -0/ps. POSIX hosts use the same code paths as before.
  • herdr backend (bin/backends/herdr.sh): fm_backend_herdr_canonical_socket_path now converts drive-letter socket paths (C:\...\herdr.sock) to their POSIX spelling with cygpath -u and refuses them when cygpath is missing. Before this, every native-Windows herdr spawn failed its launcher-identity proof.
  • Claim locks (bin/fm-wake-lib.sh): A new fm_lock_symlink publishes lock links with winsymlinks:nativestrict on MINGW/MSYS/Cygwin. Git Bash's default ln -s deep-copies directories, so the old code never produced a real symlink. With nativestrict, ln -s fails outright instead of copying. fm_lock_points_to_owner now also accepts both MSYS spellings of one Windows path (for example, /tmp vs the Temp path) by comparing their cygpath -w forms, and the stray-owner-link cleanup uses the same check. The result: a lock held by a dead holder can be reclaimed again, where before each reclaim attempt nested another .steal directory. New tests/fm-lock-reclaim.test.sh (registered in fm-test-run.sh) plus new cases in the herdr backend and session-lock ancestry tests cover these paths.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: Both round-1 fixes check out against the current code. The stray-link cleanup now uses fm_lock_points_to_owner, so both MSYS spellings of a path match. On POSIX, the kill -0 check again runs only in fm_harness_pid_alive, and the trusted-id and inspect paths once more read identity through ps alone. Windows-only behavior sits behind the /proc winpid and uname checks, and tests run it through the real public functions.

Testing

I drove every intent scenario live on the Windows 11 / Git Bash host inside Claude Code and compared each against the base commit. fm-lock.sh acquires, reports held, and re-acquires for claude.exe, while the base fails with "cannot locate harness process in ancestry". A dead Windows pid or a live non-harness pid is reclaimed. Another live claude.exe holding the lock is refused. The claim lock is a native Windows symlink: it is reclaimed from a dead holder, it refuses a contender with no stray link left behind, and release leaves nothing. The base deep-copies the directory, cannot reclaim, and leaves .steal directories. In a guarded fm-lab Herdr session, the launcher-identity proof accepts herdr's C:\ socket, while the base refuses it, and with no cygpath on PATH the path is still refused. fm-session-start.sh completes with the lock held and no read-only banner, while the base prints the banner. The POSIX scenario was not driven live: WSL Linux test-suite runs pass except one pty-host reparent e2e test, which fails the same way on base, but that is test coverage, not a live product session. The Windows-side failures I saw are also pre-existing (the symlinked-sidecar case matches the intent's out-of-scope list; the Herdr stale-shadowing-client test also fails on base). The Herdr lab was torn down, the default session was never touched, no processes were left behind, and the worktree is clean. The temp scratch dir under OS Temp could not be removed because a security policy blocks recursive rm.

  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Inside Claude Code on Git Bash, bin/fm-lock.sh acquires the session lock for native claude.exe and records its Windows pid ✅ pass live session-lock-acquire.txt: target prints 'lock acquired: harness pid 25260' (CLAUDE_PID, claude.exe per Win32_Process), status 'held by live harness pid 25260', and re-acquire exits 0. Base prints 'err…
Liveness of a recorded lock pid uses the Windows pid namespace: a dead pid and a live non-harness pid are reclaimed, and another live claude.exe is refused ✅ pass live session-lock-liveness.txt: pid 4000001 and explorer.exe 10748 are both reported stale and reclaimed. A live claude.exe (pid 73324) reads 'held by live harness' and acquire refuses with exit 1. Base re…
bin/fm-session-start.sh completes without the READ-ONLY banner ✅ pass live session-start.txt: target exits 0 with 0 banner lines and 'lock acquired: harness pid 25260'. Base prints 'READ-ONLY SESSION - FLEET LOCK OWNERSHIP WAS NOT VERIFIED'.
Herdr launcher-identity proof accepts native Windows herdr's C:...\herdr.sock in a real lab session ✅ pass live herdr-launcher-identity.txt: inside pane w1:p1 of fm-lab-wintest-77988-15446, the target canonicalizes the socket to /c/... and fm_backend_herdr_launcher_identity returns rc=0 with pane/tab/workspace…
Adversarial: a drive-letter socket path is refused when cygpath is unavailable ✅ pass live herdr-launcher-identity.txt: with PATH lacking cygpath, fm_backend_herdr_canonical_socket_path on the real injected socket prints 'refused (expected)'
Claim lock on Git Bash is a native symlink that can be reclaimed from a dead holder, with no .steal nesting ✅ pass live claim-lock-reclaim.txt: cmd dir shows '<SYMLINKD> x.lock [C:...\x.lock.owner.*]'. B acquires with recovered_pid=73672, releases, and leaves no leftovers (0 .steal). Base makes a plain <DIR> deep copy…
Adversarial: a contended claim against a live holder under Windows Temp (readlink reports /tmp) is refused and leaks no stray link into the owner dir ✅ pass live claim-lock-reclaim.txt: 'C refused (correct)' and the owner dir holds only 'pid' after contention
POSIX hosts behave as before (no winpid, so the ps/kill path is used) ⏸️ untested no The prior payload did not establish a live result: no native Linux/macOS firstmate session was available to drive live, and only WSL test-suite runs (posix-wsl-tests.txt) were recorded, which are not…
Evidence: Session lock acquire: before vs after (claude.exe found, lock held)

Source: Session lock acquire: before vs after (claude.exe found, lock held)

## host: MINGW64_NT-10.0-26200  CLAUDE_PID=25260  shell winpid=35744
## CLAUDE_PID identity via Win32_Process:
25260 claude.exe

## BEFORE (base 9296f9b): bin/fm-lock.sh acquire
error: cannot locate harness process in ancestry
exit=1
## BEFORE: ancestry walk
walk exit=1

## AFTER (target e6ece9c): ancestry walk
25260
walk exit=0
anchor=25260
## AFTER: bin/fm-lock.sh acquire
lock acquired: harness pid 25260
exit=0
## .lock contents:
25260
## .lock-session present: yes
## AFTER: fm-lock.sh status
lock: held by live harness pid 25260
## AFTER: re-acquire (already mine)
lock acquired: harness pid 25260
exit=0
Evidence: Session lock liveness on Windows pids (dead / non-harness / other live claude.exe)

Source: Session lock liveness on Windows pids (dead / non-harness / other live claude.exe)

## Scenario: recorded pid is dead (Windows pid 4000001)
lock: stale (pid 4000001 dead or not a harness)
lock acquired: harness pid 25260
exit=0
lock line1 now: 25260

## Scenario: recorded pid is a live non-harness Windows process (explorer.exe pid 10748)
lock: stale (pid 10748 dead or not a harness)
lock acquired: harness pid 25260
exit=0
lock line1 now: 25260

## Scenario: recorded pid is ANOTHER live claude.exe session (pid 73324)
lock: held by live harness pid 73324
error: another live firstmate session holds the lock (pid 73324); operate read-only until resolved
exit=1
lock line1 now: 73324

## BEFORE (base) status on held-by-live-claude lock
lock: stale (pid 25260 dead or not a harness)
Evidence: Claim lock native symlink reclaim: before vs after

Source: Claim lock native symlink reclaim: before vs after

STATE under /tmp/tmp.bHhNamduzw (Windows: ~\AppData\Local\Temp\tmp.bHhNamduzw)

===== AFTER (target) =====
\### [after] holder A acquires, then exits without release
A acquired (pid 73672)
lock path type: symlink -> /tmp/tmp.bHhNamduzw/claim-after/x.lock.owner.CpDS6J
Windows view:
   09/23/2026  08:13 AM    <SYMLINKD>     x.lock [~\AppData\Local\Temp\tmp.bHhNamduzw\claim-after\x.lock.owner.CpDS6J]
   09/23/2026  08:13 AM    <DIR>          x.lock.owner.CpDS6J
\### [after] process B tries to reclaim from the dead holder (15s bound)
B acquired; recovered_pid=73672
\### live holder B; contended C attempt:
C refused (correct)
owner dir entries after contention: pid 
B released
rc=0
leftovers in state: 
nested .steal dirs: 0

===== BEFORE (base 9296f9b) =====
\### [before] holder A acquires, then exits without release
lock path type: plain DIRECTORY (deep copy)
Windows view:
   09/23/2026  08:13 AM    <DIR>          x.lock
\### [before] process B tries to reclaim from the dead holder (15s bound)
B FAILED to acquire (rc=1)
rc=0
leftovers in state: x.lock x.lock/pid x.lock.steal x.lock.steal/pid 
nested .steal dirs: 1
Evidence: Herdr launcher-identity proof inside fm-lab pane with C:\ socket

Source: Herdr launcher-identity proof inside fm-lab pane with C:\ socket

## inside herdr lab pane: HERDR_SESSION=fm-lab-wintest-77988-15446 HERDR_PANE_ID=w1:p1
## injected HERDR_SOCKET_PATH=~\AppData\Roaming\herdr\sessions\fm-lab-wintest-77988-15446\herdr.sock

===== AFTER (target e6ece9c)
canonical(injected socket): /c/Users/SJG/AppData/Roaming/herdr/sessions/fm-lab-wintest-77988-15446/herdr.sock
launcher_identity rc=0 pane=w1:p1 tab=w1:t1 workspace=w1

===== BEFORE (base 9296f9b)
canonical(injected socket): REFUSED
error: herdr launcher pane 'w1:p1' reports an unusable socket path; refusing to place a worker from an unverifiable parent identity
launcher_identity rc=1 pane= tab= workspace=

===== adversarial: cygpath absent (PATH without /usr/bin), target
refused (expected)
DONE
Evidence: fm-session-start.sh summary: before (read-only banner) vs after (lock held)

Source: fm-session-start.sh summary: before (read-only banner) vs after (lock held)

CLAUDE_PID=25260
===== AFTER (target e6ece9c)
exit=0 elapsed=27s
read-only banner lines: 0
LOCK
lock acquired: harness pid 25260
SUPERVISION OPERATING INSTRUCTIONS - primary harness: claude
- Lock: held by this session; this session owns normal supervision unless away mode says otherwise.
   [`watcher-continuity.md`](../watcher-continuity.md) owns the exact session-lock recovery boundary.
data/captain-shared.md (shared, main-authoritative, read-only in secondmate homes)
Follow the supervision operating instructions block above for harness 'claude'.
state/.lock: 25260

===== BEFORE (base 9296f9b)
exit=0 elapsed=5s
read-only banner lines: 1
LOCK
error: cannot locate harness process in ancestry
●  READ-ONLY SESSION - FLEET LOCK OWNERSHIP WAS NOT VERIFIED
●  error: cannot locate harness process in ancestry
●  diagnostics and the rest of this read-only-safe digest still ran below.
●  Operate read-only until this resolves - do not spawn, steer, merge, or
skipped (read-only session) - 0 record(s) remain queued because this session lacks verified fleet-lock ownership.
SUPERVISION OPERATING INSTRUCTIONS - primary harness: claude
state/.lock: none
Evidence: fm-session-start.sh full digest (after)

Source: fm-session-start.sh full digest (after)


================================================================================
SESSION START - /tmp/tmp.bHhNamduzw/ss2-after/home
================================================================================

LOCK
--------------------------------------------------------------------------------
lock acquired: harness pid 25260

BOOTSTRAP
--------------------------------------------------------------------------------
(silent - all good)

WAKE QUEUE
--------------------------------------------------------------------------------
(no queued wakes)
================================================================================
SUPERVISION OPERATING INSTRUCTIONS - primary harness: claude
================================================================================
Current state:
- Lock: held by this session; this session owns normal supervision unless away mode says otherwise.
- Away/quiet mode: inactive.
- X mode: inactive; use the default watcher cadence.
- Ordinary wake: the Stop-owned auto-arm (bin/fm-claude-stop-autoarm.sh) already owns watcher continuity; drain and handle the wake, and do not arm another cycle yourself.

Mode: Claude Stop-hook-owned supervision.

When this session owns supervision and away mode is not active:
1. Drain first with `bin/fm-wake-drain.sh`.
   After handling all emitted wakes and reconciling open decisions and unread status lines, run the exact `--ack-through` command printed as `WAKE_ACK_REQUIRED`; until then the work remains durable for idempotent re-handling after interruption.
2. Routine watcher arm and re-arm are owned by the Stop `asyncRewake` hook (`bin/fm-claude-stop-autoarm.sh`), never by you.
   Every turn end while supervision is needed launches or attaches one home-scoped watcher cycle with no model command and no model tokens.
   An actionable close wakes you through the hook's exit-2 rewake, delivered as a `Stop hook feedback` message.
3. On a `Stop hook feedback` wake (`signal:`, `stale:`, `check:`, or `heartbeat`), run `bin/fm-wake-drain.sh` first and handle the wake.
   Do not run `bin/fm-watch-arm.sh` after an ordinary wake; the next turn end re-arms automatically when supervision is still needed.
   Do not invent a wake from an attach-status line alone; drain and act only on real wake records, the drain's `OPEN DECISIONS` and `UNREAD STATUS` entries, or a real watcher reason line.
4. On the one `Stop hook feedback` automatic-mechanism failure notice (`firstmate watcher auto-arm FAILED ...`), drain, inspect the automatic mechanism failure, and do not turn the notice into a repeating manual-arm loop.
5. If the Stop hook does not claim the home or reports an exhausted failure, inspect its registration and watcher startup path before ending blind.
   Keep the Stop-owned automatic mechanism as the only Claude arm owner.
6. Treat `watcher: started ...` and `watcher: attached ...` inside automatic arm output as proof that one live cycle exists.
   On attach, the arm follows verified identity-matched successors instead of exiting when the first cycle ends.
7. The durable wake queue preserves actionable events between a rewake and the next Stop-launched arm, while the bounded turn-end guard prevents a blind Stop when recovery did not start.
   No PreToolUse hook denies fleet commands based on watcher status.
   [`watcher-continuity.md`](../watcher-continuity.md) owns the exact session-lock recovery boundary.
8. The turn-end guard (`bin/fm-turnend-guard.sh --claude`) remains the final backstop.
   It requires the PID-strict live-watcher and fresh-beacon predicate at the Stop boundary, except for the Claude-specific foreign-live-owner safe exit owned by [`turnend-guard.md`](../turnend-guard.md#guard-predicates); that document also owns the distinct model-aware mid-turn pull-guard rules.
   Otherwise, it allows the stop when a watcher is healthy or an open auto-arm generation claim owns recovery, while fresh failure epochs advance the bounded one-time attended fail-open progression described there.
9. Waiting on the hook-owned cycle is silent: do not send idle progress while the watcher is parked.

The watcher itself remains `bin/fm-watch.sh`, and `bin/fm-watch-arm.sh` remains the verified arm wrapper that the Stop hook foregrounds.
Re-arm attaches to an existing healthy cycle when one is already present and follows its verified successor chain.
See [`watcher-continuity.md`](../watcher-continuity.md) for the arm-layer successor and clean-close failure contract and the Claude ownership model.


================================================================================
READ-ONCE CONTRACT
================================================================================
Everything below is printed in full for this session start: every state/*.meta,
a compact data/backlog.md listing, a bounded tail of every state/*.status,
data/projects.md, data/secondmates.md, data/captain.md, data/captain-shared.md,
and data/learnings.md.
Do NOT re-read any of them after reading this digest, and do NOT bulk-read
data/backlog.md or state/*.status: re-reading everything defeats the entire
point of this command.

Go to a source directly only when:
  - this digest flagged it ABSENT (then rebuild or create it per AGENTS.md),
  - its contents looked unparseable or corrupt,
  - an individual full status log is needed for older wake-event history, or a
    status line was capped and its tail matters (each task's full log path is
    printed with its tail),
  - a full task body is needed (bin/fm-tasks-axi.sh show <id> --full, or data/backlog.md),
  - the backlog listing disclosed omitted queued items and this turn needs them,
  - the NETWORK CHECKS section reported its checks still IN PROGRESS and this
    turn needs their verdict (bin/fm-startup-network.sh report),
  - or a STARTUP TRUNCATED banner named the stage that would have printed it, in
    which case that stage's sources were never emitted and must be reconciled.

================================================================================
FLEET STATE
================================================================================

data/backlog.md
--------------------------------------------------------------------------------
ABSENT

Work under way (state/*.meta)
--------------------------------------------------------------------------------
(none)

Orphan status logs (state/*.status without matching .meta)
--------------------------------------------------------------------------------
(none)

AFK
--------------------------------------------------------------------------------
absent

================================================================================
NETWORK CHECKS
================================================================================
completed off the startup path in 7s: GitHub authentication, dead-secondmate relaunch, secondmate convergence, pending handoff delivery, project clone refresh with its drift reporting, and inactive terminal-outcome reconciliation.
(silent - no problems found)

================================================================================
CONTEXT
================================================================================

data/projects.md
--------------------------------------------------------------------------------
ABSENT

data/secondmates.md
--------------------------------------------------------------------------------
ABSENT

data/captain.md
--------------------------------------------------------------------------------
ABSENT

data/captain-shared.md (shared, main-authoritative, read-only in secondmate homes)
--------------------------------------------------------------------------------
ABSENT

data/learnings.md
--------------------------------------------------------------------------------
ABSENT

================================================================================
NEXT STEP
================================================================================
Follow the supervision operating instructions block above for harness 'claude'.
This script never starts supervision itself.

The digest above is complete for this session start. The READ-ONCE CONTRACT
section near the top of it governs what may still be read from disk.
Evidence: fm-session-start.sh full digest (before)

Source: fm-session-start.sh full digest (before)


================================================================================
SESSION START - /tmp/tmp.bHhNamduzw/ss2-before/home
================================================================================

LOCK
--------------------------------------------------------------------------------
error: cannot locate harness process in ancestry
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  READ-ONLY SESSION - FLEET LOCK OWNERSHIP WAS NOT VERIFIED
●  error: cannot locate harness process in ancestry
●  Skipping every mutating step: stale Herdr child cleanup,
●  secondmate convergence, secondmate liveness, pending remote handoff retry,
●  X-mode artifacts, fleet sync, and wake-queue drain. Detect-only bootstrap
●  diagnostics and the rest of this read-only-safe digest still ran below.
●  Operate read-only until this resolves - do not spawn, steer, merge, or
●  otherwise mutate fleet state from this session.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

BOOTSTRAP
--------------------------------------------------------------------------------
(silent - all good)

WAKE QUEUE
--------------------------------------------------------------------------------
skipped (read-only session) - 0 record(s) remain queued because this session lacks verified fleet-lock ownership.
================================================================================
SUPERVISION OPERATING INSTRUCTIONS - primary harness: claude
================================================================================
Current state:
- Lock: read-only; do not drain, arm, spawn, steer, merge, or repair fleet state here.
- Away/quiet mode: inactive.
- X mode: inactive; use the default watcher cadence.
- Ordinary wake: the Stop-owned auto-arm (bin/fm-claude-stop-autoarm.sh) already owns watcher continuity; drain and handle the wake, and do not arm another cycle yourself.

/tmp/tmp.bHhNamduzw/base/bin/fm-supervision-instructions.sh: line 120: /tmp/tmp.bHhNamduzw/base/docs/supervision-protocols/unknown.md: No such file or directory

================================================================================
READ-ONCE CONTRACT
================================================================================
Everything below is printed in full for this session start: every state/*.meta,
a compact data/backlog.md listing, a bounded tail of every state/*.status,
data/projects.md, data/secondmates.md, data/captain.md, data/captain-shared.md,
and data/learnings.md.
Do NOT re-read any of them after reading this digest, and do NOT bulk-read
data/backlog.md or state/*.status: re-reading everything defeats the entire
point of this command.

Go to a source directly only when:
  - this digest flagged it ABSENT (then rebuild or create it per AGENTS.md),
  - its contents looked unparseable or corrupt,
  - an individual full status log is needed for older wake-event history, or a
    status line was capped and its tail matters (each task's full log path is
    printed with its tail),
  - a full task body is needed (bin/fm-tasks-axi.sh show <id> --full, or data/backlog.md),
  - the backlog listing disclosed omitted queued items and this turn needs them,
  - the NETWORK CHECKS section reported its checks still IN PROGRESS and this
    turn needs their verdict (bin/fm-startup-network.sh report),
  - or a STARTUP TRUNCATED banner named the stage that would have printed it, in
    which case that stage's sources were never emitted and must be reconciled.

================================================================================
FLEET STATE
================================================================================

data/backlog.md
--------------------------------------------------------------------------------
ABSENT

Work under way (state/*.meta)
--------------------------------------------------------------------------------
(none)

Orphan status logs (state/*.status without matching .meta)
--------------------------------------------------------------------------------
(none)

AFK
--------------------------------------------------------------------------------
absent

================================================================================
NETWORK CHECKS
================================================================================
skipped (read-only session) - GitHub authentication, project clone refresh,
secondmate liveness and convergence, and pending handoff delivery were not run.
They need the fleet lock, and this session must not spawn, steer, or merge, so it
has no action they would gate. The session holding the lock runs them.

================================================================================
CONTEXT
================================================================================

data/projects.md
--------------------------------------------------------------------------------
ABSENT

data/secondmates.md
--------------------------------------------------------------------------------
ABSENT

data/captain.md
--------------------------------------------------------------------------------
ABSENT

data/captain-shared.md (shared, main-authoritative, read-only in secondmate homes)
--------------------------------------------------------------------------------
ABSENT

data/learnings.md
--------------------------------------------------------------------------------
ABSENT

================================================================================
NEXT STEP
================================================================================
This session did not acquire the fleet lock. Stay read-only: do not arm,
drain, spawn, steer, merge, or repair fleet state from here. Only a session
with verified fleet-lock ownership may perform mutable follow-up.

The digest above is complete for this session start. The READ-ONCE CONTRACT
section near the top of it governs what may still be read from disk.
Evidence: POSIX (WSL Linux) session-lock and claim-lock test runs, target and base

Source: POSIX (WSL Linux) session-lock and claim-lock test runs, target and base

host: Linux 6.6.87.2-microsoft-standard-WSL2
no /proc/<pid>/winpid -> POSIX path
== tests/fm-session-lock-ancestry.test.sh
ok - session-lock: a version-named Claude Code session is identified from its install path and argv[0]
ok - session-lock: a harness that is pid 1 of its own namespace is examined, not skipped
ok - session-lock: ordinary script paths under a harness directory are not harness processes
ok - session-lock: ownership stops at the first non-harness gap above the contiguous run
ok - session-lock: a live version-named session holding the lock is not mistaken for a stale owner
ok - session-lock: a trusted same-session id keeps owning a recycled background chain, and nothing weaker does
ok - session-lock: a trusted id anchors the lock on the model-loop process, anything else on the outermost pid
ok - session-lock: on Git Bash the native Windows harness is found, anchored, and checked for liveness
ok - session-lock e2e: a version-named session claims the home and arms supervision
ok - session-lock e2e: a session parented by a harness-named daemon claims the home and arms supervision
ok - session-lock e2e: a version-named session under a harness-named daemon keeps its own lock
not ok - the pty-host was not reparented to init after the daemon ended
rc=1
== tests/fm-lock-reclaim.test.sh
ok - claim lock: a dead holder is reclaimed, a live holder is respected, and release leaves nothing
rc=0
== BASE 9296f9b tests/fm-session-lock-ancestry.test.sh on WSL
ok - session-lock: a trusted same-session id keeps owning a recycled background chain, and nothing weaker does
ok - session-lock: a trusted id anchors the lock on the model-loop process, anything else on the outermost pid
ok - session-lock e2e: a version-named session claims the home and arms supervision
ok - session-lock e2e: a session parented by a harness-named daemon claims the home and arms supervision
ok - session-lock e2e: a version-named session under a harness-named daemon keeps its own lock
not ok - the pty-host was not reparented to init after the daemon ended
rc=1
Evidence: Launcher identity before/after (excerpt)
AFTER: canonical(injected socket): /c/Users/SJG/AppData/Roaming/herdr/sessions/fm-lab-wintest-77988-15446/herdr.sock
launcher_identity rc=0 pane=w1:p1 tab=w1:t1 workspace=w1
BEFORE: error: herdr launcher pane 'w1:p1' reports an unusable socket path; refusing to place a worker from an unverifiable parent identity
cygpath absent: refused (expected)
- Outcome: ⚠️ 1 info across 1 run (9m42s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed ✅
  • ⚠️ bin/fm-wake-lib.sh:519 - fm_lock_remove_stray_owner_link still compares readlink output to $ownerdir with a raw string =. That misses the rule this change added to fm_lock_points_to_owner, which says both MSYS spellings of one Windows path must compare equal. How it fails: on Git Bash with native symlinks, a contended fm_lock_try_create runs ln -s ownerdir lockdir while lockdir is a live symlink to the holder's owner dir. ln then creates lockdir/<basename> inside the holder's owner dir, and fm_lock_symlink's non-zero exit sends control to fm_lock_remove_stray_owner_link. When STATE is under Windows Temp, readlink gives /tmp/... while ownerdir is /c/Users/.../Temp/..., so the stray link is never removed. The holder's later rmdir of its owner dir then fails because the dir is not empty, and each contended attempt leaks one more entry. Fix: call fm_lock_points_to_owner &#34;$stray&#34; &#34;$ownerdir&#34; instead of the raw comparison. That is the only remaining raw readlink comparison against an owner path in the file. The other readlink consumers (lines 489, 610, 1026, 1077, 1159) either compare a spelling with itself or already go through fm_lock_points_to_owner.
  • ℹ️ bin/fm-session-lock-lib.sh:331 - The intent says "POSIX hosts must behave exactly as before", but on POSIX fm_session_lock_trusted_session_id now runs through _fm_proc_identity. That adds a kill -0 check the old code did not have: it read identity with ps alone. If kill -0 fails with EPERM (CLAUDE_PID is owned by another uid, e.g. the harness runs as root and the shell drops privileges), the trusted session id is no longer returned where it used to be. The sequence is rare, but it is a POSIX behavior change. Smallest fix: keep the kill -0 gate in fm_harness_pid_alive's POSIX branch only, and let _fm_proc_identity's POSIX branch use ps alone, as the old trusted-id path did. fm_session_lock_inspect's result is unchanged either way, because _fm_proc_exists keeps the ps fallback.

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

⚠️ **Test** - 1 info
  • ℹ️ Pre-existing failures I saw that are not caused by this change (each fails the same way on base 9296f9b): the fm-session-lock-ancestry 'symlinked sidecar' case on Windows (in the intent's out-of-scope list), the fm-backend-herdr 'live remote pane behind a stale shadowing client' case on Windows, and the fm-session-lock-ancestry 'pty-host reparented to init' e2e case on WSL. Because these tests abort on the first failure, the new Windows tests were run in isolation on the Windows host, and both pass.
  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Inside Claude Code on Git Bash, bin/fm-lock.sh acquires the session lock for native claude.exe and records its Windows pid ✅ pass live session-lock-acquire.txt: target prints 'lock acquired: harness pid 25260' (CLAUDE_PID, claude.exe per Win32_Process), status 'held by live harness pid 25260', and re-acquire exits 0. Base prints 'err…
Liveness of a recorded lock pid uses the Windows pid namespace: a dead pid and a live non-harness pid are reclaimed, and another live claude.exe is refused ✅ pass live session-lock-liveness.txt: pid 4000001 and explorer.exe 10748 are both reported stale and reclaimed. A live claude.exe (pid 73324) reads 'held by live harness' and acquire refuses with exit 1. Base re…
bin/fm-session-start.sh completes without the READ-ONLY banner ✅ pass live session-start.txt: target exits 0 with 0 banner lines and 'lock acquired: harness pid 25260'. Base prints 'READ-ONLY SESSION - FLEET LOCK OWNERSHIP WAS NOT VERIFIED'.
Herdr launcher-identity proof accepts native Windows herdr's C:...\herdr.sock in a real lab session ✅ pass live herdr-launcher-identity.txt: inside pane w1:p1 of fm-lab-wintest-77988-15446, the target canonicalizes the socket to /c/... and fm_backend_herdr_launcher_identity returns rc=0 with pane/tab/workspace…
Adversarial: a drive-letter socket path is refused when cygpath is unavailable ✅ pass live herdr-launcher-identity.txt: with PATH lacking cygpath, fm_backend_herdr_canonical_socket_path on the real injected socket prints 'refused (expected)'
Claim lock on Git Bash is a native symlink that can be reclaimed from a dead holder, with no .steal nesting ✅ pass live claim-lock-reclaim.txt: cmd dir shows '<SYMLINKD> x.lock [C:...\x.lock.owner.*]'. B acquires with recovered_pid=73672, releases, and leaves no leftovers (0 .steal). Base makes a plain <DIR> deep copy…
Adversarial: a contended claim against a live holder under Windows Temp (readlink reports /tmp) is refused and leaks no stray link into the owner dir ✅ pass live claim-lock-reclaim.txt: 'C refused (correct)' and the owner dir holds only 'pid' after contention
POSIX hosts behave as before (no winpid, so the ps/kill path is used) ⏸️ untested no The prior payload did not establish a live result: no native Linux/macOS firstmate session was available to drive live, and only WSL test-suite runs (posix-wsl-tests.txt) were recorded, which are not…
  • FM_STATE_OVERRIDE=&lt;tmp&gt; bin/fm-lock.sh / status / re-acquire: target vs base (git archive 9296f9b) on the live Windows host
  • fm_harness_ancestry_pids and fm_session_lock_anchor_pid: target vs base, from inside this Claude Code session
  • bin/fm-lock.sh against a recorded dead Windows pid, a live explorer.exe pid, and another live claude.exe pid
  • fm_lock_try_acquire: dead-holder reclaim, contended attempt against a live holder, and release under a Windows-Temp STATE; cmd /c dir Windows view; target vs base
  • bin/fm-herdr-lab.sh name/provision/run/teardown on fm-lab-wintest-77988-15446; fm_backend_herdr_launcher_identity run inside lab pane w1:p1 with herdr-injected HERDR_SOCKET_PATH=C:...\herdr.sock, target vs base, plus a cygpath-absent adversarial check
  • bin/fm-session-start.sh with a throwaway FM_HOME/FM_ROOT_OVERRIDE and HERDR_* env removed: target vs base
  • tests/fm-lock-reclaim.test.sh (Windows and WSL)
  • tests/fm-session-lock-ancestry.test.sh (WSL, target and base); isolated test_windows_native_harness_owns_the_lock on Windows
  • tests/fm-backend-herdr.test.sh (Windows); isolated test_canonical_socket_path_accepts_windows_drive_path; base run to confirm the stale-shadowing-client failure is pre-existing
  • Checked Win32_Process and ps for leftover processes after the runs
✅ **Document** - passed

✅ No issues found.

⏭️ **Lint** - skipped
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

…dows

Under Git Bash the harness is a native Windows process that MSYS ps cannot
see, so the ancestry walk never found it and every session opened read-only.
The session-lock lib now routes identity, parentage, and liveness through one
process primitive that reads Win32_Process on an MSYS host (detected by
/proc/<pid>/winpid), keeping every recorded pid in the Windows namespace that
CLAUDE_PID already uses. POSIX hosts are unchanged.

Native Windows herdr reports drive-letter socket paths, which the herdr
socket canonicalization refused, so every herdr spawn failed its launcher
identity proof. Drive-letter paths are now converted with cygpath first.

Refs kunchenguid#3396, kunchenguid#3653, kunchenguid#1508, kunchenguid#3283.

Co-Authored-By: Seth Goldberg <[email protected]>
Git Bash's default ln -s deep-copies the owner directory instead of linking
it, so a claim lock never pointed at its owner, a dead holder could never be
reclaimed, and each reclaim attempt nested another .steal directory until the
caller hung (the session-start lock stage hit its 120 s bound this way).
fm_lock_symlink now asks MSYS/Cygwin for native Windows symlinks, which fail
rather than copy when Windows refuses them, and the owner comparison accepts
both MSYS spellings of one Windows path (Temp reads back as /tmp).

Co-Authored-By: Seth Goldberg <[email protected]>
@ikehoff

ikehoff commented Oct 4, 2026

Copy link
Copy Markdown

Tested this PR merged onto current main on Windows 11 (Git for Windows bash, native claude.exe launched from pwsh inside herdr 0.9.3), and found one gap: the lock works when bin/fm-session-start.sh runs from the Claude Bash tool, but the real SessionStart hook still opens read-only with error: cannot locate harness process in ancestry.

Cause

Every hook command in the tracked .claude/settings.json ends in exec "$CLAUDE_PROJECT_DIR"/bin/....
When the hook's bash execs, MSYS starts a new Windows process for the same MSYS pid.
That process is the topmost MSYS process (/proc/<pid>/ppid is 1, because the parent is the native claude.exe), so _fm_win_start_pid starts the native walk from its winpid.
But its Win32 ParentProcessId points at a transient helper process that has already exited, so the walk breaks at the first hop and never reaches claude.exe.
The original pre-exec bash.exe is still alive and is the real child of claude.exe, but nothing in /proc (winpid, ppid, stat, ...) or in the Win32 parent chain links the exec'd process back to it.

The same hook command without exec resolves the anchor correctly every time, from SessionStart (both startup and resume) and from PreToolUse.

Repro (no Claude needed)

From PowerShell, so the launcher is a native process like claude.exe:

'{}' | & "C:\Program Files\Git\bin\bash.exe" -c 'exec /path/to/probe.sh'

with probe.sh sourcing bin/fm-session-lock-lib.sh and printing the Win32 chain from _fm_win_start_pid:

start=52124
52124  43808  bash.exe  "C:\Program Files\Git\usr\bin\bash.exe" /.../probe-run.sh
missing 43808

Meanwhile the original shell is still listed, with the correct ancestry:

51816  34200  bash.exe  "C:\Program Files\Git\bin\..\usr\bin\bash.exe" -c "... exec /.../probe-run.sh"
34200  49940  bash.exe  "C:\Program Files\Git\bin\bash.exe" -c "... exec /.../probe-run.sh"

Dropping exec from the -c string makes the same probe walk up to the launching process.

Impact

All seven firstmate hook commands use exec, so on Windows this affects not just SessionStart (read-only session on every restart) but presumably also the Stop hooks (fm-turnend-guard.sh, fm-claude-stop-autoarm.sh), which rely on the same ancestry identity.

Possible fixes

  1. Drop exec from the hook commands in .claude/settings.json (and any other harness hook registrations that exec into firstmate scripts). The cost on POSIX is one extra short-lived shell per hook.
  2. Or handle it in the walk: when the start process's Win32 parent is missing from the snapshot, fall back to something that finds the surviving pre-exec process. I couldn't find a clean link to key on, so option 1 looks more robust.

The workaround for now is to run bin/fm-session-start.sh manually from the session after startup, which acquires the lock for CLAUDE_PID as expected.

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