Skip to content

fix(e2ee): stop dropping terminal output on a backed-up legacy connection - #26528

Merged
Jinwoo-H merged 7 commits into
mainfrom
fix/e2ee-legacy-binary-queue
Oct 11, 2026
Merged

Jinwoo-H merged 7 commits into
mainfrom
fix/e2ee-legacy-binary-queue

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​419 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​389
Prod 18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​220 $\color{#cf222e}{\Huge{\mathbf{−}}}$​87 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​133

ELI5

When a phone's connection to Orca was backed up, terminal output could be silently thrown away, so text
went missing from the phone's terminal. Output could also arrive out of order. Terminal output now waits in
line like everything else. Browser pictures are the one stream allowed to skip frames, and the newest
picture still arrives once the connection catches up.

What Changed

Before:

  • Every directly connected phone, and the desktop's own link to Orca servers, uses the legacy encrypted
    channel. On that channel, a binary reply (terminal output, browser pictures) was dropped once the server
    had 32 MiB of unsent data across its sockets. terminal.subscribe ignored the failure, and the phone has
    no gap check, so output went missing silently.
  • Text replies were queued, so binary could also overtake queued text.
  • Browser pictures that were refused before the stream was "ready" were resent only at "ready", so an idle
    page could stay stuck on an old picture.

After:

  • Lossless by default. On the legacy channel, text and binary share one ordered queue, encrypted
    before queueing (legacy uses a random nonce per message, so there is no counter hazard). If the queue
    overflows, the socket closes (1013), as text already did and v2 already does. Clients then reconnect
    and reload.
  • Browser pictures opt out. A new optional {dropWhenBacklogged} on the binary sender (new shared type
    RpcBinarySender) skips the frame without queueing while the socket is busy, and returns
    'backlogged'. Only the browser screencast passes it, on both the legacy channel and v2. On legacy,
    idleness is checked before encrypting, so skipped frames cost nothing.
  • The newest picture always lands. A skipped or refused picture stays as the viewer's newest pending
    frame and is retried every 50 ms until it's delivered, replaced by a newer frame, or the viewer leaves.
  • Busy is not dead. Only a dead socket (false) counts toward evicting a ghost viewer. A merely
    backlogged one doesn't, so a terminal burst can't get a phone dropped from a browser page.

Why

Terminal output must never be lost, and browser pictures are only useful if they're current. One rule
covers both: lossless streams queue, and the single lossy stream skips frames but always ends on the
newest. Upgrading those connections to v2 was considered, but it's a 300–500 line handshake change, and
it would still leave legacy clients broken.

Linked Issue

N/A (maintainer)

Visual Proof

N/A. Delivery behaviour under backpressure; no UI change.

Testing

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

  • Legacy channel: with a tiny budget, text, binary, text, binary all arrive in order. A full queue
    closes the socket. A lossy frame is skipped, not queued. Each of these failed on the old code.

  • v2: a lossy frame is skipped without spending a message counter.

  • Real legacy E2EEChannel plus real screencast fan-out: the socket is held busy while 100 frames are
    produced. The viewer is not evicted, nothing is sent during the backlog, and after the drain exactly one
    text and then the newest frame arrive. This failed before the eviction fix.

  • Screencast retry: the last refused frame is delivered after the drain with no new frame produced.
    Retrying stops when the viewer leaves, and a newer frame replaces the pending one.

  • Wider run: 627 files and 5712 tests pass across the rpc, browser, screencast, runtime,
    ws-outbound-queue and remote-runtime suites. tsc (node), oxlint, oxfmt and the changed-code quality gate
    are clean.

Notes

  • No wire change. Both sides of every connection keep the same protocol.
  • Memory: the existing limits still apply. The 32 MiB process-wide check runs on both send and drain.
    Queued bytes are capped at 128 MiB / 16,384 frames per process, and 64 MiB / 4,096 frames per socket.
  • Not covered:
    • No test checks that skipped legacy frames are never encrypted; that rests on the code order.
    • The combined channel-plus-screencast test covers the legacy channel only. v2 skipping is tested at
      the channel.
  • Follow-up (not here): the phone's terminal has no sequence-gap resync, unlike the desktop's.

An idle page sends no next frame, so a refused last frame left the viewer on a stale picture. The
desktop's relay leg to a server uses legacy E2EE, which drops on a full socket where a direct v2 phone
queues; retrying the newest pending frame restores parity. Retries never count toward ghost eviction.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…them

Legacy E2EE (every direct phone, the desktop's server link) sent binary straight to the socket and
silently dropped it once the outbound budget was full, so terminals lost output and binary could
overtake queued text. Binary now shares the ordered text queue and closes on overflow like v2; the
lossy screencast opts into dropWhenBacklogged and its retry delivers the newest frame after a drain.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
… as a ghost

A lossy frame skipped on a busy socket returned false like a dead socket, so a long backlog evicted a
live viewer. Skips now return 'backlogged', which retries without counting toward eviction; legacy
judges idleness on the sealed size before encrypting, so skipped frames cost no encryption.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cf1f55ff-fe7e-4c9e-9b9c-325862f2b72c

📥 Commits

Reviewing files that changed from the base of the PR and between 90ce943 and d259ba2.


You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough
📝 Walkthrough

Walkthrough

Binary sends now use shared options and outcomes across RPC and E2EE paths. Legacy E2EE queues handle text and binary frames, and V2 enqueueing accepts send options. Screencast delivery distinguishes backlogged and refused sends, retains pending frames, retries the latest frame, and cancels retries during cleanup. Tests cover backpressure, queue limits, fan-out, retry behavior, and delivery over an E2EE WebSocket.



Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 90ce9

If screencast startup fails after a frame was already refused, a retry timer can keep running against the failed subscriber. This is a narrow edge case with a small fix, so it can be addressed as a follow-up.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 38.10% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 28 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 identifies the primary fix: preventing terminal output loss on backed-up legacy E2EE connections. It is concise and directly related to the changes.
Description check Passed The description is detailed and covers the user impact, implementation, rationale, testing, visual proof, linked-issue exception, known gaps, and follow-up work. Some template sections such as Review …
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.



✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR



  • Autopilot · 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.

…y-queue

# Conflicts:
#	src/main/runtime/rpc/core.ts
#	src/main/runtime/rpc/dispatcher-stream-options.ts
#	src/main/runtime/runtime-rpc/runtime-rpc-websocket-dispatch.ts
The pre-ready gate now passes the per-frame send options through to the
socket sender, so the replayed startup frame arrives with an options slot.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Main's renderer throttle lease now calls setBackgroundThrottling on the guest,
so the bare { isDestroyed } guest in two branch tests threw. One shared double
keeps all three screencast suites on the shape the lease needs.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 656e5c00-400d-4603-99ee-3f18e8b740c6
📥 Commits

Reviewing files that changed from the base of the PR and between 5f5e3a6 and 90ce943.

📒 Files selected for processing (10)
  • src/main/runtime/orca-runtime-browser-screencast-e2ee-backlog.test.ts
  • src/main/runtime/orca-runtime-browser-screencast-fanout.test.ts
  • src/main/runtime/orca-runtime-browser-screencast-pending-frame-retry.test.ts
  • src/main/runtime/orca-runtime-browser.test.ts
  • src/main/runtime/orca-runtime-tests/mobile-creation-and-orchestration.spec.ts
  • src/main/runtime/rpc/core.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-frame-delivery.ts
  • src/main/runtime/runtime-browser-commands-browser-screencast.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-websocket-dispatch.ts
  • src/main/runtime/single-page-browser-commands-host-test-double.ts

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

subscriber.pendingFrame = delivered ? null : bytes
subscriber.delivery = recordScreencastSubscriberSend(subscriber.delivery, delivered)
// A slow viewer drops this frame without stalling every other viewer.
deliverScreencastSubscriberFrame(subscriber, bytes)

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -eu
printf '%s\n' '--- diff summary ---'
git diff --stat 4c4f1ee18c8948cce8cab26d6f9ca29c3b2395a5 90ce943a6e7800a9f652d540d828a4d9e0ba703e -- src/main/runtime/runtime-browser-commands-browser-screencast.ts src/main/runtime/browser-screencast-subscriber-frame-delivery.ts
printf '%s\n' '--- screencast file ---'
nl -ba src/main/runtime/runtime-browser-commands-browser-screencast.ts | sed -n '1,230p'
printf '%s\n' '--- delivery helper ---'
nl -ba src/main/runtime/browser-screencast-subscriber-frame-delivery.ts | sed -n '1,260p'
printf '%s\n' '--- startBrowserScreencast references ---'
rg -n -F --glob '*.ts' -- 'startBrowserScreencast' src tests || true
printf '%s\n' '--- browser screencast tests/references ---'
rg -n -F --glob '*.{ts,tsx}' -- 'browserScreencast' src tests || true

Repository: stablyai/orca

Length of output: 36555


🏁 Script executed:

set +e
printf '%s\n' '--- changed-file diff ---'
git diff --unified=80 4c4f1ee18c8948cce8cab26d6f9ca29c3b2395a5 90ce943a6e7800a9f652d540d828a4d9e0ba703e -- src/main/runtime/runtime-browser-commands-browser-screencast.ts src/main/runtime/browser-screencast-subscriber-frame-delivery.ts
printf '%s\n' '--- screencast file ---'
nl -ba src/main/runtime/runtime-browser-commands-browser-screencast.ts | sed -n '1,230p'
printf '%s\n' '--- delivery helper candidates ---'
find src -type f -iname '*screencast*' -print
printf '%s\n' '--- startBrowserScreencast references ---'
rg -n -F --glob '*.ts' -- 'startBrowserScreencast' src tests 2>/dev/null || true
printf '%s\n' '--- browser screencast references ---'
rg -n -F --glob '*.ts' -- 'browserScreencast' src tests 2>/dev/null || true

Repository: stablyai/orca

Length of output: 41800


🏁 Script executed:

printf '%s\n' '--- source files ---'
nl -ba src/main/runtime/runtime-browser-commands-browser-screencast.ts | sed -n '1,230p'
find src -type f -iname '*screencast*' -print
printf '%s\n' '--- delivery helper ---'
for f in $(find src -type f -iname '*screencast*' -print); do
  case "$f" in
    *subscriber*delivery*) nl -ba "$f" | sed -n '1,280p';;
  esac
done
printf '%s\n' '--- startBrowserScreencast references ---'
rg -n -F --glob '*.ts' -- 'startBrowserScreencast' src tests 2>/dev/null || true
printf '%s\n' '--- browserScreencast references ---'
rg -n -F --glob '*.ts' -- 'browserScreencast' src tests 2>/dev/null || true

Repository: stablyai/orca

Length of output: 38718


🏁 Script executed:

pwd
git status --short
nl -ba src/main/runtime/runtime-browser-commands-browser-screencast.ts | sed -n '1,210p'
printf '%s\n' '--- files ---'
find src -type f -iname '*screencast*' -print

Repository: stablyai/orca

Length of output: 12602


🏁 Script executed:

printf '%s\n' '--- startBrowserScreencast implementation ---'
nl -ba src/main/browser/browser-screencast-stream.ts | sed -n '1,280p'
printf '%s\n' '--- startup failure and first-frame tests ---'
nl -ba src/main/browser/browser-screencast-first-frame-timeout.test.ts | sed -n '1,180p'
nl -ba src/main/browser/browser-screencast-lifecycle.test.ts | sed -n '1,150p'
printf '%s\n' '--- runtime startup-failure tests ---'
nl -ba src/main/runtime/browser-screencast-renderer-throttle-lease.test.ts | sed -n '90,230p'
nl -ba src/main/runtime/orca-runtime-browser-screencast-fanout.test.ts | sed -n '115,180p'

Repository: stablyai/orca

Length of output: 30636


🏁 Script executed:

nl -ba src/main/browser/browser-screencast-stream.ts | sed -n '1,320p'
printf '%s\n' '--- first-frame timeout ---'
nl -ba src/main/browser/browser-screencast-first-frame-timeout.test.ts | sed -n '1,180p'
printf '%s\n' '--- runtime startup failure ---'
nl -ba src/main/runtime/browser-screencast-renderer-throttle-lease.test.ts | sed -n '90,230p'

Repository: stablyai/orca

Length of output: 21912


🏁 Script executed:

printf '%s\n' '--- CDP message handler ---'
nl -ba src/main/browser/browser-screencast-cdp-events.ts | sed -n '1,280p'
printf '%s\n' '--- frame pacer ---'
nl -ba src/main/browser/browser-screencast-frame-pacer.ts | sed -n '1,300p'
printf '%s\n' '--- admission contract ---'
nl -ba src/main/runtime/remote-browser-screencast-frame-admission.ts | sed -n '1,180p'

Repository: stablyai/orca

Length of output: 12031


🏁 Script executed:

nl -ba src/main/browser/browser-screencast-cdp-events.ts | sed -n '1,280p'
nl -ba src/main/browser/browser-screencast-frame-pacer.ts | sed -n '1,300p'
nl -ba src/main/runtime/remote-browser-screencast-frame-admission.ts | sed -n '1,180p'

Repository: stablyai/orca

Length of output: 11956


Cancel the retry before deleting a failed subscriber.

startBrowserScreencast accepts frame events while startup is pending. If a subscriber refuses such a frame and startup then fails, the catch deletes the subscriber before the chained stream finalizer cancels its retry. The retry can continue against the failed subscriber.

🐛 Suggested fix
     } catch (error) {
+      const subscriber = active.subscribers.get(subscriptionId)
+      if (subscriber) {
+        cancelScreencastSubscriberFrameRetry(subscriber)
+      }
       active.subscribers.delete(subscriptionId)
       resolveSubscriberDone()
       throw error

@Jinwoo-H
Jinwoo-H merged commit 08c8d30 into main Oct 11, 2026
31 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