Skip to content

fix(browser): let attached workers exit after CDP use - #122103

Merged
steipete merged 3 commits into
openclaw:mainfrom
vatsalgargg:fix/attached-browser-cdp-adapter-retirement
Aug 11, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
vatsalgargg:fix/attached-browser-cdp-adapter-retirement

Conversation

@vatsalgargg

@vatsalgargg vatsalgargg commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #122065

What Problem This Solves

Fixes an issue where a completed one-shot worker could remain alive after Browser/CDP use because attached-runtime disposal stopped the HTTP bridge but retained the Playwright WebSocket adapter in process-global state.

Why This Change Was Made

The attached Browser runtime owns one exact CDP adapter but does not own caller Chrome. Its disposer now stops bridge ingress and drains admitted work first, then uses the existing exact scoped close facade for that canonical cdpUrl.

Every disposal attempt creates a fresh exact retirement. If disconnect fails, the existing retained-closing map keeps the handle available and a later dispose() retries it. Generic bridge shutdown continues preserving shared adapters, and no global cleanup or forced process exit is added.

User Impact

One-shot workers can finish naturally after Browser actions without leaking a Playwright transport, while caller-owned Chrome remains running and reusable.

Evidence

  • Current-main source reproduction: attached-runtime disposal called only stopBrowserBridgeServer; generic bridge shutdown deliberately uses closeSharedAdapters: false, while worker terminal cleanup awaits that disposer and relies on natural event-loop exit.
  • Installed Playwright 1.62.0 types document that browser.close() for a connected browser clears client-created contexts and disconnects from the browser server rather than terminating the existing browser.
  • Existing exact-retirement coverage proves scoped close waits for in-flight connection attempts and a fresh second close retries a failed disconnect.
  • Maintainer follow-up 9fc22f34663f9576147dfe612b52a5954e9161b6 removes retained local retirement state and changes the runtime retry test to fail once, then succeed on the next disposal.
  • Canonical oxfmt, git diff --check, direct Playwright source/type inspection, mandatory Codex autoreview, and TruffleHog are clean on the combined branch.
  • Production delta: +10/-2 (net +8); tests: +39/-2 (net +37).
  • Real worker/CDP proof passed on sanitized direct AWS Crabbox: provider aws, lease cbx_6b415a755e55, run https://crabbox.openclaw.ai/portal/runs/run_5adbef33943b. A fresh checkout of patch-identical pre-rebase head a2d21b2c1a34faca7aba512d1e9aa6ff3ffa88fd used a disposable Chrome and the actual attached Browser tool. Observed: tabActionCompleted, original adapter disconnected, fresh adapter created, caller Chrome alive, and NATURAL_NODE_EXIT=1. The public/no-Tailscale/no-instance-profile lease was stopped after proof; rebased head 9fc22f34663f9576147dfe612b52a5954e9161b6 preserves the same two-file patch.
  • Current exact-head CI is pending and remains the final merge gate.

AI-assisted maintainer follow-up; no agent transcript attached.

@clawsweeper

clawsweeper Bot commented Aug 11, 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 extensions: browser size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 11, 2026
@vatsalgargg vatsalgargg changed the title fix(browser): retire attached runtime Playwright CDP adapter on disposal (#122065) fix(browser): retire attached runtime Playwright CDP adapter on disposal (#122065) [AI-assisted] Aug 11, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 11, 2026
@vatsalgargg vatsalgargg changed the title fix(browser): retire attached runtime Playwright CDP adapter on disposal (#122065) [AI-assisted] fix(browser): retire attached runtime Playwright CDP adapter on disposal (#122065) Aug 11, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 4:11 PM ET / 20:11 UTC.

ClawSweeper review

What this changes

The PR makes attached Browser workers close their own Playwright CDP client after bridge shutdown so one-shot workers can exit without stopping caller-owned Chrome.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: current main still leaves the attached worker’s CDP client alive, while this PR adds the narrow scoped cleanup. No blocking patch defect found; exact-head CI remains the merge gate.

Priority: P1
Reviewed head: a2d21b2c1a34faca7aba512d1e9aa6ff3ffa88fd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A narrow owner-boundary repair with focused coverage and credible real behavior proof; required exact-head CI remains the final gate.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The PR body records an exact-head sanitized direct AWS Crabbox run using the real attached Browser tool, observing adapter retirement, caller Chrome survival, reconnection, and natural Node exit.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR body records an exact-head sanitized direct AWS Crabbox run using the real attached Browser tool, observing adapter retirement, caller Chrome survival, reconnection, and natural Node exit.
Evidence reviewed 7 items Current-main defect: Current main returns a disposer that stops only the bridge, leaving the CDP adapter outside attached-runtime cleanup.
Scoped repair: The PR drains bridge shutdown first and always invokes the existing URL-scoped CDP retirement facade, including construction failure cleanup.
Worker lifecycle caller: The worker creates this attached runtime through the plugin’s public runtime surface and awaits disposal in its terminal finally block.
Findings None None.
Security None None.

How this fits together

The Browser plugin gives a one-shot worker an authenticated local bridge to caller-owned Chrome through CDP. Worker teardown must drain bridge work, release only that worker’s CDP client, and then allow the Node process to exit.

flowchart LR
A[One-shot worker] --> B[Attached Browser runtime]
B --> C[Authenticated Browser bridge]
C --> D[Browser action over CDP]
D --> E[Scoped CDP client]
B --> F[Worker disposal]
F --> G[Drain bridge work]
G --> H[Close exact CDP client]
H --> I[Natural worker exit]
Loading

Before merge

  • Resolve merge risk (P1) - This availability-sensitive teardown path should not merge until required CI completes green on the exact head.
  • Resolve merge risk (P1) - The patch is production net +8 lines; that growth is justified because one local disposer keeps normal and construction-failure cleanup on the same canonical sequence.
  • Resolve merge risk (P1) - The installed Playwright source/types were unavailable in this read-only checkout, so caller-Chrome preservation is supported here by the recorded real Crabbox result rather than a local upstream-type reread.
  • Complete next step (P2) - No actionable patch defect was found; await the existing exact-head CI gate rather than dispatching a repair.
Agent review details

Security

None.

PR surface

Source +8, Tests +37. Total +45 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 2 +8
Tests 1 39 2 +37
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 49 4 +45

Review metrics

Metric Value Why it matters
Production vs test LOC production +10/-2 (net +8); tests +39/-2 (net +37) The production growth is the single canonical teardown sequence; the tests add focused disposal and retry coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #122065
Summary: This PR is the candidate fix for the linked attached-worker CDP lifecycle bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Complete exact-head validation (recommended)
    Keep the scoped-disposal implementation and merge only after required CI completes green for the current head.
  2. Pause if lifecycle validation regresses
    If exact-head CI exposes a worker-exit or Browser lifecycle failure, pause this PR and repair that concrete path before merging.

Technical review

Best possible solution:

Keep the local disposal helper that drains the bridge and closes only the exact CDP client, then land after exact-head CI is green.

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

Yes. Current main’s disposer stops only the bridge, while worker terminal cleanup awaits that disposer; the PR body also records an after-fix real worker/CDP run.

Is this the best way to solve the issue?

Yes. The existing exact URL-scoped retirement primitive fixes the owner boundary without changing generic bridge behavior or sweeping other adapters.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 09c39e0ec528.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body records an exact-head sanitized direct AWS Crabbox run using the real attached Browser tool, observing adapter retirement, caller Chrome survival, reconnection, and natural Node exit.
  • 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 (linked_artifact): The PR body records an exact-head sanitized direct AWS Crabbox run using the real attached Browser tool, observing adapter retirement, caller Chrome survival, reconnection, and natural Node exit.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: A one-shot worker can remain alive after completing Browser work, delaying completion handling.
  • merge-risk: 🚨 availability: The change alters worker teardown and process-liveness behavior, so exact-head validation is required before merge.
  • 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 (linked_artifact): The PR body records an exact-head sanitized direct AWS Crabbox run using the real attached Browser tool, observing adapter retirement, caller Chrome survival, reconnection, and natural Node exit.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records an exact-head sanitized direct AWS Crabbox run using the real attached Browser tool, observing adapter retirement, caller Chrome survival, reconnection, and natural Node exit.

Evidence

What I checked:

Likely related people:

  • steipete: Current main attributes the attached-runtime lifecycle to Peter Steinberger, who also authored the PR’s final disposal simplification. (role: feature and lifecycle owner; confidence: high; commits: b5d5ec340fe7, 76ab9a751a12, a2d21b2c1a34; files: extensions/browser/src/attached-browser-tool-runtime.ts, extensions/browser/src/browser/pw-session-connection.ts, src/worker/embedded-agent.runtime.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for required CI to finish green on the exact PR head.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-11T15:51:16.966Z sha 82cfcfe2de0576ecda18c3fdf871bf7b76bba8ea :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-11T19:54:29.121Z sha a2d21b2c1a34faca7aba512d1e9aa6ff3ffa88fd :: needs real behavior proof before merge. :: none

@steipete steipete self-assigned this Aug 11, 2026
@steipete steipete changed the title fix(browser): retire attached runtime Playwright CDP adapter on disposal (#122065) fix(browser): let attached workers exit after CDP use Aug 11, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Aug 11, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

The current head now includes a stateless exact-retirement simplification and real fresh-PR AWS Browser proof. The PR body records the run, adapter disconnect, fresh reconnect, caller Chrome survival, natural Node exit, isolation checks, and lease cleanup. Exact-head CI is still running.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 11, 2026
@steipete
steipete force-pushed the fix/attached-browser-cdp-adapter-retirement branch from a2d21b2 to 9fc22f3 Compare August 11, 2026 20:20
@steipete

Copy link
Copy Markdown
Contributor

Land-ready verification for 9fc22f34663f9576147dfe612b52a5954e9161b6:

  • Accepted the attached-runtime owner repair: bridge ingress drains first, then one exact Playwright CDP client disconnects; generic bridge shared-adapter behavior and caller-owned Chrome remain unchanged.
  • Maintainer rewrite removed unnecessary retained retirement state, reducing production growth from net +19 to net +8. Retry coverage now fails one disconnect and proves a later disposal succeeds.
  • Installed Playwright 1.62.0 types confirm closing a connected Browser disconnects the client from the browser server rather than terminating the existing browser.
  • Real behavior proof passed on sanitized direct AWS Crabbox run https://crabbox.openclaw.ai/portal/runs/run_5adbef33943b: actual Browser tabs action, original adapter disconnected, fresh adapter reconnected, caller Chrome remained alive, and NATURAL_NODE_EXIT=1. The public/no-Tailscale/no-instance-profile lease was stopped.
  • Rebased exact-head CI parent https://github.com/openclaw/openclaw/actions/runs/31532460666 completed successfully.
  • Native review artifacts validated with no findings, and OPENCLAW_TESTBOX=1 scripts/pr prepare-run 122103 completed with hosted gates passed.
  • ClawSweeper marks real proof sufficient and has no actionable finding; its exact-head CI rank-up move is satisfied. The final push after that review was a mechanical rebase preserving the same two-file patch.

@steipete
steipete merged commit a432e2a into openclaw:main Aug 11, 2026
94 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

vincentkoc added a commit to tangtaizong666/openclaw that referenced this pull request Aug 11, 2026
…-prep

* commit 'edb7a1692e58d78ff7e196db39ea8eff297b2e19': (1351 commits)
  fix(telegram): expose live location updates to hooks (openclaw#122185)
  fix(ui): remove the pre-creation session row (openclaw#122259)
  fix(openai): surface failed realtime response outcomes (openclaw#121177)
  fix(logging): publish diagnostics ZIP through staged atomic overwrite (openclaw#122130)
  test(cli): trim duplicate MCP probe process cases (openclaw#122260)
  feat(agents): replay persisted native video (openclaw#122257)
  fix(test): serialize default e2e runner (openclaw#122203)
  fix(ui): always show full assistant responses (openclaw#122207)
  feat(mcp): per-requester OAuth for MCP servers (openclaw#122166)
  fix(ui): preserve focus on composer accessory clicks (openclaw#122243)
  fix(backup): exclude state temp files (openclaw#122250)
  fix(browser): let attached workers exit after CDP use (openclaw#122103)
  test(cli): trim duplicate Claw authoring process cases (openclaw#122248)
  refactor(outbound): inline delivery diagnostics (openclaw#122219)
  refactor: eliminate final wrapper-shadowing hazards (openclaw#122157)
  fix(ui): keep new-session identity anchored (openclaw#122242)
  test(cli): trim duplicate gateway process cases (openclaw#122240)
  fix(media): decode local file URLs safely (openclaw#122192)
  refactor(agents): centralize typed activity event emission (openclaw#122188)
  fix(ui): effort slider matches selected level after model switches (openclaw#122125)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
* fix(browser): retire attached runtime Playwright CDP adapter on disposal (openclaw#122065)

* fix(browser): use optional chaining on refresh in CDP adapter retirement

* refactor(browser): simplify attached adapter disposal

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: browser merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. 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.

Attached Browser worker does not retire its Playwright CDP adapter

2 participants