Skip to content

fix(browser): preserve peer observations after a rejected page attachment - #13841

Merged
morluto merged 1 commit into
morluto:mainfrom
cyanseek:codex/cdp-rejected-page-attach
Nov 23, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
cyanseek:codex/cdp-rejected-page-attach

Conversation

@cyanseek

Copy link
Copy Markdown
Contributor

Summary

When Chrome rejects a page attachment, REA now releases that operation's lease on the shared browser WebSocket. A concurrent observation can finish its requested window, and the next inspection can use the same connection.

Problem and expected behavior

A selected page can close between target discovery and Target.attachToTarget. Chrome then returns a correlated command error. Previously, REA correctly reported the failed inspection but also closed the shared socket. A capture on another page ended early with transport_disconnected.

Change and scope

The page-session cleanup path recognizes the existing CdpCommandRejection produced by the CDP transport. An explicit rejection releases the lease. A cancellation, timeout, or unusable success reply after the attach was sent still evicts the socket because a session may have been created. The existing owner handles both cleanup paths.

Contract and boundary impact

  • Semantic owner and earliest changed stage. CdpBrowserProvider.withTargetSession chooses how to release an acquired endpoint after attachment fails. CdpConnection already validates the reply and classifies explicit command rejections.
  • Contribution scope. This fixes cleanup within the existing passive CDP browser capability. A new maintainer scope decision is inapplicable. The original browser-socket reuse contract is in #9203. The issue search found no dedicated report for peer observations lost after a rejected page attachment.
  • CLI and MCP. The rejected inspection still reports protocol_error. Other operations on that browser WebSocket can continue. Existing tool arguments, results, deadlines, and target selection apply.
  • Provider and evidence. The affected transport is an admitted browser WebSocket. REA continues to require the caller's selected target and allowed origin. Existing page-socket, successful detach, evidence, artifact, installation, and generated metadata contracts are unchanged.

In the real page inspection and session observation, REA enabled CDP domains, read the frame tree and metrics, and detached. The CDP trace contained no script evaluation or script installation.

Expected effects for the affected existing workflow

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • The regression uses a production provider and a controlled loopback WebSocket. It starts a real observation lease before a second operation attempts attachment. It checks the original error, the peer's end reason, the next inspection's connection count, and provider shutdown for explicit refusal, cancellation after send, timeout, and malformed success.
  • On 6cda340ec, the explicit-rejection case received transport_disconnected despite the independently delivered peer event. The other three cases passed. All four pass with this change.
  • In Chromium 151.0.7922.34, the fixture closed one owned page after discovery and before REA sent the attach. Chromium itself returned -32602 No target with given id found. On the base, an observation on another page ended with transport_disconnected and a follow-up inspection opened a second socket. With the change, the peer ended with window_elapsed and the follow-up reused the first socket.
  • In a separate stdio MCP run, the refused inspect_web_page returned protocol_error with the fixture's CDP command and code. The peer reported its own target_terminated event and a follow-up inspection succeeded. The CLI returned exit 1 with the same structured reason and command detail, and a subsequent successful command returned exit 0.

The evidence preserves the following distinctions.

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run build:cached succeeded. Vitest passed 248 tests across 17 browser provider, connection, owner, CLI, and MCP test files.
  • npm run check:fast passed typechecking, lint and architecture guards. npm run check:ci on both the base and the change stopped at the same five Knip findings in client configuration, uninstall, and UEFI modules. Fresh uncached Knip runs confirmed the same list on both.
  • Typed lint passed on both changed files with eight warnings. A separate repository-wide typed lint run reported three switch exhaustiveness errors in the managed graph, JavaScript application version comparison, and web-module import code. Running the same typed rules on those three files at the base reproduced all three errors. Test discovery, both Python suites (184 tests), and the production reachability report passed.
  • The stock real-browser verifier has a separate large-screenshot fixture failure on this Linux/Chromium setup. In targeted production screenshot captures on the base and the change, un-clipped PNG coverage was 2048 × 1393 for an emulated 2048 × 1536 viewport. The clipped retry returned a full-size PNG, but the final viewport had changed to 2048 × 1393. REA reported target_changed. The real Chromium page-attachment comparison above passed independently.

Compatibility, safety, and release

This is a provider lifecycle fix. Existing callers need no migration. REA uses the same CDP methods, endpoint policy, origin checks, cleanup owner, and evidence schema. Real browser coverage used Linux Chromium. The diff touches the provider and its boundary test only.

Author readiness

Human owner: @cyanseek

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T01:46:27.798071Z b67185a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the change preserves peer observations without weakening cleanup for uncertain attachment outcomes.

Summary

The PR keeps a shared browser WebSocket open when Chrome explicitly rejects a page attachment.

  • A rejected page attachment no longer interrupts other browser sessions.

Source review found no actionable issues. Tests were not run during this review. Whether another PR supersedes this one could not be checked because GitHub access was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Page attachment fails] --> B{Explicit command rejection?}
  B -->|Yes| C[Release this operation's lease]
  C --> D[Healthy socket remains available to peers]
  B -->|No| E[Evict and close socket]
  E --> F[Next operation opens a new socket]
Loading

Reviews (2) · Last reviewed commit: "fix(browser): preserve peer observations..." · Reviewed by Greptile

@morluto
morluto enabled auto-merge (squash) November 23, 2026 01:58
@morluto
morluto merged commit 6ecb70c into morluto:main Nov 23, 2026
40 checks passed
@morluto morluto added area: runtime Process capture and runtime observation bug Something isn't working labels Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants