Skip to content

feat(bin): support Firstmate fleet tooling on Windows Git Bash/MSYS hosts - #5501

Closed
kendylx wants to merge 16 commits into
kunchenguid:mainfrom
kendylx:fm/win32-msys-fleet-support
Closed

kendylx wants to merge 16 commits into
kunchenguid:mainfrom
kendylx:fm/win32-msys-fleet-support

Conversation

@kendylx

@kendylx kendylx commented Sep 24, 2026

Copy link
Copy Markdown

Intent

Make Firstmate's fleet tooling work correctly on Windows Git Bash/MSYS hosts so a native-Windows harness session (Devin CLI specifically) can hold the fleet lock, be ancestry-detected as its harness, spawn and supervise crewmates through herdr, and tear work down cleanly. The platform gaps closed: ln -s silently copies instead of linking on this host (no Developer Mode) so fm_lock_try_create always failed; Cygwin ps -o is dead so harness ancestry/liveness verdicts were blind; herdr's Windows build reports drive-letter socket paths, no ACL presentation namespace, and null foreground_cwd; teardown had no lsof; and the repo's own test fixtures assumed POSIX pids and real symlinks. Key scope decision: this started as a full Devin harness adapter, but upstream merged its own Devin adapter (PR #5380) mid-flight, so the captain elected to rebase ONLY the Windows/MSYS compatibility layer onto upstream main as this branch - our own adapter pieces (classification rows, launch recipe, control rows, devin.md supervision doc, pane-signature readiness gate) were deliberately DROPPED as superseded by upstream's fm-devin-config.sh/fm-busy-event.sh design and must not be re-added. What intentionally remains: mklink /J junction fallback in fm_lock_try_create gated to hosts where ln -s cannot link; shared fm-win32-proc-lib.sh Win32 process table with capability-gated ancestry/liveness fallbacks wired into fm-harness.sh, fm-session-lock-lib.sh (incl. adding ^devin$ to FM_HARNESS_RE which upstream still lacked), fm-sessionstart-nudge.sh, fm-branch-outcome.sh - all designed so healthy POSIX hosts take byte-identical verdict paths and fallbacks only fire when the ps read itself fails; herdr Windows socket/namespace/pane capability handling; cwd-blind herdr spawn worktree acquisition via durable lease with FM_WT_ marker proof; /proc//cwd teardown reaping plus canonical state-dir dedup (kills the D:/ vs /d/ self-match refusal); positive scratch-probe fallback for PR mode-bit invariants where chmod cannot express bits; Windows-capable test fixtures (operative-pid-space probe, renamed real binaries instead of symlinked fakes, fake-ps -l whole-table arms, capability-gated skips for POSIX-only cases like process groups); the noncanonical-state teardown regression opts out via config/backlog-backend=manual because it proves dedup not backlog mechanics. Delivery: push the branch to the fork remote and open a PR to upstream for the captain to review and merge - the captain retains merge authority.

What Changed

  • Win32 process fallbacks: Adds bin/fm-win32-proc-lib.sh, a shared Win32 process-table reader. fm-harness.sh, fm-session-lock-lib.sh, fm-sessionstart-nudge.sh and fm-branch-outcome.sh now use it for harness ancestry and liveness checks, but only when the ps read itself fails. Healthy POSIX hosts keep their existing verdict paths. This branch also adds ^devin$ to FM_HARNESS_RE.
  • Lock fallback on Windows: fm_lock_try_create now falls back to a mklink /J junction. The fallback only runs on hosts where ln -s cannot create a real link.
  • herdr and teardown on Windows:
    • bin/backends/herdr.sh handles herdr's Windows socket paths (drive letters), the missing ACL presentation namespace, and pane capabilities.
    • When herdr reports a null foreground_cwd, fm-spawn.sh claims the worktree through a durable lease and checks the FM_WT_<id> marker.
    • fm-teardown.sh finds processes through /proc/<pid>/cwd when lsof is missing. It also treats D:/… and /d/… as the same state directory, which stops teardown from wrongly refusing on itself.
    • fm-pr-lib.sh falls back to a scratch-file check for mode bits that chmod cannot set on this host.
  • Tests and docs:
    • New suites cover the Win32 process lib, the junction lock, and herdr spawns on Windows.
    • Existing fixtures now work on Windows: they probe which pid space is in use, rename real binaries instead of symlinking fakes, and add a fake ps -l that returns the whole process table.
    • POSIX-only cases, such as process groups, are skipped when the host lacks the capability.
    • docs/herdr-backend.md and docs/scripts.md document the changes.

🤖 Generated with Claude Code

Risk Assessment

⚠️ Medium: Round 2's preload fix is correct and every Win32 fallback stays gated on dead POSIX ps. The change is still a broad platform layer across lock, ancestry, spawn and teardown paths, and its Windows paths are proven mainly by fabricated-table fixtures, so a human should review it before merge.

Testing

I ran the real fm-sessionstart-nudge.sh hook on a MINGW64 host where ps -o doesn't work. A fixture staged without fm-win32-proc-lib.sh prints a 'No such file' source error into the captured output, which is the defect the fixture repair fixes; with the lib staged the output is clean. A .lock holding the MSYS $$ still triggers the nudge, a .lock holding the shell's WINPID is correctly silent, and a dead WINPID still triggers the nudge. The nudge suite passes through the owned-lock case, which fails on base. The two failures after it also fail on this host without this branch's changes: Node can't spawn a .sh directly, and the full-digest run case fails the same way on base. The cursor, calm-pi, and opencode/pi live-e2e suites could not run here because the host has no C compiler, tmux, or pi. The repairs are committed as cc5af92. This change has no visual UI, so there are no screenshots.

  • Live validation: ✅ go - 3 of 5 scenarios driven live against the product
Scenario Result Live Evidence
On Git Bash where ps -o is dead, a primary whose .lock holds the session shell's WINPID gets no nudge (the lock holder is found in the ancestry) ✅ pass live nudge-fixture-repair-live.txt case D (empty output); tests/fm-sessionstart-nudge.test.sh test_owned_lock_is_silent passes on the branch and fails at base 9284978
Adversarial: a .lock holding a dead WINPID or the MSYS $$ (not a Win32 ancestor) still gets the session-start nudge ✅ pass live nudge-fixture-repair-live.txt cases C and E print the FIRSTMATE_OP session-start line
A fixture that stages fm-sessionstart-nudge.sh plus fm-win32-proc-lib.sh gives clean nudge output; without the lib, a source error leaks into captured output ✅ pass live nudge-fixture-repair-live.txt cases A (source error in output) and B (clean nudge line)
The OpenCode plugin delivers the exact nudge once per session (fixture now stages the lib) ⏸️ untested no Node on Windows cannot spawn a shebang .sh directly (EFTYPE), so the plugin never runs the hook on this host, with or without this branch. It needs a POSIX host (Linux CI) to run.
The cursor, calm-pi interactive e2e, and opencode/pi primary live e2e fixtures work with the lib staged ⏸️ untested no The host has no C compiler, tmux, or pi on PATH. Linux CI (with those installed) runs these suites.
Evidence: Live nudge hook fixture-repair demo (Git Bash)

Source: Live nudge hook fixture-repair demo (Git Bash)

== host: MINGW64_NT-10.0-26200; ps -o usable? no
== A. fixture staged WITHOUT fm-win32-proc-lib.sh (pre-repair fixture shape), no lock
exit=0 output=[/tmp/tmp.LClxXXitma/a/bin/fm-sessionstart-nudge.sh: line 20: /tmp/tmp.LClxXXitma/a/bin/fm-win32-proc-lib.sh: No such file or directory
⁣FIRSTMATE_OP: v1 session-start: Run `bin/fm-session-start.sh` now, exactly once, before executing any other instructions.]
== B. fixture staged WITH fm-win32-proc-lib.sh (repaired), no lock -> nudge expected
exit=0 output=[⁣FIRSTMATE_OP: v1 session-start: Run `bin/fm-session-start.sh` now, exactly once, before executing any other instructions.]
== C. lock = bash $$ (2704, MSYS pid) - pre-repair test fixture value
exit=0 output=[⁣FIRSTMATE_OP: v1 session-start: Run `bin/fm-session-start.sh` now, exactly once, before executing any other instructions.]
== D. lock = this shell's WINPID (60268) - repaired fixture value -> must be silent
exit=0 output=[]
== E. adversarial: lock = dead WINPID 999999 -> must nudge
exit=0 output=[⁣FIRSTMATE_OP: v1 session-start: Run `bin/fm-session-start.sh` now, exactly once, before executing any other instructions.]
Evidence: fm-sessionstart-nudge suite run (worktree)

Source: fm-sessionstart-nudge suite run (worktree)

ok - fm-sessionstart-nudge: a genuine primary gets one explicitly marked instruction line
ok - fm-sessionstart-nudge: NO_MISTAKES_GATE is silent
ok - fm-sessionstart-nudge: .no-mistakes gate common-dir is silent
ok - fm-sessionstart-nudge: an unmarked linked task worktree is silent
ok - fm-sessionstart-nudge: a marked linked secondmate home is a primary
ok - fm-sessionstart-nudge: a checkout without state is silent
ok - fm-sessionstart-nudge: a lock holder in process ancestry is already run
ok - fm-sessionstart-nudge: the Win32 walk recognizes a lock holder, a live stranger, and a dead owner
# skip: unprivileged PID namespaces are unavailable here, so the namespace pid 1 lock owner is unverified
not ok - OpenCode exact nudge delivery: expected exit 0, got 1

real	0m10.537s
user	0m1.688s
sys	0m2.173s
Evidence: fm-sessionstart-nudge suite without the OpenCode Node-spawn case

Source: fm-sessionstart-nudge suite without the OpenCode Node-spawn case

ok - fm-sessionstart-nudge: a genuine primary gets one explicitly marked instruction line
ok - fm-sessionstart-nudge: NO_MISTAKES_GATE is silent
ok - fm-sessionstart-nudge: .no-mistakes gate common-dir is silent
ok - fm-sessionstart-nudge: an unmarked linked task worktree is silent
ok - fm-sessionstart-nudge: a marked linked secondmate home is a primary
ok - fm-sessionstart-nudge: a checkout without state is silent
ok - fm-sessionstart-nudge: a lock holder in process ancestry is already run
ok - fm-sessionstart-nudge: the Win32 walk recognizes a lock holder, a live stranger, and a dead owner
# skip: unprivileged PID namespaces are unavailable here, so the namespace pid 1 lock owner is unverified
not ok - startup did not run the full digest (missing: 'SESSION START - /tmp/fm-sessionstart-nudge.wdHTOz/run-startup')
--- output ---


real	0m9.436s
user	0m1.677s
sys	0m2.035s
Evidence: fm-cursor-primary suite run

Source: fm-cursor-primary suite run

not ok - a C compiler is required to build the fake Cursor process

real	0m1.229s
user	0m0.165s
sys	0m0.241s
- Outcome: ⚠️ 2 infos across 2 runs (32m37s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 5 issues found → auto-fixed (2) ✅
  • 🚨 bin/fm-win32-proc-lib.sh:43 - declare -A _FM_WIN32_ROW=() runs at source time, but stock macOS /bin/bash 3.2 has no associative arrays. The repo explicitly supports bash 3.2 (the ci.yml macos-stock-bash job; fm-classify-lib.sh:604 notes 'no associative arrays so the fold runs on bash 3.2'). On 3.2 this line fails with 'declare: -A: invalid option' and a non-zero status. So every script that sources the lib breaks on macOS, even though the Win32 path can never be reached there. Failure scenario: fm-branch-outcome.sh runs set -eu (line 92) and then sources the lib at top level (line 100), so it exits right away. fm-inbox.sh (set -euo pipefail) sources fm-session-lock-lib.sh at line 850, which sources this lib (fm-session-lock-lib.sh:109). The set -u hooks print the error to stderr on every run: fm-harness.sh:80, fm-sessionstart-nudge.sh:20, and fm-lock.sh, fm-turnend-guard.sh and fm-claude-stop-autoarm.sh through fm-session-lock-lib.sh. Fix: don't declare the associative array at source time. Create it lazily inside fm_win32_proc_load behind a BASH_VERSINFO[0] -ge 4 check (for example declare -gA), and have the load fail closed on older bash. Alternatively, drop the associative index and use an awk lookup.
  • ⚠️ bin/fm-harness.sh:308 - Intent conformance. The intent says 'healthy POSIX hosts take byte-identical verdict paths and fallbacks only fire when the ps read itself fails'. In the code, though, the Win32 fallback runs whenever a POSIX walk finds no match, or whenever kill -0 fails on an ordinary dead pid, not only when ps fails. Failure scenario: on WSL, powershell.exe is on PATH through interop. A walk that finds no harness, or a stale-lock liveness check on a dead Linux pid, then starts powershell.exe (seconds of latency). It also looks the Linux pid up in the Windows process table as if it were a Win32 pid: on Linux, fm_win32_ancestor_winpids reuses $$ as the seed because ps -l columns differ. A dead Linux lock-holder pid that happens to match the pid of a Windows claude.exe/codex process (for example Claude Desktop) is then reported as a live harness, which wedges the lock. On plain Linux and macOS every miss also costs an extra ps -l fork. Same invariant at: fm-harness.sh:171 (ancestry_names_omp falls back after a normal walk end); fm-session-lock-lib.sh:184 (fm_harness_ancestry_pids falls back whenever printed=0); fm-session-lock-lib.sh:223 (fm_harness_pid_alive falls back on any kill -0 failure); fm-sessionstart-nudge.sh:38 (kill -0 || fm_win32_pid_alive) and :50 (unconditional Win32 walk after the POSIX loop). Suggested fix: follow the ps_dead pattern that fm-branch-outcome.sh:412 already uses, so each walk falls back only when its own ps -o read failed. For the pid-liveness checks, fall back only when ps -o is proven unusable, not just because kill -0 failed.
  • ⚠️ bin/fm-spawn.sh:4108 - Every herdr spawn now probes fm_backend_herdr_foreground_cwd_supported. Any miss sends the spawn into the Windows arm, and that arm exits 1 immediately when cygpath is missing. Failure scenario: on Linux or macOS herdr, a transient pane get error, target_ready failure, or a pane that still reports a null foreground_cwd after the 3s retry window now aborts the spawn with the misleading error 'cannot report a live foreground cwd and no cygpath exists'. Before this change, the 60s treehouse get discovery poll tolerated that. Fix: take the Windows arm only on a host that can run it, for example command -v cygpath in the gate before the probe. Otherwise fall through to the existing discovery poll.
  • ⚠️ bin/backends/herdr.sh:808 - Simplification / scope. fm_backend_herdr_presentation_lock_namespace_valid now repairs a non-700 /tmp/firstmate-herdr-presentation (chmod 700, then accept) instead of refusing it, on every host. The intent asks only for handling Windows' lack of ACL mode bits (chmod has no effect there). Accepting a namespace that was group- or world-writable on POSIX goes beyond that. Entries another local user planted while it was open survive the chmod and are then trusted as presentation locks. Recommendation: keep only the narrower rule. Use the chmod no-op probe to detect filesystems that ignore mode bits and accept on ownership there; on hosts where chmod takes effect, keep refusing a namespace that was not 700.
  • ⚠️ tests/fm-devin-harness.test.sh:55 - The fabricated-table case is written as FM_TEST_OWN_WINPID=500 FM_TEST_WIN32_TABLE=... PATH=&#34;$fakebin:$PATH&#34; out=$(...). That line only assigns variables, so FM_TEST_OWN_WINPID and FM_TEST_WIN32_TABLE become unexported shell variables and never reach the fake ps or powershell.exe. The fake ps then fails on ${FM_TEST_OWN_WINPID:?}, and the fake powershell prints an empty table. The Win32 path this case claims to isolate never runs, so the negative check passes trivially. PATH also stays pointed at the fakebin (whose ps rejects -o) for the rest of the file, including the fm-busy-event.sh and fm-devin-config.sh cases. Fix: move the assignments inside the substitution as a command prefix, e.g. out=$(FM_TEST_OWN_WINPID=500 FM_TEST_WIN32_TABLE=&#34;...&#34; PATH=&#34;$fakebin:$PATH&#34; &#34;$TMP_ROOT/names/devin-helper&#34; -c ... ), or use env.

🔧 Fix applied.
2 warnings still open:

  • ⚠️ bin/fm-harness.sh:308 - Intent conformance. The intent says 'healthy POSIX hosts take byte-identical verdict paths and fallbacks only fire when the ps read itself fails'. In the code, though, the Win32 fallback runs whenever a POSIX walk finds no match, or whenever kill -0 fails on an ordinary dead pid, not only when ps fails. Failure scenario: on WSL, powershell.exe is on PATH through interop. A walk that finds no harness, or a stale-lock liveness check on a dead Linux pid, then starts powershell.exe (seconds of latency). It also looks the Linux pid up in the Windows process table as if it were a Win32 pid: on Linux, fm_win32_ancestor_winpids reuses $$ as the seed because ps -l columns differ. A dead Linux lock-holder pid that happens to match the pid of a Windows claude.exe/codex process (for example Claude Desktop) is then reported as a live harness, which wedges the lock. On plain Linux and macOS every miss also costs an extra ps -l fork. Same invariant at: fm-harness.sh:171 (ancestry_names_omp falls back after a normal walk end); fm-session-lock-lib.sh:184 (fm_harness_ancestry_pids falls back whenever printed=0); fm-session-lock-lib.sh:223 (fm_harness_pid_alive falls back on any kill -0 failure); fm-sessionstart-nudge.sh:38 (kill -0 || fm_win32_pid_alive) and :50 (unconditional Win32 walk after the POSIX loop). Suggested fix: follow the ps_dead pattern that fm-branch-outcome.sh:412 already uses, so each walk falls back only when its own ps -o read failed. For the pid-liveness checks, fall back only when ps -o is proven unusable, not just because kill -0 failed.
  • ⚠️ bin/fm-harness.sh:318 - This was in the original change, not added by the fix round. On a Git Bash/MSYS host each Win32 fallback walk starts PowerShell twice, although the lib's contract says the table loads once per process. The ancestor list is built with for winpid in $(fm_win32_ancestor_winpids ...). The command substitution is a subshell: fm_win32_ancestor_winpids calls fm_win32_proc_load there, and the cached table and _FM_WIN32_ROW are thrown away when the subshell exits. The loop body then calls fm_win32_proc_get in the parent, which finds _FM_WIN32_TABLE_LOADED=0 and runs Get-CimInstance again. Each fallback walk therefore pays about 2×200-400ms, and these walks run in hooks on every turn. Same pattern at: fm-harness.sh:181 (_fm_ancestry_names_omp_win32), fm-harness.sh:345/379 (fm_win32_proc_pairs in a substitution, then fm_win32_proc_get in the parent), and fm-session-lock-lib.sh:117 (_fm_harness_ancestry_pids_win32). fm-sessionstart-nudge.sh:50 and fm-branch-outcome.sh:424 avoid it only when an earlier parent-side fm_win32_pid_alive call has already loaded the table. Fix: call fm_win32_proc_load || return ... in the parent before each $(fm_win32_ancestor_winpids) / $(fm_win32_proc_pairs) substitution, so the subshell inherits the loaded table. That call is already gated by fm_win32_proc_available, so POSIX hosts are unaffected.

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

⚠️ **Test** - 2 infos
  • ⚠️ The Test agent did not finish within its invocation budget. Reported: agent run tests timed out after 30m0s: agent last produced output 18s ago (140 observed); agent reported: claude exited: exit status 1:. This is a budget or provider-slowness cut, not a code failure. Re-running the same request costs another full budget, so no further attempt is made automatically. If this repository's targeted tests or evidence gathering routinely approach the default 30m0s, raise test_agent_timeout in global config. Respond with fix to spend another budget: a repair turn runs only for selected findings other than this budget cut, then validation re-runs. Or abort and retry after raising the budget.
  • 🚨 Approval is refused: the run worktree at ~.no-mistakes\worktrees\c02c87ead702\01M38ZEEQWQH82T97JZCDWHS9X holds work no Test turn validated, and the steps after Test would commit and publish it. It holds uncommitted changes to tests/fm-calm-pi-extension.test.sh, tests/fm-cursor-primary.test.sh, tests/fm-opencode-primary-live-e2e.test.sh, tests/fm-pi-primary-live-e2e.test.sh, tests/fm-sessionstart-nudge.test.sh (inspect with git -C ~\.no-mistakes\worktrees\c02c87ead702\01M38ZEEQWQH82T97JZCDWHS9X status and git -C ~\.no-mistakes\worktrees\c02c87ead702\01M38ZEEQWQH82T97JZCDWHS9X diff). Respond with fix to validate it, or abort.

🔧 No changes applied.
2 infos still open:

  • ℹ️ tests/fm-sessionstart-nudge.test.sh:266 - test_opencode_plugin_delivers_exact_nudge_once cannot pass on native Windows: Node's child_process.spawn of bin/fm-sessionstart-nudge.sh fails with EFTYPE/ENOENT because Windows cannot exec a shebang script, so no prompt is delivered. Because the suite exits at the first failure, the rest of fm-sessionstart-nudge.test.sh never runs here. This is a limitation of the host and the plugin, not of this change, and the intent does not cover OpenCode-plugin Windows support.
  • ℹ️ tests/fm-sessionstart-nudge.test.sh:1160 - test_run_startup_runs_the_full_digest fails on this Git Bash host ('startup did not run the full digest'), and it fails the same way at base 9284978, so this branch did not cause it. It is left for CI and any later Windows follow-up.
  • Live validation: ✅ go - 3 of 5 scenarios driven live against the product
Scenario Result Live Evidence
On Git Bash where ps -o is dead, a primary whose .lock holds the session shell's WINPID gets no nudge (the lock holder is found in the ancestry) ✅ pass live nudge-fixture-repair-live.txt case D (empty output); tests/fm-sessionstart-nudge.test.sh test_owned_lock_is_silent passes on the branch and fails at base 9284978
Adversarial: a .lock holding a dead WINPID or the MSYS $$ (not a Win32 ancestor) still gets the session-start nudge ✅ pass live nudge-fixture-repair-live.txt cases C and E print the FIRSTMATE_OP session-start line
A fixture that stages fm-sessionstart-nudge.sh plus fm-win32-proc-lib.sh gives clean nudge output; without the lib, a source error leaks into captured output ✅ pass live nudge-fixture-repair-live.txt cases A (source error in output) and B (clean nudge line)
The OpenCode plugin delivers the exact nudge once per session (fixture now stages the lib) ⏸️ untested no Node on Windows cannot spawn a shebang .sh directly (EFTYPE), so the plugin never runs the hook on this host, with or without this branch. It needs a POSIX host (Linux CI) to run.
The cursor, calm-pi interactive e2e, and opencode/pi primary live e2e fixtures work with the lib staged ⏸️ untested no The host has no C compiler, tmux, or pi on PATH. Linux CI (with those installed) runs these suites.
  • bash tests/fm-sessionstart-nudge.test.sh (worktree): it passes through the owned-lock and Win32-walk cases, then stops at the OpenCode delivery case (Node EFTYPE, see findings)
  • bash tests/fm-sessionstart-nudge.test.sh with only the OpenCode Node-spawn case disabled, in a temporary copy that was then deleted: all cases up to test_run_startup_runs_the_full_digest pass
  • The same suite at base 9284978 (via git archive into /tmp): test_owned_lock_is_silent fails there ('owned lock nudge must be silent'), and test_run_startup_runs_the_full_digest fails the same way it does on the branch
  • bash tests/fm-cursor-primary.test.sh: stops immediately because the host has no C compiler
  • Live nudge-hook demo: a fixture primary staged with and without the lib, and .lock set to $$, the shell's WINPID, and a dead WINPID
  • Checked that the tools the other suites need (tmux, pi, cc/gcc/clang) are on PATH: all are missing
  • git commit of the five test-file repairs (cc5af92)
✅ **Document** - passed

✅ No issues found.

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

✅ No issues found.

kendylx and others added 16 commits September 24, 2026 12:50
Git Bash without Developer Mode turns ln -s into a silent directory copy,
so fm_lock_try_create could never verify the link and every lock failed.
After the normal path fails verification, fm_lock_try_create now cleans
the stray copy (known files only, so rmdir still refuses foreign content)
and asks cmd.exe for a directory junction - a real filesystem link Cygwin
reads as a symlink, no privileges required. Capability is probed by
trying and latched per process; creation is re-verified through the same
fm_lock_points_to_owner check, and a missing primitive still fails
closed. //c and //J keep MSYS argument conversion from mangling the
switches into paths.
…lities

Native Windows herdr reports socket_path in drive-letter form
(C:\Users\...\herdr.sock); canonicalize it through cygpath -u and re-check
the absolute result so Windows and POSIX spellings derive one presentation
lock identity instead of failing closed.

The presentation lock namespace required mode 700 verbatim, but Git
Bash/MSYS mounts are noacl: chmod is a silent no-op and every directory
stats 755. Attempt the repair chmod first, then treat an unchanged mode as
proof the filesystem cannot express mode bits and fall back to ownership +
the platform ACL boundary.

Also add the pane-capability primitives fm-spawn's Windows arm needs:
foreground_cwd support probing, foreground process naming, and literal
wait-output, since native Windows panes report foreground_cwd null.
Exact-mode invariants (600/700) are unanswerable on Git Bash/MSYS noacl
mounts: chmod synthesizes non-POSIX modes (chmod 000 reports 400), so
every private-file check refused forever on that host.

fm_pr_mode_bits_unfaithful positively proves chmod infidelity by mutating
a scratch sibling - never the caller's file - and stays false on any
probe failure so undetermined cases keep refusing. The private-file
validator and its two exact-mode call sites fall back to ownership +
device + link-count plus the platform ACL boundary there.
…dows

collect_local_firstmate_states deduplicated state dirs by raw spelling;
a state dir reachable as both D:/... and /d/... was scanned twice and the
self-skip read the task's own meta as a conflicting record, refusing
pool-slot teardown. Dedup by canonical directory identity instead.

Git Bash/MSYS has no lsof and its ps cannot express pgid or setpgrp a
real process group. The lsof-absent reap arm now resolves the tmux pane
leader only when ps -o pgid actually works there, and otherwise scans
/proc/<pid>/cwd - which MSYS does expose - through the same
identity-safe TERM-then-KILL flow.

Test fixtures gain the matching MSYS emulations: wrapper scripts where
ln -s copies binaries, a real-PATH lsof-absent mode where lsof is
genuinely missing, /proc-backed lsof/lstart emulation for the exec-
change case, and a platform skip where POSIX process groups cannot even
be constructed.
… panes

Native Windows herdr panes cannot report a live foreground cwd (cwd
tracking there is prompt-integration only), so the interactive treehouse
get discovery poll can never observe worktree entry - and the pane's
native powershell/cmd shell cannot run the POSIX launch flow anyway.

When the foreground_cwd capability probe fails, spawn now reverses the
information flow: it takes Treehouse's durable lease firstmate-side under
the project lock (get --lease --json --lease-holder fm-<id>), enters Git
Bash for powershell/cmd panes, and proves the pane reached the leased
slot with an output marker the echoed command line cannot fake. Every
failure releases the lease through the abort cleanup while the project
lock is still held; unrecognized pane shells refuse before any launch.
Three fixture gaps made the suite unbuildable on Windows:

- The fake python3 was shebang-less, relying on the POSIX ENOEXEC shell
  fallback; noacl mounts cannot set an execute bit, so a file is runnable
  there only through #! and command -v skipped the fake for the real
  interpreter. Emit an explicit bash shebang instead.
- The symlink-at-shim refusal needs a creatable symlink; MSYS without
  Developer Mode can only copy. Skip by capability probe.
- The fail-closed retry cases need chmod 0000 to deny reads; MSYS
  synthesizes only 400 (still readable). Skip via a scratch-sibling
  mode_denial_works probe instead of uname.
… MSYS

The private-spec assertion demanded a literal 600 that noacl mounts
cannot express; it now accepts the shared fm_pr_mode_bits_unfaithful
verdict, matching the production fallback.

The unregister symlink-refusal half needs a creatable symlink; MSYS
without Developer Mode only copies. Skip by capability probe while the
hard-link refusal half still verifies.
… host

Every case past the inert section drives a detached runner that must
isolate and prove its own process group through ps -o pgid; Git Bash/MSYS
perl setpgrp creates no group and MSYS ps cannot express pgid, so the
runner substrate does not exist there. Gate on the capability probe the
runner itself uses rather than uname, so the inert contract still verifies
and the suite exits green on hosts without the substrate.
…nd ln -s cannot

The ancestry suite never ran green on Git Bash/MSYS: its fixtures recorded
Cygwin pids the lock world never sees, the copied fixture home lacked
fm-win32-proc-lib.sh so the real lock lib could not even load there, and a
per-hop ps -l -p/fields substitution chain cost ~18 process launches per
ancestry walk, which pushed every fm-lock/autoarm/guard call past the
fixture's phase budgets.

- Probe the operative lock pid space by capability (ps -o vs the Win32
  table), record operative pids in .lock/.lock-session/CLAUDE_PID, and keep
  Cygwin pids only for kill/wait.
- Copy renamed real binaries instead of ln -s where the host cannot link.
- Copy fm-win32-proc-lib.sh into fixture homes; fm-session-lock-lib.sh
  sources it unconditionally.
- Replace the per-hop substitutions in fm_win32_ancestor_winpids with one
  ps -l table plus a row index built at load (fm_win32_proc_get gives callers
  zero-fork field reads): ~6s to ~1s per walk on this host.
- Fix a latent break where the trusted-session-id path called the
  nonexistent _fm_win32_lookup; it now calls fm_win32_proc_fields.
- Fake ps stubs answer the whole-table ps -l the lib now reads, keyed to the
  caller chain plus caller-declared extra rows for explicit-pid translation.
- Widen the fixture's FM_CLAUDE_AUTOARM_EPOCH_FRESH: the guard's 15s rewake
  freshness window is sized for production timing, not spawn-taxed hosts.

Evidence: tests/fm-session-lock-ancestry.test.sh 22/0 on this host for the
first time; fm-win32-proc-lib 9/9; fm-devin-harness 10/10;
fm-harness-precedence 13/13; fm-branch-supervision 24/0; fm-omp-harness and
fm-sessionstart-nudge identical to their pre-existing baselines.
…ck lib

fm-session-lock-lib.sh now sources the Win32 process-table lib
unconditionally for its ancestry fallback, so every fixture checkout that
copies the lock lib, fm-harness.sh, fm-branch-outcome.sh, or
fm-sessionstart-nudge.sh into a fake bin/ must copy the new lib beside it
or sourcing the copied script fails outright.
…cestry

- fm-procevent-when: every case past the runner-free arm/retire binding needs
  a live detached runner, and the runner requires POSIX process-group proof
  (ps -o pgid=) that Git Bash/MSYS does not have; gate on the capability,
  matching fm-procevent's runner gate.
- fm-devin-harness: the devin-helper negative ancestry case ran under ambient
  ancestry, so inside a real Devin session the honest verdict is the true
  devin.exe ancestor; fabricate the process table for that probe so the case
  isolates the helper's own name.
…ative WINPID lock

fm-sessionstart-nudge.sh now sources fm-win32-proc-lib.sh unconditionally, so
fixtures that copy the hook must stage the lib beside it (otherwise the source
error leaks to stderr/captured output). The owned-lock nudge case writes this
shell's WINPID where ps -o is dead, matching the pid space the Win32 walk reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kendylx

kendylx commented Sep 24, 2026

Copy link
Copy Markdown
Author

Closing: this PR was opened against the wrong target. The change is being delivered on the fork (kendylx#1) instead. Apologies for the noise.

@kendylx kendylx closed this Sep 24, 2026
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