Skip to content

fix(bin): resolve Windows/MSYS harness ancestry across the native process boundary - #4616

Open
xonaib wants to merge 1 commit into
kunchenguid:mainfrom
xonaib:fix/windows-harness-ancestry
Open

xonaib wants to merge 1 commit into
kunchenguid:mainfrom
xonaib:fix/windows-harness-ancestry

Conversation

@xonaib

@xonaib xonaib commented Sep 16, 2026

Copy link
Copy Markdown

Problem

On Windows, bin/fm-lock.sh was refusing to acquire the fleet lock inside a real Herdr + Claude session with error: cannot locate harness process in ancestry, even though claude.exe was a few hops up the real process tree.

The native Windows/MSYS failure mode

Git Bash/MSYS's ps only sees processes inside its own emulated process table, so it cannot find a harness that launched the current shell as a native Windows process.

This PR introduces fm_harness_ancestry_pids_windows, a fallback tried only when the POSIX ps walk finds no harness, to bridge that gap.

A native-only walk from /proc/$$/winpid is not sufficient across nested MSYS fork() boundaries because intermediate bash.exe processes can have transient Windows ParentProcessId values that no longer resolve in Win32_Process, even though MSYS still knows the correct logical parent relationship.

Why /proc alone isn't enough

MSYS's /proc only knows about processes visible to MSYS. It has no entries for native Windows ancestors above the MSYS boundary, such as claude.exe.

So a pure /proc walk also cannot reach the harness.

The fix

The Windows fallback now uses a hybrid ancestry walk:

  1. Climb MSYS's logical ancestry from $$ via /proc/<pid>/ppid, recording /proc/<pid>/winpid at each hop, until the MSYS parent reaches PID 1 or the next proc entry is unreadable.
  2. From the topmost MSYS-visible process's Windows PID, fetch the native Windows process tree with a single Get-CimInstance Win32_Process query and continue the ancestry walk there.
  3. Apply the same harness matching and contiguous-Claude-chain behavior as the existing POSIX path.

POSIX behavior is unchanged. The Windows fallback is only attempted if the existing POSIX ancestry walk finds no harness.

Tests

Added hermetic Windows/MSYS fallback coverage using a fake /proc tree, fake powershell.exe, and an overridable starting MSYS PID.

The new tests cover:

  • missing /proc/<pid>/winpid
  • ensuring the Windows fallback is not used when POSIX already finds a harness
  • climbing past ordinary ancestors
  • stopping at a single non-Claude harness
  • case-insensitive harness matching
  • failure when no known harness exists
  • nested MSYS fork() ancestry before crossing into the native Windows tree

All 7 new Windows fallback tests pass.

Also manually verified in a real Herdr + Claude Windows session that fm_harness_ancestry_pid now resolves the real claude.exe PID where it previously failed.

Fixes #3396.
Addresses the harness-ancestry portion of #3653.

Known remaining gap

This does not make Firstmate fully ready end-to-end on Windows yet.

Full native-Windows readiness remains blocked separately by #3267, an unrelated pre-existing issue in the claim-lock primitive. This PR does not touch that behavior.

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.

Windows/Git Bash: session lock always refuses - harness ancestry cannot be resolved

1 participant