Skip to content

fix(browser): preserve contextless worker and iframe sessions - #133571

Merged
steipete merged 1 commit into
mainfrom
steipete/trusting-lamport-059058
Aug 30, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/trusting-lamport-059058

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #133569

Related: #132419 — root contextless-target crash protection.

Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers can help update the branch when needed.

What Problem This Solves

Fixes an issue where browser automation loses nested workers and out-of-process iframes when their CDP attachment event has a parent session but omits browserContextId. Playwright never receives those events because the managed transport incorrectly treats them as browser-root targets.

This is a pre-existing main defect, not a regression introduced by the standalone relay feature. The affected modules remain unchanged on main 00b64b81c4073e594c423bcb5e7a5ca1c5a6f6d7.

Why This Change Was Made

Only Playwright's browser-root attachment handler requires browserContextId. The outer envelope sessionId selects the parent session; params.sessionId identifies the attached child. Add that missing discriminator to the existing predicate so every parent-routed attachment passes through unchanged, while the root-only protection remains intact.

Root contextless targets still resume, wait for the resume response, and then detach. DNS pinning, endpoint discovery, internal reply suppression, and connection/event cleanup are unchanged. No new configuration, dependencies, compatibility path, public API, or test-only production seam.

User Impact

Playwright retains ownership of nested worker and iframe sessions even when the optional context field is absent. Existing protection against contextless root targets terminating the Gateway is preserved.

Evidence

Before and after

The regression uses the actual managed WebSocket transport through listPagesViaPlaywright, with a mock only at the Playwright consumer boundary. Before the production edit, all four nested worker/iframe envelopes (paused and unpaused) were missing; one test failed and the other six passed. After repair, all seven transport tests pass. The test also proves nine root resumes, no detach before a resume response, exactly one detach per resumed root session, unchanged forwarded envelopes, and no leaked internal replies or extra commands after socket closure.

node scripts/run-vitest.mjs extensions/browser/src/browser/pw-session.pinned-transport.test.ts

The final sibling run passed 96/96 tests across six files, covering pinning, cross-authority redirect rejection, connection retirement/cancellation, scoped cleanup, enumeration, and event-before-close delivery:

node scripts/run-vitest.mjs extensions/browser/src/browser/pw-session.pinned-transport.test.ts extensions/browser/src/browser/pw-session.connections.test.ts extensions/browser/src/browser/pw-session.enumeration.test.ts extensions/browser/src/browser/pw-session.termination-cdp-ssrf.test.ts extensions/browser/src/browser/cdp.helpers.internal.test.ts extensions/browser/src/browser/cdp.helpers.transport.test.ts

The complete changed-scope gate passed, including production/test typechecks, lint, formatting, five doctor-contract tests, export scans, boundary guards, and zero runtime import cycles:

node scripts/check-changed.mjs -- extensions/browser/src/browser/pw-session-cdp-transport.ts extensions/browser/src/browser/pw-session.pinned-transport.test.ts

Fresh Codex autoreview completed scoped-clean with no P0 findings. An initial test-fixture conditional-spread lint finding was fixed and the full gate rerun successfully.

Real dependency and browser proof

Personally inspected installed Playwright 1.62.1: lib/coreBundle.js:34732–34738 routes on the outer session ID; 37547–37599 handles nested worker/iframe attachments; 38166–38201 requires the context field only in the root handler.

A disposable, isolated Chrome for Testing 151.0.7922.34 and real Playwright exercised the actual repaired transport. Ordinary traffic passed worker evaluation (42), worker-to-page messaging, cross-site OOPIF content/evaluation (63), and positive Playwright-owned initialization/resume commands. Chromium naturally included context IDs, so a second explicitly fault-injected leg removed only targetInfo.browserContextId from nested worker/iframe events. It passed the same assertions without transport-owned resume/detach commands. Every other envelope field and text framing were preserved.

Scratch-fixture framing and startup-budget failures were corrected before the successful run; they were not product failures. The browser, WebSockets, ephemeral ports, and temporary profile were cleaned up. No operator Chrome/Gateway or parked relay work was used. This is dependency/transport proof, not a Gateway or extension-relay end-to-end claim; no UI or visual layout changes are included.

Scope and size

Production: +3/-2, net +1. The one added line is the session-ownership discriminator within the existing predicate. Tests: +39/-13, net +26, extending the existing table and making assertion failure/cleanup reliable rather than adding another fixture.

Release-note context: Browser automation now preserves nested worker and iframe CDP sessions that omit a browser context ID while retaining safe release of contextless root targets.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 30, 2026 21:45
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 5:51 PM ET / 21:51 UTC.

ClawSweeper review

What this changes

The PR forwards contextless worker and iframe CDP attachments with an outer parent session to Playwright while retaining safe release of contextless browser-root targets.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this active: it is the linked maintainer-authored repair for a current browser-transport defect, and the introduced predicate plus boundary regression are coherent. No blocking patch defect surfaced; exact-head CI is still in progress.

Priority: P2
Reviewed head: a2d28d32c9ac798b0f0cd4b75ea5126e4f44200b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary fix with meaningful transport regression coverage; independent upstream-source inspection is the remaining reviewer-environment limitation.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its supplied body nevertheless describes an after-fix real-Chrome and Playwright transport run consistent with the changed owner boundary.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its supplied body nevertheless describes an after-fix real-Chrome and Playwright transport run consistent with the changed owner boundary.
Evidence reviewed 7 items Introduced ownership discriminator: The PR adds the outer session-ID check at the transport’s classification point, so parent-routed attachments bypass the root-target release branch and are forwarded through the existing message scheduler.
Current-main behavior remains affected: The fetched main revision lacks the outer session-ID condition, so a contextless nested attachment reaches the transport-owned resume/detach path.
Caller and user-facing entry point: Browser page enumeration connects through this managed transport, so the classification governs the Playwright connection used by browser automation.
Findings None None.
Security None None.

How this fits together

OpenClaw’s browser plugin connects to Chrome through a managed CDP WebSocket transport before handing events to Playwright. The transport must release unsupported contextless root targets but preserve nested session events for Playwright to manage.

flowchart LR
  A[Chrome CDP attachment] --> B[Managed browser transport]
  B --> C{Outer parent session?}
  C -->|Yes| D[Playwright nested session]
  C -->|No| E{Contextless root target?}
  E -->|Yes| F[Resume then detach]
  E -->|No| G[Playwright browser handler]
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head CI is still in progress, so this review is not a landing-ready result.
  • Resolve merge risk (P1) - Independent inspection of Playwright’s bundled handler was unavailable in this read-only checkout; the precise upstream and real-browser evidence in the PR body remains the dependency-contract corroboration.
  • Complete next step (P2) - An open maintainer PR already owns this bounded repair; wait for its exact-head checks and ordinary landing review rather than creating a competing fix job.
Agent review details

Security

None.

PR surface

Source +1, Tests +26. Total +27 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 2 +1
Tests 1 39 13 +26
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 42 15 +27

Review metrics

Metric Value Why it matters
Production versus regression-test LOC production +3/-2 (net +1); tests +39/-13 (net +26) The sole net production line is the necessary parent-session discriminator inside the existing owner predicate; the test growth exercises the lost nested-event cases and existing cleanup invariant.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #133569
Summary: This PR directly implements the linked issue’s requested correction to nested contextless attachment routing.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the narrow transport-owner distinction after exact-head checks complete, preserving root-target protection while leaving parent-routed sessions to Playwright.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the narrow transport-owner distinction after exact-head checks complete, preserving root-target protection while leaving parent-routed sessions to Playwright.

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

Yes—source-reproducible with high confidence: current main’s predicate releases a contextless attachment based only on target information, while the focused WebSocket scenario supplies an outer parent session and observes the lost event path.

Is this the best way to solve the issue?

Yes. The outer session ID is the narrow ownership discriminator at the transport boundary; a target-type allowlist would miss valid siblings, while removing root release would undo the existing crash protection.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 786b19ebfbb5.

Labels

Label changes:

  • add P2: This repairs a bounded browser-automation session-routing defect without evidence of a current crash or broader availability failure.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its supplied body nevertheless describes an after-fix real-Chrome and Playwright transport run consistent with the changed owner boundary.

Label justifications:

  • P2: This repairs a bounded browser-automation session-routing defect without evidence of a current crash or broader availability failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its supplied body nevertheless describes an after-fix real-Chrome and Playwright transport run consistent with the changed owner boundary.

Evidence

What I checked:

Likely related people:

  • obviyus: 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 self-assigned this Aug 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready verification for a2d28d32c9ac798b0f0cd4b75ea5126e4f44200b: exact-head CI run 33337277959 succeeded, the required openclaw/ci-gate is green, and native review artifacts validated for this head.

All items in the latest ClawSweeper review are addressed:

  • Exact-head CI has completed successfully.
  • Independent direct inspection of installed Playwright 1.62.1 is complete: lib/coreBundle.js:34732–34738 routes messages by the outer session ID; 37547–37599 initializes and owns nested workers/iframes without requiring a browser context ID; 38166–38201 applies the context assertion in the root handler. types/protocol.d.ts:18792–18825 declares the context ID optional. The real Chromium/Playwright ordinary and explicitly fault-injected runs in the PR body corroborate that contract.
  • Maintainer source review is complete on this existing repair PR; no competing fix or relay rewrite was created. No patch/security finding or separate Rank-up moves list was present.

The transport owns root-target interception; Playwright owns parent-routed child sessions. The existing predicate is the right repair point, not a type allowlist or downstream workaround. Root resume-response-before-detach, internal reply suppression, DNS pinning and lifecycle cleanup remain intact. No old path was retained or added. Production is +3/-2 (net +1); tests are +39/-13 (net +26).

Local proof: the new four nested-event cases failed before the repair; the final 96/96 sibling tests and complete changed-scope gate passed:

node scripts/run-vitest.mjs extensions/browser/src/browser/pw-session.pinned-transport.test.ts extensions/browser/src/browser/pw-session.connections.test.ts extensions/browser/src/browser/pw-session.enumeration.test.ts extensions/browser/src/browser/pw-session.termination-cdp-ssrf.test.ts extensions/browser/src/browser/cdp.helpers.internal.test.ts extensions/browser/src/browser/cdp.helpers.transport.test.ts
node scripts/check-changed.mjs -- extensions/browser/src/browser/pw-session-cdp-transport.ts extensions/browser/src/browser/pw-session.pinned-transport.test.ts

Fresh Codex autoreview was scoped-clean with no P0 findings. Real isolated Chromium 151.0.7922.34 retained worker evaluation/messaging and OOPIF evaluation in both protocol legs; owned resources were cleaned up. The absence of context IDs was deliberately injected because this Chromium naturally included them. No Gateway/extension-relay E2E or stable-release incidence is claimed. Initial scratch-fixture framing/startup failures and the test-fixture lint issue were corrected before the successful final runs.

Proceeding through the native hosted-CI prepare/merge flow; this closes the nested-attachment bug in #133569.

@steipete
steipete merged commit 214deeb into main Aug 30, 2026
171 checks passed
@steipete
steipete deleted the steipete/trusting-lamport-059058 branch August 30, 2026 22:06
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 30, 2026
* origin/main: (55 commits)
  test: include v2026.8.1 release navigation (#133581)
  fix: stop cloud work before unrelated provider inspection finishes (#133476)
  fix(e2e): keep delete fixture target-compatible (#133526)
  fix(release): detect optional target E2E capability (#133525)
  fix(package): publish readable dist inventory (#133549)
  docs: add complete v2026.8.1 maintainer change index (#133585)
  fix(browser): preserve contextless worker and iframe sessions (#133571)
  fix(voice): discover configured provider candidates (#133507)
  refactor(ui): simplify chat rendering and lifecycle state (#133567)
  test: reduce maturity fixture cleanup time (#133566)
  improve: speed up legacy imports and transcript replacement (#133546)
  docs: add draft v2026.8.1 release notes (#133557)
  test: guard multi-project Vitest cache ownership (#133554)
  fix(memory): clarify default agent scope in command help (#133560)
  fix(clawdock): keep credentials out of diagnostic output (#133547)
  refactor(ui): avoid redundant presence work in avatar lists (#133548)
  fix(agents): recognize internal requester completion replies (#133543)
  fix: prevent duplicate queued user messages in chat clients (#133542)
  chore(ui): refresh control ui locales (#133544)
  fix(beam): restart delivery when the receiver changes (#133533)
  ...
vincentkoc added a commit to shojikumaru/openclaw that referenced this pull request Aug 30, 2026
…cked-delivery

* origin/main:
  test: include v2026.8.1 release navigation (openclaw#133581)
  fix: stop cloud work before unrelated provider inspection finishes (openclaw#133476)
  fix(e2e): keep delete fixture target-compatible (openclaw#133526)
  fix(release): detect optional target E2E capability (openclaw#133525)
  fix(package): publish readable dist inventory (openclaw#133549)
  docs: add complete v2026.8.1 maintainer change index (openclaw#133585)
  fix(browser): preserve contextless worker and iframe sessions (openclaw#133571)
  fix(voice): discover configured provider candidates (openclaw#133507)
  refactor(ui): simplify chat rendering and lifecycle state (openclaw#133567)
  test: reduce maturity fixture cleanup time (openclaw#133566)
  improve: speed up legacy imports and transcript replacement (openclaw#133546)
  docs: add draft v2026.8.1 release notes (openclaw#133557)
  test: guard multi-project Vitest cache ownership (openclaw#133554)
  fix(memory): clarify default agent scope in command help (openclaw#133560)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: browser maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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.

[Bug]: Browser transport drops contextless worker and iframe attachments

1 participant