Skip to content

fix(browser): bound CDP output for stalled clients - #20949

Merged
nwparker merged 2 commits into
mainfrom
np-oom-scan-cdp-backpressure
Sep 20, 2026
Merged

nwparker merged 2 commits into
mainfrom
np-oom-scan-cdp-backpressure

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​123 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​123
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​266 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​257

ELI5

Browser automation clients receive command replies and browser events. If a client stops reading, Orca previously kept saving more messages for it. This change disconnects a client whose waiting messages become too large.

What Changed

Send CDP output through the existing bounded WebSocket writer. A stalled connection is terminated when queued output exceeds 64 MiB or 4,096 frames. Normal replies and events retain their order.

Why

One stalled automation client should not exhaust the host's memory. Keeping every message forever recreates the leak.

Tradeoff

Queued replies and events are discarded when the connection is closed. Automation may need to reconnect and determine whether a command already ran before retrying it. Large direct messages remain allowed while the connection is draining.

Linked Issue

Related to #19831 as memory hardening; incident causality is not established.

Visual Proof

No before/after UI capture is attached; this is an automation-connection behavior change. Automated behavior evidence is linked under Testing.

Testing

The audit covers a stalled real client, both queue limits, close cleanup, and ordinary CDP output delivery.

Audit evidence

Review

Do not automatically retry side-effecting commands unless the caller can prove they are idempotent.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one minor docs-tracking nit.

Reviewed changes

  • Backpressure routing for CDP replies: CdpClientResponseWriter.send now enqueues onto the existing createWsOutboundBackpressureQueue (8 MiB soft cap, 64 MiB / 4,096-frame hard caps) instead of writing straight to ws, with lazy per-client queue creation and disposal in forgetClient.
  • Debugger events share that queue: CdpDebuggerChannel event fan-out now calls responder.send(msg, client) instead of client.send(...), so events and command replies preserve order through one queue. Event payloads carry no numeric id, so the responder's session-correlation step is a no-op for them.
  • Tests + audit artifacts: a new real-socket writer suite pins ordering/session correlation, queue teardown, stalled-reader termination on overflow, and a 65 MiB single reply; docs/audits/cdp-stream-retention/ records the before/after reproduction.

ℹ️ Nitpicks

  • docs/audits/cdp-stream-retention/ matches the wholesale docs/** ignore rule (.gitignore:96) and was force-added, so a clean git add won't pick it up. Add !docs/audits/ and !docs/audits/** to the allow-list so the evidence stays reproducible.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: d8211811-4055-4ebd-974c-9eb9feff43be

📥 Commits

Reviewing files that changed from the base of the PR and between d12d1e0 and c1ff3b7.

📒 Files selected for processing (2)
  • src/main/browser/cdp-client-response-writer.ts
  • src/shared/ws-outbound-backpressure-queue.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/browser/cdp-client-response-writer.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The CDP response writer now queues serialized WebSocket messages per client. The queue reports overflow evidence, limits draining per event-loop turn, terminates stalled clients, and disposes state when clients close or are forgotten. Debugger events use this writer. Tests cover ordering, cleanup, large replies, stalled readers, and bursts. Audit tooling and fixtures measure retention behavior.

Priority: ⬇️ Low

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: bounding CDP output for stalled browser clients.
Description check ✅ Passed The description covers the user impact, mechanism, rationale, tradeoff, linked issue, visual-proof rationale, testing evidence, and review guidance. It omits several template checklist sections and do…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The outbound queue terminated the automation client silently on overflow, so
the client saw a socket close indistinguishable from a crash. Surface the cap
that tripped and the backlog held when it did.

The queue dropped its backlog before invoking onOverflow, so the counters were
already zero at the callback. Snapshot them first and pass them through.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This run re-reviewed the single commit added since the prior pullfrog review (d12d1e0 → c1ff3b7), which adds observability to the CDP outbound overflow path.

  • Overflow evidence on the shared queue: createWsOutboundBackpressureQueue's onOverflow now receives a WsOutboundOverflowEvidence snapshot — which cap tripped plus the backlog held when it did — captured before dropBacklog() zeroes the counters. The widened signature is backward compatible; every existing caller passes a zero-arg handler.
  • CDP overflow logging: CdpClientResponseWriter logs the cap and queued byte/frame counts before terminating a stalled automation client, so the abrupt close is diagnosable from the main-process log.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit a445aba into main Sep 20, 2026
27 of 30 checks passed
@nwparker
nwparker deleted the np-oom-scan-cdp-backpressure branch September 20, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants