Skip to content

fix(bin): canonicalize Windows drive-letter herdr socket paths before identity comparison - #2918

Closed
3min-lang wants to merge 2 commits into
kunchenguid:mainfrom
3min-lang:windows-herdr-socket-identity
Closed

3min-lang wants to merge 2 commits into
kunchenguid:mainfrom
3min-lang:windows-herdr-socket-identity

Conversation

@3min-lang

@3min-lang 3min-lang commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On native Windows the herdr server injects and reports drive-letter socket
paths (C:\Users\...\herdr.sock), while the launcher's claimed socket arrives
in POSIX spelling. fm_backend_herdr_socket_identity compares the two
literally, so the same socket compares unequal. That comparison is the single
owner for the presentation session lock and the launcher-identity
same-session proof, so both reject a socket that is in fact their own.

Fix

Convert a drive-letter path to its POSIX spelling with cygpath -u before the
existing directory resolution, so both sides land in the same form.

The case guard matches only [A-Za-z]:[\/]*, a shape that cannot occur on
Linux or macOS, so cygpath is never invoked there and behaviour on those
platforms is unchanged. An unresolvable drive-letter path returns 1 rather than
comparing a half-converted string.

Testing and scope

  • bin/fm-lint.sh bin/backends/herdr.sh clean.
  • Read against current main: fm_backend_herdr_socket_identity still compares
    the two spellings literally, so the mismatch this fixes is still present.

Scope note, stated because it limits what this PR can be said to fix: on the
Windows host where this was found, fm_backend_herdr_presentation_session_lock_path
fails earlier, at fm_backend_herdr_presentation_lock_namespace_valid, which
requires mode 700. Git Bash mounts both /c and /tmp with noacl, so
mkdir -m 700 is a silent no-op there and the namespace directory reads 755.
That is a separate defect with a separate cause, and this PR does not address
it. So this change is offered as a correctness fix to the identity comparison
itself, not as an end-to-end repair of presentation locking on Windows.

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "test(herdr): cover Windows drive-letter ..." | Re-trigger Greptile

Comment thread bin/backends/herdr.sh Resolved
Adds the regression coverage the review asked for. `cygpath` ships only with
Git for Windows, so the cases stub it and therefore run on every platform; the
adapter guard matches only `[A-Za-z]:[\/]*`, a shape that cannot occur on
Linux or macOS.

Three cases: a drive-letter spelling normalizes to the same identity as the
POSIX spelling of the same socket, a failed `cygpath` is refused rather than
compared half-converted, and empty `cygpath` output is refused.

Verified the cases fail for the right reason: with the guard removed, the
normalization case reports an empty identity against the expected POSIX path.
@3min-lang

Copy link
Copy Markdown
Contributor Author

Added the regression coverage in 72e411c.

Three cases in tests/fm-backend-herdr.test.sh:

  • a drive-letter spelling normalizes to the same identity as the POSIX spelling of the same socket
  • a failed cygpath is refused rather than compared half-converted
  • empty cygpath output is refused

cygpath ships only with Git for Windows, so the cases stub it and run on every platform. The adapter guard matches only [A-Za-z]:[\/]*, a shape that cannot occur on Linux or macOS, so nothing about the POSIX path changes.

I checked the cases can fail for the right reason rather than just passing: with the guard removed, the normalization case reports an empty identity against the expected POSIX path.

One note in case you see it on your side too. On this host tests/fm-backend-herdr.test.sh already halts earlier, at not ok - the ambiguity refusal did not name the candidate workspaces (missing: 'w1 w7'), and that failure reproduces identically on unpatched main here, so it is pre-existing and unrelated to this PR. Because the suite stops there, I verified the three new cases in isolation rather than through a full green run of the file.

🤖 Generated with Claude Code

@cr101

cr101 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Tested together with #8181 on native Windows (Windows 11, Git for Windows 2.51.0 / MSYS2, no WSL, Herdr 0.9.3). Together they make a Herdr spawn and cleanup work end to end there with a Git Bash pane, clearing the four defects tracked in #3283.

Setup. This PR's head (72e411c1) and #8181's head (52bb4793) were merged onto main 7c6170e2. This PR merges cleanly. #8181 then conflicts only in the list of test calls at the end of tests/fm-backend-herdr.test.sh, where both PRs append after the same line; keeping both sides resolves it. Every run used a named, isolated Herdr session, with a Git Bash pane ([terminal] default_shell) and the drive-letter socket Herdr reports (C:\Users\…\herdr.sock).

Results on the combined tree

  • fm_backend_herdr_canonical_socket_path maps the drive-letter socket to /c/Users/…/herdr.sock. fm_backend_herdr_launcher_identity then accepts the launcher pane, and the presentation session lock resolves.
  • A real fm-spawn.sh: exit 0. The folder probe proves the Git Bash pane is in the leased copy, the worker launches in its own workspace, and fm-teardown.sh takes the presentation lock and closes it, leaving panes and workspaces back at baseline. This worked with a token-free worker command, and a real Claude Code worker was also placed and torn down.
  • tests/fm-spawn-herdr-lease.test.sh: all 15 cases pass. This PR's three canonical_socket_path tests and fix(herdr): spawn task workers on native Windows Herdr with Git Bash panes #8181's namespace test pass. The full tests/fm-backend-herdr.test.sh stops at two host-specific tests (version_check … not installed, registered idle agent over a shell-only pane) that fail identically on unpatched main.

Control: main + #8181 without this PR. The same spawn is refused before any pane work:
error: herdr launcher pane 'w1:p1' reports an unusable socket path; refusing to place a worker from an unverifiable parent identity

So this PR is what lets #8181's Windows fixes take effect. Both need full-ci for the Linux/macOS suites, and they look easiest to review as a pair.

@cr101

cr101 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't carry the no-mistakes attestation that CONTRIBUTING.md requires and hasn't had activity since August, so I've opened #8185 as a no-mistakes replacement: the same two commits, unchanged, with @3min-lang as their author. It pairs with #8181, as verified above. Suggest closing this PR in favour of #8185. @3min-lang, thanks for the fix, and if you'd rather re-push it through no-mistakes yourself, say so and I'll close #8185.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Thanks @3min-lang for this fix and for the careful regression cases, and thanks @cr101 for the native Windows run with #8181.

I read the whole thread and compared the branches. #8185 carries your two commits unchanged, still authored by you, rebased onto main 7c6170e2. Its bin/ and tests/ changes match this PR line for line. It also has the no-mistakes attestation that CONTRIBUTING.md asks for, and this PR doesn't. Its CI never ran here either: the August runs were cancelled.

So we're taking the fix forward on #8185. You don't need to do anything. If you'd rather re-raise it yourself through git push no-mistakes, just say so here and we'll go with yours. Once #8185 lands, we'll close this PR as superseded, with your credit kept on the commits.

VISION.md, per rule: aligns on every rule. One captain, one interface: a refused Herdr spawn leaves no usable crew. Authority stays explicit: an unconvertible path is still refused. Scripts own the mechanics. Restart is a non-event: n/a. Delegation with a spine: aligns. The fleet outlives any vendor: it binds to the socket path Herdr actually reports. Scope: backend adapter.
Contract-class: restore. The launcher-identity check already promises to compare two spellings of one socket. The drive-letter guard only fires on a X:\ or X:/ shape that can't occur on POSIX.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Thanks again @3min-lang. Your two commits have landed on main through #8185 (merge 2886bbe), with you still credited as their author. I'm closing this PR as superseded so there's one source of truth for the socket-path fix (#3283 defect 1). Thank you for the fix and the regression cases.

@kunchenguid kunchenguid closed this Nov 5, 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.

3 participants