fix: bundle server into browse binary, eliminate fallback chain#635
Open
sternryan wants to merge 1 commit intogarrytan:mainfrom
Open
fix: bundle server into browse binary, eliminate fallback chain#635sternryan wants to merge 1 commit intogarrytan:mainfrom
sternryan wants to merge 1 commit intogarrytan:mainfrom
Conversation
…) fallback chain The compiled browse binary now includes server.ts bundled via bun build --compile. When invoked with --server, the binary runs in server mode (the persistent Chromium daemon). The CLI spawns itself with --server instead of trying to locate server.ts on disk through the fragile resolveServerScript() fallback chain. Changes: - Add --server flag gate at top of cli.ts: dynamic import of server.ts - Add IS_COMPILED detection (import.meta.dir contains $bunfs) - startServer() spawns process.execPath --server in compiled mode - Dev mode (bun run) still uses resolveServerScript() via lazy getServerScript() - Add --external electron to build command (needed since server.ts now pulls in playwright-core which has an unused electron loader dependency) - Legacy process detection includes 'browse' binary name - main() gated on !IS_SERVER_MODE to prevent CLI execution in server mode Resolves TODOS.md P2: "Bundle server.ts into compiled binary"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
browsebinary now bundlesserver.tsviabun build --compile, eliminating the fragileresolveServerScript()fallback chain that caused bugs in v0.3.2--server, the binary runs as the persistent Chromium daemon instead of the CLI -- the CLI spawns itself with--serverrather than searching forserver.tson diskbun run browse/src/cli.ts) is unchanged and still usesresolveServerScript()via lazy resolutionTechnical approach
The problem:
resolveServerScript()tries multiple filesystem paths to findserver.tsat runtime (adjacent tocli.ts, relative toexecPath,BROWSE_SERVER_SCRIPTenv). In compiled binaries whereimport.meta.diris inside$bunfs, this chain falls through to theexecPath-relative check, which fails when the binary isn't installed in the expectedbrowse/dist/browsedirectory structure.The fix:
Server mode gate (top of
cli.ts): Checkprocess.argvfor--server. When present,import('./server')triggers server.ts's top-levelstart()call. The CLI'smain()is gated on!IS_SERVER_MODE.Compiled binary detection:
IS_COMPILED = import.meta.dir.includes('$bunfs')-- Bun's compiled binaries use a virtual filesystem prefix.startServer() priority chain:
Bun.spawn([process.execPath, '--server'], ...)Bun.spawn(['bun', 'run', getServerScript()], ...)Build change: Added
--external electronto the browse binary build command. Sinceserver.tsis now bundled, Bun follows the import chain throughplaywright-corewhich has an unused Electron loader dependency.Lazy server script resolution:
resolveServerScript()is now only called when actually needed (dev mode), not eagerly at module load time.Test plan
bun run buildcompiles successfully (377 modules bundled into browse binary)bun test test/skill-validation.test.ts test/gen-skill-docs.test.ts-- 601 tests passbun test browse/test/config.test.ts-- 31 tests pass (includesresolveServerScriptunit tests)browse/dist/browse statusauto-starts server via--serverflagbun run dev statusstill works via dev mode pathBROWSE_SERVER_SCRIPT=/path/to/server.ts browse statusstill works