Repository navigation
Fix browse daemon crash-loop diagnostics + a shell-injection bug found along the way - #2461
Closed
phuttimatebenchanakatkul wants to merge 1 commit into
Closed
phuttimatebenchanakatkul wants to merge 1 commit into
phuttimatebenchanakatkul wants to merge 1 commit into
Conversation
Root cause: the detached daemon's stdout/stderr were wired to 'ignore'
on every platform, so every console.error('[browse] FATAL: ...') from
a crash -- Chromium disconnect, uncaughtException, unhandledRejection --
went nowhere. A restart was indistinguishable from any other cause of a
dropped session; nothing on disk ever recorded why.
cli.ts: both the Windows and macOS/Linux spawn paths now redirect
stdout/stderr to <stateDir>/browse-daemon.log (append mode, accumulates
across the daemon's full lifetime and every respawn).
That immediately surfaced two real, previously invisible bugs:
1. "[browse] FATAL uncaught exception: spawn bun ENOENT" --
bun-polyfill.cjs's Bun.spawn/spawnSync polyfill called Node's
child_process.spawn with a bare command name ('bun'), which Windows
can't resolve without PATHEXT lookup. First attempt used shell:true
with hand-rolled double-quote escaping; verified empirically that this
does NOT neutralize cmd.exe metacharacters (&|^%<>) and is exploitable
via browser-skill-commands.ts's `...opts.skillArgs` passthrough --
spawning a resolved .cmd path with an arg containing
`& echo INJECTED > proof.txt` created the file. Replaced with
cross-spawn (already resolved in node_modules transitively via
@modelcontextprotocol/sdk, now a direct dependency) -- the established
library for correct Windows PATHEXT resolution + argument escaping
together. Re-verified: same injection payload no longer executes,
normal resolution (bun --version) still works.
2. "[browse] FATAL unhandled rejection: browser?.process is not a
function" -- resolveDisconnectCause() (the crash classifier itself)
threw on some browser/connection-mode shapes, and that throw was
unhandled (fire-and-forget void call from the 'disconnected' event),
taking the whole daemon down a second, harder-to-diagnose way. Now
wrapped in try/catch, logging the caught error (so a future different
failure here stays diagnosable) and defaulting to the existing
conservative 'crash' classification.
Verified end-to-end multiple times: killed the live Chromium child under
a running daemon, confirmed the log shows a single clean
"FATAL: Chromium process crashed or was killed", the terminal-agent
respawns successfully, and the daemon auto-recovers to a healthy new
PID. 24/24 pre-existing browser-manager-unit tests pass.
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
4 of 9 tasks
Owner
|
Thank you — this was absorbed on main (credited in the v1.6x CHANGELOG entries; roster in PR #2604). Closing. |
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
'ignore'on every platform, so everyconsole.error('[browse] FATAL: ...')from a crash (Chromium disconnect, uncaughtException, unhandledRejection) went nowhere — a restart was indistinguishable from any other cause of a dropped session, with nothing on disk recording why.cli.ts: both the Windows and macOS/Linux spawn paths now redirect stdout/stderr to<stateDir>/browse-daemon.log(append mode, accumulates across the daemon's full lifetime and every respawn).spawn bun ENOENT—bun-polyfill.cjs'sBun.spawn/spawnSyncpolyfill called Node'schild_process.spawnwith a bare command name ('bun'), which Windows can't resolve without PATHEXT lookup.browser?.process is not a function—resolveDisconnectCause()(the crash classifier itself) threw on some browser/connection-mode shapes, and being an unhandled fire-and-forget rejection, took the whole daemon down a second, harder-to-diagnose way.A note on how the fix for #1 evolved
My first attempt used
shell:truewith hand-rolled double-quote escaping to fix the PATHEXT resolution. I verified empirically (not just reasoned about it) that this does not neutralize cmd.exe metacharacters (&|^%<>), and is reachable viabrowser-skill-commands.ts's...opts.skillArgspassthrough from$B skill run <name> --arg k=v. Spawning a resolved.cmdpath with an arg containing& echo INJECTED > proof.txtactually created the file.Replaced it with
cross-spawn— already resolved innode_modulestransitively via@modelcontextprotocol/sdk, now added as a direct dependency — the established library for correct Windows PATHEXT resolution + argument escaping together. Re-verified the same injection payload no longer executes, and normal resolution (bun --version) still works.Test plan
FATAL: Chromium process crashed or was killed, terminal-agent respawns successfully, daemon auto-recovers to a healthy new PID& echo INJECTED > proof.txt) no longer executes after thecross-spawnfixbun --versionvia bothspawnandspawnSync) still works, including paths/args containing spacesbrowser-manager-unittests passbun build --compilesucceeds for bothcli.tsand the Node server bundle🤖 Generated with Claude Code