Skip to content

fix(browser): retain stderr when Chrome MCP startup fails - #137993

Merged
steipete merged 1 commit into
mainfrom
fix/browser-mcp-startup-stderr-ec0f57
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/browser-mcp-startup-stderr-ec0f57

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators attaching an existing Chrome session could lose the subprocess diagnostic warning when the Chrome MCP initialization handshake failed. The attach error was returned, but startup stderr was missing from the browser/chrome-mcp logs even when the child emitted it.

Why This Change Was Made

Start the existing stderr capture before Client.connect starts the subprocess. MCP SDK 1.30.0 creates the piped stderr stream in the transport constructor and explicitly supports listeners before startup; waiting until initialization succeeds skips capture on initialization failure. The browser plugin's session creator owns this ordering, and both persistent and ephemeral sessions share it.

This relocates the existing capture and removes its empty placeholder and late attachment. Production LOC: +2/-2, net 0; tests: +140/-0; docs: +3/-0. Capturing only in the catch would still miss draining during startup, and a new transport wrapper is unnecessary.

User Impact

Failed startup can now include the available bounded, redacted stderr tail in the existing warning log. The browser troubleshooting page points operators to that log. The 8192-byte UTF-8 tail, redaction, returned attach error, subprocess cleanup, successful tool behavior, and 30000ms handshake deadline are unchanged.

Evidence

The focused regression uses the real SDK Client and StdioClientTransport with a synthetic Node MCP child through the production lease flow; only logger output is mocked. With identical test source, the original production code produced 2 failures / 2 passes: persistent and ephemeral initialization failures each emitted zero stderr warnings. With capture moved before connect, 4/4 pass, including tool-discovery failure and a successful initialization/list-tools/tool-call control.

Assertions cover warning content, credential and home-path/profile-label redaction, UTF-8 retention, old-prefix eviction, the 8192-byte bound, stdin EOF, child-process exit, and no cached MCP PID. The successful persistent session remains usable until explicitly closed.

Owner and sibling coverage: 139/139 tests in 5 files pass in the original shared-worker order with --isolate=false --maxWorkers=1. The selected changed gate passes, including 5 doctor-contract tests, production/test typechecks, targeted lint, formatting, boundary guards, and zero runtime import cycles. No build/module/packaging boundary changes are involved.

Commands run from the repository root (Node 24.20.0, pnpm 12.1.0):

node scripts/run-vitest.mjs extensions/browser/src/browser/chrome-mcp-connect.test.ts
node scripts/run-vitest.mjs extensions/browser/src/browser/chrome-mcp-connect.test.ts extensions/browser/src/browser/chrome-mcp.test.ts extensions/browser/src/browser/chrome-mcp.ownership.test.ts extensions/browser/src/browser/chrome-mcp.snapshot.test.ts extensions/browser/src/browser/bounded-utf8-tail.test.ts --isolate=false --maxWorkers=1
node scripts/check-changed.mjs --base 3b710e4b75c94675a0e1f1b1c31754635c08a1a6 -- extensions/browser/src/browser/chrome-mcp-connect.ts extensions/browser/src/browser/chrome-mcp-connect.test.ts docs/tools/browser.md
git diff --check

The first command was run before and after the production correction. An earlier fixture-only home-directory mismatch was corrected before the accepted failing-before run and is excluded from the regression evidence. Fresh independent Codex pre-commit review reports scoped-clean at its selected P0 scope with no findings; the maintainer also reviewed the owner boundary, dependency contract, and proof.

Exact-head pull-request CI run 33845809427 passed on attempt 1 at 85b84acf4611812cc133a93195b26421f43c3dc6: 80 successful jobs, 16 intentional skips, and no failures. The required openclaw/ci-gate passed. Automatic Chromium UI E2E was skipped by CI classification; the separate exact-head real Chromium run below supplies that coverage.

Native review artifacts validated with zero findings. OPENCLAW_TESTBOX=1 scripts/pr prepare-run 137993 passed using exact-head hosted evidence and prepared the same SHA, without a rebase or additional push. Workflow Sanity also passed.

CI context: the earlier Chromium bootstrap failure timed out on existing-session /tabs after native registration, auto-pairing, and doctor checks passed. Its connection source was also present unchanged in its raw parent and this task's base; the native-review main baseline a550b3f7a1c3611c574f3c073ef2268de74b1a23 retains the same ordering. This PR repairs missing diagnostics; it does not establish or fix that timeout's cause, or distinguish npm provisioning from protocol startup. The diagnostic regression uses a synthetic child with the real SDK; the separate real Chromium run verifies the ordinary native/attach flow. Introduction provenance remains unknown; the known extraction carried the ordering forward.

Real Chromium proof: corrected CI-setup run 33847930752, on a fresh Blacksmith Testbox lease at the same head, passed 1/1 with zero skips in one scenario attempt. Native registration, MCP attach, labeled screenshots, reconnect, navigation recovery, launcher probes, revocation, version checks, and unpairing passed with the existing assertions and 120s E2E/30s handshake deadlines unchanged. Both synthetic screenshots were inspected and remain local.

The first manual run 33846819421 failed on existing-session /tabs with the 30s handshake timeout after omitting the existing CI project npm cache/offline setup. It is retained as a non-CI-parity rig failure, not evidence that this patch introduced a regression. The corrected run used the setup already owned by ci.yml:2532-2556, which keeps the warmed cache reachable when MCP filters npm environment settings and Vitest changes HOME:

npx -y [email protected] --version
npm config set cache="$HOME/.npm" offline=true --location=project
pnpm test:e2e:browser-extension

This was temporary remote test provisioning, not a source fix: original .npmrc bytes were restored, all 20 source hashes and the complete tracked tree matched before setup and after restoration, both owned leases are stopped, and no fixture roots remain. Neither this PASS nor the first manual FAIL establishes the original CI timeout cause or means the diagnostic relocation fixes it.

Disposition of all three before-merge items in the fresh ClawSweeper review:

  • P1 independent contract verification: completed by direct maintainer inspection of installed SDK 1.30.0 and byte comparison against its version-pinned published stdio.js. Constructor lines 49-55 allocate PassThrough; start lines 103-105 pipe child stderr into that same stream; getter lines 108-119 explicitly allow “attach listeners before the start method is invoked.”
  • P2 direct SDK inspection: completed, including stdio.d.ts:66-73 and Client.connect:274-316, which starts transport, initializes, and closes on initialize error. Package version independently verified as 1.30.0.
  • Review confidence: the reviewer-side source/network availability gap is resolved by direct dependency inspection, failing/passing real-SDK subprocess evidence, exact-head green CI, and the corrected real Chromium PASS. No introduced correctness/security finding or new source repair is required. The reviewed head is unchanged and the review is fresh; no re-review request or wait for a bot rating refresh is needed. Live GitHub rules impose no independent approval requirement.

The Chromium test command exited 0. The linked Testbox Actions host job shows cancelled after lease shutdown; its Run Testbox holding step was cancelled and cleanup steps succeeded. This is the documented Testbox lifecycle result, distinct from the passing test command and the green required CI workflow.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: browser size: S maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete steipete self-assigned this Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 06:47
@steipete

steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Prepared and approved source remains 85b84acf4611812cc133a93195b26421f43c3dc6. Native review validation and OPENCLAW_TESTBOX=1 scripts/pr prepare-run 137993 passed without a rebase or additional push. CI 33845809427 passed attempt 1 (80 successful jobs, 16 skips), including openclaw/ci-gate.

The identical real-SDK/synthetic-child regression changed from 2 failures / 2 passes to 4/4 passing; owner/sibling coverage passed 139/139. Redaction, bounded UTF-8 stderr, successful tool calls and child/cache cleanup are verified. Production +2/-2 (net 0); tests +140; docs +3. Exact local regression and changed-gate commands remain in the PR body.

New ordinary-flow proof: real Chromium run 33847930752 passed 1/1, zero skips, one scenario attempt at the same head on fresh Blacksmith Testbox. Native registration, MCP attach, screenshots, reconnect, navigation recovery, launcher probes, revocation/version checks and unpairing passed. Existing assertions and 120s/30s deadlines were unchanged. The first manual run 33846819421 omitted existing CI project cache/offline setup and failed /tabs; its evidence is retained as a non-CI-parity rig failure. Corrected setup matches ci.yml:2532-2556:

npx -y [email protected] --version
npm config set cache="$HOME/.npm" offline=true --location=project
pnpm test:e2e:browser-extension

Temporary remote .npmrc provisioning was restored byte-for-byte, not committed as a fix. All 20 source hashes and the complete tracked tree match after restoration. Both screenshots were inspected; both leases are stopped and no fixture roots remain.

All three items from the fresh ClawSweeper review are addressed: P1 independent verification and P2 SDK inspection are complete. Installed package version is 1.30.0; its stdio.js byte-matches the version-pinned published source. Constructor 49-55 creates the PassThrough; start 103-105 pipes child stderr into it; getter 108-119 documents pre-start listeners. stdio.d.ts:66-73 confirms that contract; Client.connect:274-316 initializes and closes on error. Reviewer confidence gap: resolved by that direct maintainer inspection plus real-SDK, exact-head CI and real Chromium proof. No new source repair is needed. With the head unchanged and review fresh, no re-review request or wait for publisher refresh is needed; no GitHub-enforced approval rule is bypassed.

Neither the corrected PASS nor the first manual FAIL establishes the cause of the original Chromium CI timeout, or shows that relocating diagnostic capture fixes it.

The Chromium test command exited 0. The linked Testbox Actions host job shows cancelled after lease shutdown; its Run Testbox holding step was cancelled and cleanup steps succeeded. This is the documented Testbox lifecycle result, distinct from the passing test command and the green required CI workflow.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 3:10 AM ET / 07:10 UTC.

ClawSweeper review

What this changes

The browser plugin captures Chrome MCP subprocess stderr before initialization, adds startup and cleanup regression coverage, and documents the diagnostic log.

Merge readiness

⛔ Blocked before merge - 3 items remain

This remains a useful, focused correction absent from fetched main. No introduced correctness or security defect was found in the inspected source; direct dependency-contract verification remains incomplete.

Priority: P2
Reviewed head: 85b84acf4611812cc133a93195b26421f43c3dc6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-neutral repair with relevant subprocess evidence; the reviewer-side dependency inspection gap does not diminish the submitted proof.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The captured before/after execution reports exercise the production lease/startup owner with the real SDK transport and a synthetic Node subprocess: initialization failures gain redacted stderr warnings, tool use remains functional, and children/cache entries are cleaned up. This supports the diagnostic correction without claiming real-Chrome or provisioning coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured before/after execution reports exercise the production lease/startup owner with the real SDK transport and a synthetic Node subprocess: initialization failures gain redacted stderr warnings, tool use remains functional, and children/cache entries are cleaned up. This supports the diagnostic correction without claiming real-Chrome or provisioning coverage.
Evidence reviewed 11 items Verified introduced change: The pinned merge-base-to-head diff moves the existing collector before initialization; it introduces no transport wrapper, dependency change, or startup policy change.
Current-main defect remains: Fetched main initializes getStderr to an empty reader and replaces it only after client.connect resolves. Initialization rejection therefore reaches the catch block without the emitted stderr diagnostic.
Caller, owner, and sibling coverage: Availability probes and tab listing enter the lease flow; persistent pending sessions and ephemeral sessions both use createChromeMcpSession. Their existing failure paths close the tracked session. Managed Chrome uses its own early stderr listener and the same bounded-tail utility.
Findings None None.
Security None None.

How this fits together

The browser plugin uses a Chrome MCP subprocess to connect browser requests to an existing Chrome session. Its session startup owner handles initialization, diagnostic logging, and cleanup when attachment fails.

flowchart TD
  A[Browser requests] --> B[Shared session startup]
  B --> C[Bounded stderr capture]
  C --> D[MCP initialization]
  D -->|Success| E[Browser operations]
  D -->|Failure| F[Redacted diagnostics]
  C --> F
  F --> G[Cleanup and attach error]
Loading

Before merge

  • Resolve merge risk (P1) - The SDK's pre-start stderr-stream contract remains independently unverified because dependency source and network inspection were unavailable to this reviewer.
  • Complete next step (P2) - Complete direct inspection of MCP SDK 1.30.0 to confirm that piped stderr is available before connect and remains the stream used during startup.
  • Resolve review confidence - ClawSweeper must reach high confidence before merge readiness is known.
Agent review details

Security

None.

PR surface

Source 0, Tests +140, Docs +3. Total +143 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 1 140 0 +140
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 145 2 +143

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net 0 (+2/-2); tests +140; docs +3 The repair relocates existing behavior without production growth; added tests exercise startup through a real subprocess boundary.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one bounded, redacted diagnostic flow owned by session creation and shared by persistent and ephemeral attachments, without adding a transport wrapper or changing startup policy.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one bounded, redacted diagnostic flow owned by session creation and shared by persistent and ephemeral attachments, without adding a transport wrapper or changing startup policy.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: reject initialization after the subprocess emits stderr, and current main's empty reader suppresses the warning. The supplied before/after run corroborates this; this read-only review did not execute tests.

Is this the best way to solve the issue?

Unclear pending direct SDK-contract verification: within OpenClaw, moving the existing collector into shared session startup is the appropriate repair and avoids a redundant wrapper or catch-only workaround.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 69a0aa25c778.

Labels

Label changes:

  • add P2: Restoring diagnostics for failed browser attachment is a bounded operational improvement; the attach error already reaches the caller.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after execution reports exercise the production lease/startup owner with the real SDK transport and a synthetic Node subprocess: initialization failures gain redacted stderr warnings, tool use remains functional, and children/cache entries are cleaned up. This supports the diagnostic correction without claiming real-Chrome or provisioning coverage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The captured before/after execution reports exercise the production lease/startup owner with the real SDK transport and a synthetic Node subprocess: initialization failures gain redacted stderr warnings, tool use remains functional, and children/cache entries are cleaned up. This supports the diagnostic correction without claiming real-Chrome or provisioning coverage.

Label justifications:

  • P2: Restoring diagnostics for failed browser attachment is a bounded operational improvement; the attach error already reaches the caller.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The captured before/after execution reports exercise the production lease/startup owner with the real SDK transport and a synthetic Node subprocess: initialization failures gain redacted stderr warnings, tool use remains functional, and children/cache entries are cleaned up. This supports the diagnostic correction without claiming real-Chrome or provisioning coverage.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after execution reports exercise the production lease/startup owner with the real SDK transport and a synthetic Node subprocess: initialization failures gain redacted stderr warnings, tool use remains functional, and children/cache entries are cleaned up. This supports the diagnostic correction without claiming real-Chrome or provisioning coverage.

Evidence

What I checked:

  • Verified introduced change: The pinned merge-base-to-head diff moves the existing collector before initialization; it introduces no transport wrapper, dependency change, or startup policy change. (extensions/browser/src/browser/chrome-mcp-connect.ts:65, 85b84acf4611)
  • Current-main defect remains: Fetched main initializes getStderr to an empty reader and replaces it only after client.connect resolves. Initialization rejection therefore reaches the catch block without the emitted stderr diagnostic. (extensions/browser/src/browser/chrome-mcp-connect.ts:64, 69a0aa25c778)
  • Caller, owner, and sibling coverage: Availability probes and tab listing enter the lease flow; persistent pending sessions and ephemeral sessions both use createChromeMcpSession. Their existing failure paths close the tracked session. Managed Chrome uses its own early stderr listener and the same bounded-tail utility. (extensions/browser/src/browser/chrome-mcp-session.ts, 85b84acf4611)
  • Production-boundary regression: The new regression invokes the production lease owner with the real SDK and a spawned Node MCP child. It covers persistent and ephemeral initialization failure, tool-discovery failure, successful tool use, warning redaction, byte bounds, stdin closure, process exit, and cached-PID removal; only the logger is mocked. (extensions/browser/src/browser/chrome-mcp-connect.test.ts:90, 85b84acf4611)
  • Captured execution evidence: The supplied complete PR body and fix(browser): retain stderr when Chrome MCP startup fails #137993 (comment) report identical regression source changing from two failures/two passes to four passes, plus 139 passing owner/sibling tests in shared-worker order. Node 24.20.0 and pnpm 12.1.0 are identified. This proves the diagnostic scenario claimed, not the separate Chrome timeout or default npx provisioning. (85b84acf4611)
  • Security safeguards retained: The existing collector retains at most 8192 bytes. Warning output still passes through home-path and CDP credential redaction; shared tool-payload redaction forces redaction even when logging redaction is configured off. No authority, permissions, package sources, or execution commands change. (extensions/browser/src/browser/chrome-mcp-diagnostics.ts:13, 85b84acf4611)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 090549d into main Sep 4, 2026
231 of 234 checks passed
@steipete
steipete deleted the fix/browser-mcp-startup-stderr-ec0f57 branch September 4, 2026 07:33
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 4, 2026
Extend the real-child fixture from #137993 with quiet and 2 MiB startup
stderr cases. Gate the initialize response on the write callback while
retaining actual tool-call and EOF/PID cleanup assertions.

The runtime fix remains owned by #137993; this change is test-only.
Verified an intended pre-drain RED, identical GREEN, 140 owner/sibling
tests, all 19 changed checks, and an independent code review.
steipete added a commit that referenced this pull request Sep 4, 2026
Extend the real-child fixture from #137993 with quiet and 2 MiB startup
stderr cases. Gate the initialize response on the write callback while
retaining actual tool-call and EOF/PID cleanup assertions.

The runtime fix remains owned by #137993; this change is test-only.
Verified an intended pre-drain RED, identical GREEN, 140 owner/sibling
tests, all 19 changed checks, and an independent code review.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…#138022)

Extend the real-child fixture from openclaw#137993 with quiet and 2 MiB startup
stderr cases. Gate the initialize response on the write callback while
retaining actual tool-call and EOF/PID cleanup assertions.

The runtime fix remains owned by openclaw#137993; this change is test-only.
Verified an intended pre-drain RED, identical GREEN, 140 owner/sibling
tests, all 19 changed checks, and an independent code review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: browser maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant