Skip to content

fix(session-broker): detect Windows bunfs paths when auto-launching the daemon#507

Merged
benvinegar merged 1 commit into
mainfrom
fix/502-windows-bunfs-daemon-argv
Jul 3, 2026
Merged

fix(session-broker): detect Windows bunfs paths when auto-launching the daemon#507
benvinegar merged 1 commit into
mainfrom
fix/502-windows-bunfs-daemon-argv

Conversation

@benvinegar

Copy link
Copy Markdown
Member

Fixes #502.

What

On Windows, Bun-compiled single-file executables report argv[1] as a virtual path on Bun's B: drive (B:\~BUN\root\hunk.exe — the reporter's log shows the forward-slash form). resolveDaemonLaunchCommand only recognized the Unix virtual prefix (/$bunfs/), so the Windows path fell through to the script-entrypoint branch (it contains path separators) and the auto-launched daemon became hunk.exe B:/~BUN/root/hunk.exe daemon serve — the compiled binary received the virtual path as a bogus first argument, the daemon never started, and hunk session list found no sessions unless hunk daemon serve was started manually.

How

Recognize the Windows bunfs prefix (b:/~bun/, case-insensitive, either separator) alongside /$bunfs/ in a small isBunfsEntrypoint helper, so compiled binaries relaunch via execPath with clean daemon serve args on every platform.

Testing

  • New unit test covering both separator forms; verified it fails against the previous implementation and passes with the fix.
  • bun run typecheck, full bun test (1084 pass), format, lint.
  • Not verified on real Windows hardware — the repro in Windows: hunk diff auto-launches daemon with invalid Bun argv #502 maps exactly onto the argv shapes covered by the unit test, but a confirmation from the reporter after release would be good.

🤖 Generated with Claude Code

…he daemon

Bun single-file executables on Windows report argv[1] as a virtual
B:\~BUN\root\<name>.exe path. That misses the Unix /$bunfs/ check but
matches the script-entrypoint pattern, so the daemon relaunched the
binary with the virtual path as a bogus first argument and never came
up, leaving 'hunk session' commands with no live sessions.

Fixes #502

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a Windows-only bug where Bun single-file executables reported argv[1] as a virtual B:/~BUN/... path instead of the Unix /$bunfs/... prefix, causing the daemon auto-launch to pass that virtual path as a bogus argument and silently fail.

  • Introduces a small isBunfsEntrypoint helper that recognises both the Unix (/$bunfs/) and Windows (b:/~bun/, case-insensitive, either separator) virtual-path prefixes, replacing a direct startsWith call in resolveDaemonLaunchCommand.
  • Adds a targeted unit test covering both separator forms (B:/~BUN/... and B:\\~BUN\\...) for the Windows branch, alongside the changeset note.

Confidence Score: 5/5

Safe to merge — the change is a narrow, well-tested detection fix with no impact on non-Windows paths.

The fix is minimal and surgical: one new helper function with two branches (existing Unix prefix unchanged, new Windows prefix added), a module-level constant, and an updated call site. Both separator forms for the Windows virtual path are covered by the new test. No existing behavior changes on Unix or native-binary paths, and the SCRIPT_ENTRYPOINT_PATTERN fallback is unaffected.

No files require special attention.

Important Files Changed

Filename Overview
src/session-broker/brokerLauncher.ts Adds isBunfsEntrypoint helper and BUNFS_WINDOWS_PREFIX constant; replaces inline startsWith with the new helper in resolveDaemonLaunchCommand. Logic is correct and well-commented.
src/session-broker/brokerLauncher.test.ts New test covers Windows bunfs paths with both forward-slash and backslash separators; uses a realistic Windows binary path as execPath. Good coverage of the new branch.
.changeset/windows-bunfs-daemon-argv.md Adds a patch-level changeset entry for hunkdiff describing the Windows daemon auto-launch fix.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["resolveDaemonLaunchCommand(argv, execPath)"] --> B{"argv[1] exists?"}
    B -- No --> E["return { command: execPath, args: ['daemon','serve'] }"]
    B -- Yes --> C{"isBunfsEntrypoint(argv[1])?"}
    C -- "starts with /$bunfs/ (Unix)" --> D["return { command: execPath, args: ['daemon','serve'] }"]
    C -- "matches b:/~bun/ after normalize (Windows)" --> D
    C -- No --> F{"SCRIPT_ENTRYPOINT_PATTERN matches?"}
    F -- Yes --> G["return { command: execPath, args: [argv[1],'daemon','serve'] }"]
    F -- No --> E

    style D fill:#22c55e,color:#fff
    style G fill:#3b82f6,color:#fff
    style E fill:#3b82f6,color:#fff
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["resolveDaemonLaunchCommand(argv, execPath)"] --> B{"argv[1] exists?"}
    B -- No --> E["return { command: execPath, args: ['daemon','serve'] }"]
    B -- Yes --> C{"isBunfsEntrypoint(argv[1])?"}
    C -- "starts with /$bunfs/ (Unix)" --> D["return { command: execPath, args: ['daemon','serve'] }"]
    C -- "matches b:/~bun/ after normalize (Windows)" --> D
    C -- No --> F{"SCRIPT_ENTRYPOINT_PATTERN matches?"}
    F -- Yes --> G["return { command: execPath, args: [argv[1],'daemon','serve'] }"]
    F -- No --> E

    style D fill:#22c55e,color:#fff
    style G fill:#3b82f6,color:#fff
    style E fill:#3b82f6,color:#fff
Loading

Reviews (1): Last reviewed commit: "fix(session-broker): detect Windows bunf..." | Re-trigger Greptile

@benvinegar benvinegar merged commit d4b829f into main Jul 3, 2026
12 of 13 checks passed
@benvinegar benvinegar deleted the fix/502-windows-bunfs-daemon-argv branch July 3, 2026 17:34
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: hunk diff auto-launches daemon with invalid Bun argv

1 participant