Skip to content

fix(browser): drain Chrome MCP stderr before connect, not after - #243

Merged
convyusboy merged 2 commits into
boonfrom
ridho/chrome-mcp-stderr-on-handshake-timeout
Sep 25, 2026
Merged

convyusboy merged 2 commits into
boonfrom
ridho/chrome-mcp-stderr-on-handshake-timeout

Conversation

@convyusboy

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Live testing of the browser-handoff flow on arief-openclaw-test kept failing with a generic Chrome MCP existing-session attach failed ... Chrome MCP handshake timed out, with no way to tell what actually went wrong. Direct investigation ruled out the obvious causes:

  • A raw curl WebSocket-upgrade probe from the same host to boon-core's CDP relay endpoint succeeded normally (401 for a bad ref, logged as expected).
  • boon-core's own pod logs (checked across all 3 replicas) show zero trace of the real attach attempt ever arriving, on two separate handoffs with two different Anchor sessions.

That means the failure is local to openclaw's own Chrome MCP subprocess, not the remote endpoint — but nothing was capturing that subprocess's own diagnostic output.

Why This Change Was Made

createRealSession (extensions/browser/src/browser/chrome-mcp.ts) only wired up getStderr = drainStderr(transport) after client.connect(transport) resolved successfully:

await client.connect(transport);
getStderr = drainStderr(transport);

So the one case this stderr capture exists for — a hung or failing MCP handshake — is exactly the case where it never runs, and the catch block's getStderr() call returns an empty string, discarding whatever the subprocess itself logged about why it never came up.

Checked the MCP SDK's own source (node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js): StdioClientTransport's constructor creates its stderr PassThrough immediately when stderr: "pipe" is passed, and its stderr getter's own docstring says it's "returned immediately, allowing callers to start consuming it before the child process is spawned." Draining it right after constructing transport (before calling connect()) is exactly the intended, documented use — not a hack.

User Impact

No behavior change for the happy path. When a Chrome MCP attach genuinely hangs or fails during the handshake (as currently happening on arief), the resulting error/log will include the subprocess's own stderr output instead of nothing — turning an opaque "handshake timed out" into an actionable diagnostic.

Evidence

  • Live: reproduced twice on arief-openclaw-test with two different Anchor sessions/profiles, both hitting the identical symptom; ruled out network reachability (curl succeeded) and boon-core-side involvement (zero log trace across all 3 boon-web pods in the exact time window).
  • Confirmed via direct source read of @modelcontextprotocol/sdk's StdioClientTransport (constructor + stderr getter) that draining before connect() is safe and intended.
  • node scripts/run-vitest.mjs extensions/browser/src/browser/chrome-mcp.test.ts — 46/46 passing (single-worker, per this worktree's known fan-out/worker-crash limitation for the full directory — pnpm tsgo:core, check:import-cycles, oxlint, and oxfmt all clean on the changed file).
  • git diff --numstat — 7 insertions / 2 deletions; no test file needed updating (existing tests replace createRealSession entirely via setChromeMcpSessionFactoryForTest, so none exercise this exact code path — documented in-code instead, matching this file's existing pattern for subtle ordering invariants).

🤖 Generated with Claude Code

Live debugging on arief-openclaw-test: the browser tool kept failing
with a generic "Chrome MCP handshake timed out" against a
browser-handoff CDP profile, with no way to tell why. Direct network
checks (curl, boon-core pod logs) ruled out the remote endpoint --
the request never even reached boon-core -- pointing at the local
Chrome MCP subprocess itself, but its stderr was never captured to
say what actually went wrong.

createRealSession only wired up drainStderr(transport) *after*
client.connect(transport) resolved successfully -- so the one case
this stderr capture exists for (a hung or failing handshake) is
exactly the case where it never engages, silently discarding whatever
the subprocess itself logged.

The MCP SDK's own StdioClientTransport returns its stderr PassThrough
immediately from the constructor, specifically so callers can start
consuming it before the child process spawns (confirmed against
node_modules/@modelcontextprotocol/sdk's stdio.js source and its own
stderr getter docstring). Moving the drain call before connect() is
safe and means a future handshake timeout/failure will actually show
the subprocess's own error instead of a black box.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@convyusboy
convyusboy requested a review from a team September 23, 2026 12:44

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 1 file

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

cubic review feedback on #243: the comment narrated before/after
history and repeated SDK rationale around a one-line call. Reduced to
the invariant and failure consequence.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

@augusteo augusteo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed exact head 21b4aef: no actionable code findings. Moving stderr draining ahead of connect() matches @modelcontextprotocol/sdk 1.29.0, whose piped stderr PassThrough is created before start(). Exact-head CI completed successfully. Local tests were not run; the CI plan excludes the full browser-extension Vitest shard, so the handshake failure path is not directly exercised. No merge or deployment performed.

@convyusboy
convyusboy merged commit db082e4 into boon Sep 25, 2026
139 of 141 checks passed
@convyusboy
convyusboy deleted the ridho/chrome-mcp-stderr-on-handshake-timeout branch September 25, 2026 12:43
convyusboy added a commit that referenced this pull request Sep 28, 2026
…249)

* chore(release): bump version 2026.6.11-boon.46 -> 2026.6.11-boon.47

Root version, 135 plugin manifests synced via scripts/sync-plugin-versions.ts, changed npm-shrinkwrap.json files regenerated, CHANGELOG section for boon.47.

Shipping: #236/#239 (a plugin tool's own execute() handler can now reliably schedule/unschedule a cron-backed session turn, fixing the browser-handoff recheck across three sequential live-found bugs), #240 (recheck backoff cap tightened 5m -> 2m), #242 (recheck messages the customer before attaching the browser), #241 (delivery.mode: "none" cron jobs can deliver an explicit message-tool send), #243 (Chrome MCP stderr drained before connect, not after), #247 (distinct exec-trajectory label for boon-projects schedule append/list), ENG-20030 (shared turn-resume-instruction wording for boon-core/anychat-boon-web), #248 (Docker build no longer OOMs 8 GB CI runners).

Base = 2026.6.11-boon.46. Gateway plus @openclaw/slack, @openclaw/msteams and @openclaw/diagnostics-prometheus bumped in lockstep; no separately published plugin source changed in this train, so a gateway roll delivers all of it.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(release): regenerate stale extension npm-shrinkwrap.json versions for boon.47

pnpm plugins:sync bumps each plugin's package.json version but does not touch its checked-in npm-shrinkwrap.json, so 65 published extension shrinkwraps still embedded version 2026.6.11-boon.46 despite package.json already reading boon.47. Since npm-shrinkwrap.json ships inside the npm artifact, this would have published every affected plugin with a mismatched embedded version.

Bumped the version field(s) in all 65 (plus the openclaw peerDependency range where present) to 2026.6.11-boon.47, matching the pattern boon.46's bump commit already applied to these same files.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
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.

2 participants