Skip to content

fix(browser): release failed shared screencast joins - #34874

Merged
OrcaWin merged 2 commits into
mainfrom
OrcaWin/electron-browser-lifetime-pass2
Oct 28, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
OrcaWin/electron-browser-lifetime-pass2

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​184 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​183
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8

ELI5

If a second browser viewer fails to join a live stream, Orca now removes that failed viewer. The working viewer stays connected, and closing the last working viewer stops the native stream.

What Changed

Shared screencast joins register their subscriber before configuring the native viewport and frame budget. A rejected native update previously escaped without removing that subscriber. The caller never received its stop handle, so the failed join could retain its sender, newest frame, 50 ms retry timer and native-stream ownership indefinitely.

Route configuration failures through the existing subscriber leave path. A reconnect replaces its previous socket only after configuration succeeds, and only retires subscriptions older than itself. Both completion orders of overlapping reconnects preserve the newest viewer.

Why

One rejected join left one unreachable owner. A pre-ready sender rejects delivery, and ghost eviction deliberately excludes viewers that have never received a frame. Closing every successful viewer therefore could leave native capture and publication leases running. The unchanged-base reproduction recorded three failed-sender calls over 100 ms (initial fan-out plus retry ticks).

The existing leave path already cancels pending retries, restores the surviving viewport/budget, resolves subscriber completion and stops an empty native stream. Reusing it keeps ownership in one place.

Linked Issue

N/A — focused internal Electron lifetime audit.

Visual Proof

Before: the three new failure regressions fail against unchanged production at 5237d52f82: the failed distinct-device sender receives later frames, same-device replacement masks a restart failure, and a failed last joiner keeps the native stream alive.

After: Linux Electron 43.8.1 hidden-webview fault injection sends two real Page.startScreencast calls with an invalid format to Chromium. Both native errors reach the caller, the healthy viewer continues receiving actual PNG frames, and neither failed sender receives later attempts. The last successful leave sends exactly one Page.stopScreencast, detaches the debugger and restores both throttling leases. All window presentation/focus methods throw in this harness.

Playwright CDP screenshot of the hidden renderer after the failures:

Healthy browser page after rejected joins

PNG decoded from the actual binary screencast (pixel at 100,350 verified as BGRA [70,130,30,255]):

Surviving native screencast frame

The native harness exercises the production runtime/native stream with injected Chromium rejection; it is not a full mobile or SSH interaction recording.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Unchanged-base failure controls: 3 failed / 3 passed; production source automatically restored afterward.

  • Focused runtime/native suites: 55 tests passed in 5 files, including both overlapping-reconnect completion orders, retry/fan-out, native stream lifecycle and renderer publication leases.

  • Native Linux hidden-renderer proof described above; screenshot inspected through Playwright CDP. Own native apps exited 0 and Playwright session closed; shared isolated display retained.

  • After rebasing onto main (including perf(browser): throttle idle guests between active operations #34776 idle guest throttling), branch-native pnpm check:changed --maxWorkers=1 passed 20/20 checks in 1602.7 s. An earlier --maxWorkers=2 attempt under host load (load average ~80) timed out only in the unchanged replaced-pane-handle-recovery.test.ts source census.

  • Renderer publication throttle leases belong to the native stream: they are acquired once when the stream starts and released once when it finishes. A failed join or a same-device replacement therefore never holds its own lease. The failed-last-joiner regression now asserts that the guest lease is restored exactly once.

  • Packaged-app builds and other-platform coverage are left to CI. Native proof bundle compiled against the production source.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

No RPC schema, platform path, shell, shortcut or workspace-kind change. Paired-device reconnects use the existing subscriber identity. Remote/mixed-version compatibility and folder workspaces remain unchanged. macOS, Windows, actual SSH and mobile hardware were not exercised. Counts demonstrate ownership and teardown; no CPU, memory, GPU or battery measurement is claimed.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@OrcaWin
OrcaWin force-pushed the OrcaWin/electron-browser-lifetime-pass2 branch from 5157557 to 52c586a Compare October 28, 2026 09:04
@OrcaWin
OrcaWin marked this pull request as ready for review October 28, 2026 09:04
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1ad6dd54-2915-43f3-b4af-121335475176
Commits

Reviewing files that changed from the base of the PR and between 52c586a and f65f24d.

Files selected for processing: 1
  • src/main/runtime/browser/browser-screencasts.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

For an existing browser screencast stream, viewport-owner and shared frame-budget updates now run before earlier subscribers for the same paired device are removed. If an update fails, the joining subscriber is removed and the error is rethrown. Tests cover failed reconnects, replacement stream creation, and reconnects that complete in different orders.

Priority: Normal

Merge Risk: Minimal · up to f65f2

Failed joins and overlapping reconnects have no established regression that would prevent merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the required change, rationale, testing, visual proof, review notes, and checklist. However, the required Linked Issue section contains “N/A” instead of an actua… Add the actual linked issue using the required issue reference format. If the author is a maintainer, attach a pre-existing issue as permitted by the template; otherwise, create or link the issue addressed by this PR.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: releasing resources when shared screencast joins fail.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Full details: Description check

Explanation

The description is detailed and covers the required change, rationale, testing, visual proof, review notes, and checklist. However, the required Linked Issue section contains “N/A” instead of an actual issue reference.

Resolution

Add the actual linked issue using the required issue reference format. If the author is a maintainer, attach a pre-existing issue as permitted by the template; otherwise, create or link the issue addressed by this PR.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@OrcaWin
OrcaWin force-pushed the OrcaWin/electron-browser-lifetime-pass2 branch from 52c586a to f65f24d Compare October 28, 2026 09:44
@OrcaWin
OrcaWin merged commit 7cf156a into main Oct 28, 2026
45 of 46 checks passed
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.

1 participant