Repository navigation
fix(browser): preserve peer observations after a rejected page attachment - #13841
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge; the change preserves peer observations without weakening cleanup for uncertain attachment outcomes. SummaryThe PR keeps a shared browser WebSocket open when Chrome explicitly rejects a page attachment.
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]
Reviews (2) · Last reviewed commit: "fix(browser): preserve peer observations..." · Reviewed by Greptile |
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 withtransport_disconnected.Change and scope
The page-session cleanup path recognizes the existing
CdpCommandRejectionproduced 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
CdpBrowserProvider.withTargetSessionchooses how to release an acquired endpoint after attachment fails.CdpConnectionalready validates the reply and classifies explicit command rejections.protocol_error. Other operations on that browser WebSocket can continue. Existing tool arguments, results, deadlines, and target selection apply.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
Evidence and regression coverage
6cda340ec, the explicit-rejection case receivedtransport_disconnecteddespite the independently delivered peer event. The other three cases passed. All four pass with this change.-32602 No target with given id found. On the base, an observation on another page ended withtransport_disconnectedand a follow-up inspection opened a second socket. With the change, the peer ended withwindow_elapsedand the follow-up reused the first socket.inspect_web_pagereturnedprotocol_errorwith the fixture's CDP command and code. The peer reported its owntarget_terminatedevent 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.
Validation performed
npm run build:cachedsucceeded. Vitest passed 248 tests across 17 browser provider, connection, owner, CLI, and MCP test files.npm run check:fastpassed typechecking, lint and architecture guards.npm run check:cion 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.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
Before merge
type(scope): outcome.