Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): browser control replies no longer wait behind old frames on slow links #20290

Mergedshivamhwp(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/20290/headmerged by juliusmarminge View on GitHub

Closes #20283

What was wrong

Browser frames and control replies share one WebSocket. The server wrote every frame the moment Chromium made it, so on a slow link a few big JPEGs sat in the socket ahead of replies like "you have control", probe results and dialogs. Those replies had to wait until the old images finished sending. This hits any streamed viewer: web, and the Android/iOS app's browser.

The fix

ServerBrowserStream now keeps at most one frame on the wire and one newest frame waiting behind it:

  • If a frame is still waiting for the viewer's ack, a new frame replaces the waiting one. The replaced frame is acked to Chromium right away so the screencast keeps going.
  • When the viewer acks, the server acks that frame to Chromium and sends the newest waiting frame.
  • Everything that isn't a frame (control, probe, viewport, dialogs, downloads…) is written right away, so it is never stuck behind more than one image.

The old 64-frame window is gone; the 8 MiB socket guard stays. Server only, no client or contract change.

I left out the other parts of the issue's proposal (adaptive resolution, scaled stills). They change sharpness and frame rate and the issue asks for a maintainer call on them first.

Trade-off: a slow viewer gets at most one frame per round trip. On a fast link nothing changes, since Chromium's own pacing (100 ms, 3 unacked frames) is already the limit.

Evidence

Android app (POCO M3, release build) connected to a dev server through a proxy capped at 160 KB/s with 120 ms delay. An agent opened a test page that redraws noise every frame. I tapped Take control / Release control and timed when the label changed.

Before (main)After (this PR)
2.8 s to 8.7 s per toggle, one tap never showed within 30 sUnder 1 s every time, picture keeps updating
full videofull video

Tests: new ServerBrowserStream.test.ts case sends frame 1, holds its ack, then queues frames 2, 3, 4 and a probe reply. On main the viewer gets [1, 2, ...] before the reply. With the fix it gets [1, "probe"], frames 2 and 3 are acked to Chromium without being sent, and after the viewer acks it gets frame 4. ServerBrowserStream.test.ts and ServerBrowser.test.ts pass, server typecheck is clean.

Done by Claude Opus 5.5 in Claude Code through T3 Code.

🤖 Generated with Claude Code

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Approved at ab071c3

      Macroscope's review found this PR approvable — This is a localized server bug fix that bounds frame buffering to the current and newest image so control replies are not delayed on slow links. It preserves existing protocol and socket safeguards and includes focused integration coverage.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 4602a7d8-48f3-4042-aa6d-6e5eda3b36d9
      📥 Commits

      Reviewing files that changed from the base of the PR and between cfafb4bb54d244e4612f5681aad3832ea64cb0fb and ab071c3c3e426272380cae3e4bc69f46f9eb7990.

      📒 Files selected for processing: 2
      • apps/server/src/preview/ServerBrowserStream.test.ts
      • apps/server/src/preview/ServerBrowserStream.ts

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

      📝 Walkthrough

      ServerBrowserStream now sends one frame at a time and keeps only the newest pending frame. The test checks that superseded frames are acknowledged and a probe reply arrives before the retained frame.

      Changes: Browser frame streaming

      Layer / File(s)Summary
      Latest-frame stream queue
      apps/server/src/preview/ServerBrowserStream.ts, apps/server/src/preview/ServerBrowserStream.test.ts
      The stream replaces the 64-frame unacknowledged queue with one in-flight frame and one replaceable pending frame. It acknowledges a replaced pending frame and sends the retained frame after the in-flight frame is acknowledged. The test checks frame ordering and probe reply timing.

      Priority: ➖ Normal

      Estimated code review effort: 2 (Simple) | ~12 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Sequence Diagram(s)

      sequenceDiagram
        participant FrameProducer
        participant ServerBrowserStream
        participant Viewer
        FrameProducer->>ServerBrowserStream: Provide frames 1–4
        ServerBrowserStream->>Viewer: Send frame 1
        ServerBrowserStream->>FrameProducer: Acknowledge superseded frames 2 and 3
        Viewer->>ServerBrowserStream: Send probe and acknowledge frame 1
        ServerBrowserStream->>Viewer: Send probe reply
        ServerBrowserStream->>Viewer: Send pending frame 4
        ServerBrowserStream->>FrameProducer: Acknowledge frame 1

      Suggested reviewers: maria-rcks

      Merge Risk: ⚪ Minimal · up to ab071

      This change keeps slow browser-preview viewers on the newest frame and lets control replies arrive without waiting behind stale frames. No actionable merge-blocking risk remains.

      Security architecture risk: 🔵 Low · up to ab071

      The change is confined to browser-preview delivery and preserves existing access checks and resource limits. No introduced security vulnerability was established. Remaining uncertainty concerns concurrent socket writes and partial-write failure behavior.

      Retained concerns No architecture-level concerns identified.

      Security review details

      Security Blast Radius

      • inferred — The changed scheduling state belongs to an individual attached viewer and its CDP session. The inspected change does not add cross-service calls, credentials, or browser-operation authority; its direct exposure is preview delivery within the viewer's existing access.

      Trust Boundaries and Controls

      • observed — WebSocket attachment still requires orchestration-read authorization. Client-controlled non-acknowledgement messages reach viewer input only with preview-operate permission and interactive mode enabled; the service additionally checks viewer permission and control ownership. Acknowledgement messages select server-held frame effects rather than granting browser-operation authority. These controls predate and are unchanged by this PR.

      Resilience and Maintainability Implications

      • observed — The existing 8 MiB socket-buffer guard remains, and the producer retains its bounded dropping queue with acknowledgement release for dropped frames. The new pending slot replaces stale frames instead of growing a stream-side backlog.
      • inferred — Disconnect or write failure exits the scoped stream lifecycle. Existing finalizers clear the settle timer, disconnect viewer control and release held input, remove viewer membership, stop the screencast, and detach its CDP session. This provides containment even though individual retained frame acknowledgements are not explicitly drained during teardown; exact partial-write timing remains unverified.
      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Linked Issues checkPassedIssue #20283 requires bounded frame backlog, prompt non-frame delivery, producer acknowledgements for discarded frames, and preserved authorization and control ownership. ServerBrowserStream now kee…
      Out of Scope Changes checkPassedThe diff changes only ServerBrowserStream and its focused test. The implementation removes the obsolete 64-frame limit and supports the linked issue's WebSocket scheduling behavior. The type alias a…
      Title checkPassedThe title is concise, specific, and accurately describes the main server fix: browser control replies no longer wait behind obsolete frames on slow links.
      Description checkPassedThe description clearly explains the problem, fix, scope, trade-off, issue link, verification steps, observed results, and agent attribution. It uses different headings from the template and does not …
      Full details: Linked Issues check

      Explanation

      Issue #20283 requires bounded frame backlog, prompt non-frame delivery, producer acknowledgements for discarded frames, and preserved authorization and control ownership. ServerBrowserStream now keeps one in-flight frame and one newest pending frame, acknowledges superseded frames, sends non-frame outputs directly, and retains the existing authentication and canOperate checks. The new test verifies probe ordering, dropped-frame acknowledgements, and delivery of the newest pending frame after the viewer acknowledgement. The issue makes image sizing and adaptive resolution contingent on maintainer agreement, so their omission is not an unmet requirement here.

      Full details: Out of Scope Changes check

      Explanation

      The diff changes only ServerBrowserStream and its focused test. The implementation removes the obsolete 64-frame limit and supports the linked issue's WebSocket scheduling behavior. The type alias and test are directly related support changes. No unrelated client, contract, authorization, or image-resolution changes are present.

      Full details: Description check

      Explanation

      The description clearly explains the problem, fix, scope, trade-off, issue link, verification steps, observed results, and agent attribution. It uses different headings from the template and does not provide an explicit maintainer approval reference, but it is otherwise substantially complete.

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.
    4. juliusmarminge merged this7c68c7d

    5. juliusmarminge closed this

Sign in to join this conversation.