Repository navigation
Conversation
…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]>
|
Tested this PR merged onto current CauseEvery hook command in the tracked The same hook command without Repro (no Claude needed)From PowerShell, so the launcher is a native process like '{}' | & "C:\Program Files\Git\bin\bash.exe" -c 'exec /path/to/probe.sh'with Meanwhile the original shell is still listed, with the correct ancestry: Dropping ImpactAll seven firstmate hook commands use Possible fixes
The workaround for now is to run |
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
bin/fm-session-lock-lib.sh): On native Windows (Git Bash / MSYS, detected when/proc/<pid>/winpidexists), the harness ancestry walk now climbs the MSYS part of the chain through/proc. From the topmost process's winpid it continues throughWin32_Processrows, read with oneGet-CimInstancecall, so it can find the nativeclaude.exeancestor 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 ofkill -0/ps. POSIX hosts use the same code paths as before.bin/backends/herdr.sh):fm_backend_herdr_canonical_socket_pathnow converts drive-letter socket paths (C:\...\herdr.sock) to their POSIX spelling withcygpath -uand refuses them whencygpathis missing. Before this, every native-Windows herdr spawn failed its launcher-identity proof.bin/fm-wake-lib.sh): A newfm_lock_symlinkpublishes lock links withwinsymlinks:nativestricton MINGW/MSYS/Cygwin. Git Bash's defaultln -sdeep-copies directories, so the old code never produced a real symlink. Withnativestrict,ln -sfails outright instead of copying.fm_lock_points_to_ownernow also accepts both MSYS spellings of one Windows path (for example,/tmpvs the Temp path) by comparing theircygpath -wforms, 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.stealdirectory. Newtests/fm-lock-reclaim.test.sh(registered infm-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.
Evidence: Session lock acquire: before vs after (claude.exe found, lock held)
Source: Session lock acquire: before vs after (claude.exe found, lock held)
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)
Evidence: Claim lock native symlink reclaim: before vs after
Source: Claim lock native symlink reclaim: before vs after
Evidence: Herdr launcher-identity proof inside fm-lab pane with C:\ socket
Source: Herdr launcher-identity proof inside fm-lab pane with C:\ socket
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)
Evidence: fm-session-start.sh full digest (after)
Source: fm-session-start.sh full digest (after)
Evidence: fm-session-start.sh full digest (before)
Source: fm-session-start.sh full digest (before)
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
Evidence: Launcher identity before/after (excerpt)
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 runsln -s ownerdir lockdirwhile 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: callfm_lock_points_to_owner "$stray" "$ownerdir"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 akill -0check the old code did not have: it read identity withpsalone. 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 thekill -0gate 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.
FM_STATE_OVERRIDE=<tmp> bin/fm-lock.sh/status/ re-acquire: target vs base (git archive 9296f9b) on the live Windows hostfm_harness_ancestry_pidsandfm_session_lock_anchor_pid: target vs base, from inside this Claude Code sessionbin/fm-lock.shagainst a recorded dead Windows pid, a live explorer.exe pid, and another live claude.exe pidfm_lock_try_acquire: dead-holder reclaim, contended attempt against a live holder, and release under a Windows-Temp STATE;cmd /c dirWindows view; target vs basebin/fm-herdr-lab.sh name/provision/run/teardownon fm-lab-wintest-77988-15446;fm_backend_herdr_launcher_identityrun inside lab pane w1:p1 with herdr-injected HERDR_SOCKET_PATH=C:...\herdr.sock, target vs base, plus a cygpath-absent adversarial checkbin/fm-session-start.shwith a throwaway FM_HOME/FM_ROOT_OVERRIDE and HERDR_* env removed: target vs basetests/fm-lock-reclaim.test.sh(Windows and WSL)tests/fm-session-lock-ancestry.test.sh(WSL, target and base); isolatedtest_windows_native_harness_owns_the_lockon Windowstests/fm-backend-herdr.test.sh(Windows); isolatedtest_canonical_socket_path_accepts_windows_drive_path; base run to confirm the stale-shadowing-client failure is pre-existingChecked Win32_Process and ps for leftover processes after the runs✅ **Document** - passed
✅ No issues found.
⏭️ **Lint** - skipped
✅ **Push** - passed
✅ No issues found.