Skip to content

fix(browser): reuse the process DevTools connection - #487

Merged
steipete merged 2 commits into
mainfrom
fix/browser-connection-reuse
Sep 12, 2026
Merged

fix(browser): reuse the process DevTools connection#487
steipete merged 2 commits into
mainfrom
fix/browser-connection-reuse

Conversation

@steipete

@steipete steipete commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Chrome approves each browser WebSocket separately. Oracle previously opened and closed that socket for target discovery and each page operation, so one run or successive service requests could repeatedly show Allow remote debugging?.

Retain one browser connection per endpoint for the process lifetime, share pending approvals, and give each page an independently disposable session. Cancellation and approval deadlines release only their own lease; failed handshakes and real disconnects permit reconnection. Page listeners are removed on disposal, command callbacks remain session-bound, failed attachment cleans up only its newly created tab, and idle sockets allow a normal CLI exit.

Fixes #484.

Validation: 51 focused connection/lifecycle tests, a 2,410-test full-suite baseline followed by the focused callback regression, and the composed batch's 2,458-test suite. The compiled transport proof counted one real WebSocket handshake across three discovery/attach/evaluate/dispose cycles and natural child-process exit; repeated real CLI clients also reused one service socket against a synthetic DevTools endpoint. CI now runs the standalone transport proof after an explicit build on every platform.

The instrumented signed-in proof uses one long-lived built service: five model-warning scenarios, a Pro answer, reattach, and harvest have completed with exactly one handshake/upgrade. The same service also delivered the generated PNG with its dimensions and file ID intact. The probe refuses any second handshake. Separate CLI processes still require separate approval; use one long-running service to share approval across client commands. Release notes are consolidated in #486.

Local and committed-branch autoreviews are clean through P2. All four CI jobs passed on final head 465843e5be5b96d3a0b8d6fa32776cf10e651f00: https://github.com/steipete/oracle/actions/runs/34669035154. Ready for the orchestrator’s squash-merge decision. The Windows run exposed an existing MCP proof cleanup race (EBUSY after signalling a detached worker). The follow-up waits for worker exit before directory removal and adds bounded filesystem retries without dropping any lifecycle assertion.

@clawsweeper

clawsweeper Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete

steipete commented Sep 12, 2026

Copy link
Copy Markdown
Owner Author

Live proof for head 465843e5be5b96d3a0b8d6fa32776cf10e651f00 used the composed batch build and one long-running built CLI service. Instrumentation covered the WebSocket library's actual HTTP GET upgrade path and refused a second handshake. It recorded one attempt at 2026-09-12T02:44:00.455Z and one upgrade at 02:44:04.376Z, with no subsequent handshake across five CLI warning runs, a signed-in Pro answer, Pro-preserving reattach, matched-identity harvest, generated-image transfer, provider sign-in inspection, and owned-tab cleanup.

The standalone compiled-transport proof independently counted one handshake across three discovery/attach/delayed-evaluation/dispose cycles and natural child-process exit. Real CLI service-routing fixtures also cover repeated requests using one transport. Validation includes 51 focused tests and the 2,458-test composed suite; local and branch autoreview are clean through P2. All four CI jobs passed at final head 465843e5be5b96d3a0b8d6fa32776cf10e651f00: https://github.com/steipete/oracle/actions/runs/34669035154. The follow-up to the initial Windows CI failure changes only the MCP proof and Windows notes: wait for detached-worker exit before removing its working directory, then use bounded filesystem retries. All six MCP lifecycle cases pass locally with explicit worker-exit and cleanup assertions. The live browser code is unchanged from the instrumented proof.

For transparency, the maintenance session used two Chrome attaches total: one preliminary warning run before correcting its handshake counter, then the single final instrumented run above. There were no per-test reconnects. Release notes are in #486.

@clawsweeper

clawsweeper Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 11, 2026, 11:42 PM ET / September 12, 2026, 03:42 UTC (Revision 4).

ClawSweeper review

What this changes

Oracle reuses one browser debugging connection per endpoint, cleans up page sessions independently, and adds transport checks plus reliable Windows proof cleanup.

Merge readiness

Ready for maintainer review

This PR remains useful: the reviewed main branch and v0.20.1 still close browser connections between operations. No blocking defect was found; the supplied instrumented browser proof supports connection reuse across service requests.

Priority: P2
Reviewed head: 465843e5be5b96d3a0b8d6fa32776cf10e651f00

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with strong recorded runtime evidence and no identified blocking findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The captured instrumented signed-in service run exercised the changed connection owner across repeated requests, Pro output, reattach, and cleanup with one actual WebSocket upgrade; the compiled transport proof separately covers delayed commands and natural idle exit.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The captured instrumented signed-in service run exercised the changed connection owner across repeated requests, Pro output, reattach, and cleanup with one actual WebSocket upgrade; the compiled transport proof separately covers delayed commands and natural idle exit.
Evidence reviewed 8 items Policy and review scope: Read the complete root AGENTS.md and Windows guidance. No nested AGENTS.md or .agents/maintainer-notes directory was found. Applied the browser proof guidance and accepted the maintainer’s consolidated release-note arrangement in #486.
Introduced connection ownership: The endpoint-keyed pool shares pending connections, counts active leases, releases idle socket references, and evicts disconnected or failed connections. Page cleanup removes its listeners and detaches its session before releasing its lease.
Still needed on main and release: Inspected the pinned main implementation, which creates a new CDP connection for each acquisition and closes it during cleanup. The same behavior remains in v0.20.1; the supplied related implementation PRs are open, not merged replacements.
Findings None None.
Security None None.

How this fits together

Oracle’s browser engine sends prompts and captures answers through Chrome’s debugging connection. Target discovery, page automation, and recovery share that connection within one CLI or service process.

flowchart TD
  A[CLI or service request] --> B[Browser endpoint]
  B --> C{Connection available?}
  C -->|Yes| D[Shared browser connection]
  C -->|No| E[Chrome approval and connection]
  E --> D
  D --> F[Independent page sessions]
  F --> G[Automation and answer capture]
  G --> H[Detach session and retain connection]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Code and validation growth Production net +121 lines; tests net +231; proof scripts net +138 Production growth implements shared transport ownership and page isolation, with larger regression and transport-proof coverage.

Technical review

Best possible solution:

Keep connection ownership at process scope while preserving independently disposable page sessions, existing authorization checks, and normal idle CLI exit.

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

Yes, from source: main creates and closes separate browser WebSockets for discovery and attachment, explaining repeated per-connection approvals. This review did not execute a browser reproduction.

Is this the best way to solve the issue?

Yes. Sharing the browser transport while retaining separate page sessions directly repairs the ownership mismatch without adding configuration or replacing existing authentication and tab-selection rules.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d1b2e38e2b59.

Labels

Label justifications:

  • P2: Repeated Chrome approvals are a bounded browser-workflow problem with a focused implementation and positive runtime evidence.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The captured instrumented signed-in service run exercised the changed connection owner across repeated requests, Pro output, reattach, and cleanup with one actual WebSocket upgrade; the compiled transport proof separately covers delayed commands and natural idle exit.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured instrumented signed-in service run exercised the changed connection owner across repeated requests, Pro output, reattach, and cleanup with one actual WebSocket upgrade; the compiled transport proof separately covers delayed commands and natural idle exit.

Evidence

What I checked:

  • Policy and review scope: Read the complete root AGENTS.md and Windows guidance. No nested AGENTS.md or .agents/maintainer-notes directory was found. Applied the browser proof guidance and accepted the maintainer’s consolidated release-note arrangement in chore: consolidate browser fixes and refresh Zod #486. (AGENTS.md:1, 465843e5be5b)
  • Introduced connection ownership: The endpoint-keyed pool shares pending connections, counts active leases, releases idle socket references, and evicts disconnected or failed connections. Page cleanup removes its listeners and detaches its session before releasing its lease. (src/browser/browserConnection.ts:22, 465843e5be5b)
  • Still needed on main and release: Inspected the pinned main implementation, which creates a new CDP connection for each acquisition and closes it during cleanup. The same behavior remains in v0.20.1; the supplied related implementation PRs are open, not merged replacements. (src/browser/chromeLifecycle.ts:681, 19fbb1a86050)
  • Recorded real browser proof: The captured maintainer comment reports one actual HTTP upgrade attempt and one completed upgrade across repeated built-service CLI requests, a signed-in Pro answer, Pro-preserving reattach, harvest, and owned-tab cleanup. It explicitly connects the composed build to this head’s unchanged browser code: fix(browser): reuse the process DevTools connection #487 (comment). (465843e5be5b)
  • Focused lifecycle validation: Read the regression coverage for concurrent leases, cancelled discovery, pending approval, deadlines, genuine disconnects, listener cleanup, borrowed-tab preservation, failed attachment, and callback forwarding. The compiled transport proof uses real WebSockets and checks three delayed evaluations, one handshake, and natural process exit. Supplied checks passed; tests and proof scripts were not executed during this read-only review. (tests/browser/browserConnection.test.ts:65, 465843e5be5b)
  • Authorization and session isolation: Service requests retain bearer-token admission and host-owned endpoint configuration. Deep Research filters shared target events by the parent page session before reading related frames. The patch retains per-page command binding and does not introduce a new route around those checks. (src/browser/actions/deepResearch.ts:693, 465843e5be5b)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • dedene: 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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-12T02:50:09.698Z sha d8a19b2 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-12T03:00:59.548Z sha 465843e :: needs maintainer review before merge. :: none
  • reviewed 2026-09-12T03:06:02.663Z sha 465843e :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. 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 12, 2026
@steipete
steipete merged commit 20d70d6 into main Sep 12, 2026
5 checks passed
@steipete
steipete deleted the fix/browser-connection-reuse branch September 12, 2026 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

browser: reuse DevTools approval across operations in one process

1 participant