Skip to content

fix: detect Bun compiled binary when import.meta.url percent-encodes ~BUN - #208

Merged
gjtorikian merged 1 commit into
mainfrom
fix/windows-compiled-binary-detection
Jul 26, 2026
Merged

fix: detect Bun compiled binary when import.meta.url percent-encodes ~BUN#208
gjtorikian merged 1 commit into
mainfrom
fix/windows-compiled-binary-detection

Conversation

@gjtorikian

Copy link
Copy Markdown
Contributor

Why

The v0.20.0 release failed both Windows smoke tests with:

VERIFY_ASSETS_AGENT_SDK_FAILED: Cannot find module
'@anthropic-ai/claude-agent-sdk-win32-x64/package.json' from 'B:\~BUN\root\workos-windows-x64.exe'

isCompiledBinary() checks import.meta.url for $bunfs (POSIX) or ~BUN (Windows). But Bun's URL serializer (WebKit WTF::URL::fileURLWithFileSystemPath) percent-encodes the tilde, so on Windows the URL is file:///B:/%7EBUN/root/… — neither marker matches. The compiled binary then took the dev-mode path and tried to resolve the Agent SDK from node_modules, which doesn't exist in a standalone binary.

Verified empirically (same serializer as Bun.pathToFileURL):

$ bun -e 'console.log(Bun.pathToFileURL("/tmp/~BUN/root/x.exe").href)'
file:///tmp/%7EBUN/root/x.exe

POSIX targets were unaffected because $ isn't percent-encoded, which is why all six macOS/Linux smoke tests passed.

What

  • Extract the marker check into isBunVirtualFsUrl() and additionally match the percent-encoded %7EBUN form.
  • Regression tests covering the exact URL shape observed in the failed Windows smoke run.

Note: Bun.isStandaloneExecutable is the official API for this, but it shipped after Bun 1.3.14 (the version CI pins), so the URL heuristic stays.

Verification

  • bun run test (2033 pass), bun run typecheck, bun run build all green.
  • The real gate is the release pipeline's Windows smoke jobs, which run internal verify-assets on real Windows hardware before anything publishes.

🤖 Generated with Claude Code

…~BUN

On Windows, the compiled binary's virtual filesystem root B:\~BUN\ shows
up in import.meta.url with the tilde percent-encoded
(file:///B:/%7EBUN/root/...), so isCompiledBinary() returned false and the
binary tried to resolve the Agent SDK from node_modules instead of
downloading the pinned executable. Both v0.20.0 Windows smoke tests failed
on exactly this, which kept the release draft unpublished.

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

greptile-apps Bot commented Jul 26, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes Bun standalone-binary detection for percent-encoded Windows virtual-filesystem URLs.

  • Extracts the virtual-filesystem marker check into an exported helper.
  • Recognizes %7EBUN in addition to the existing POSIX and raw Windows markers.
  • Adds regression coverage for compiled and source-mode URL forms.

Confidence Score: 4/5

The PR appears safe to merge, with a non-blocking path-boundary hardening opportunity in the new encoded-marker check.

The intended Windows standalone URL is now detected, but matching %7EBUN anywhere can send an unusual source checkout path through the download-and-cache branch.

Files Needing Attention: src/lib/agent-sdk-assets.ts

Important Files Changed

Filename Overview
src/lib/agent-sdk-assets.ts Adds encoded Windows marker detection, though the unbounded substring match can classify ordinary source paths containing ~BUN as compiled.
src/lib/agent-sdk-assets.spec.ts Adds focused positive and negative tests for Bun virtual-filesystem URL detection.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/lib/agent-sdk-assets.ts:64
**Unbounded virtual-filesystem marker match**

The new check accepts `%7EBUN` anywhere in a source-mode module URL, so an ordinary path containing a `~BUN` component is classified as compiled and unnecessarily enters the download-and-cache flow instead of resolving the installed node_modules asset. Match the documented virtual-filesystem segment, such as `%7EBUN/root/`, to avoid breaking offline use from such paths.

Reviews (1): Last reviewed commit: "fix: detect Bun compiled binary when imp..." | Re-trigger Greptile

* tests.
*/
export function isBunVirtualFsUrl(url: string): boolean {
return url.includes('$bunfs') || url.includes('~BUN') || url.includes('%7EBUN');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unbounded virtual-filesystem marker match

The new check accepts %7EBUN anywhere in a source-mode module URL, so an ordinary path containing a ~BUN component is classified as compiled and unnecessarily enters the download-and-cache flow instead of resolving the installed node_modules asset. Match the documented virtual-filesystem segment, such as %7EBUN/root/, to avoid breaking offline use from such paths.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/agent-sdk-assets.ts
Line: 64

Comment:
**Unbounded virtual-filesystem marker match**

The new check accepts `%7EBUN` anywhere in a source-mode module URL, so an ordinary path containing a `~BUN` component is classified as compiled and unnecessarily enters the download-and-cache flow instead of resolving the installed node_modules asset. Match the documented virtual-filesystem segment, such as `%7EBUN/root/`, to avoid breaking offline use from such paths.

How can I resolve this? If you propose a fix, please make it concise.

@gjtorikian
gjtorikian merged commit 4c66d6e into main Jul 26, 2026
5 checks passed
@gjtorikian
gjtorikian deleted the fix/windows-compiled-binary-detection branch July 26, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant