Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): reduce dropped frames in agent preview recordings #34131

Closedjuliusmarmingewants to merge 6 commits intomain fromrefs/pull/34131/headopened View on GitHub

juliusmarmingecommented

Agent preview recordings dropped frames because each Page.screencastFrame ack waited for the encoder page to decode the frame. Chrome stops sending screencast frames while too many are unacked, so the recording's frame rate fell to the encoder's decode speed. The change acks every frame as soon as it arrives. Decoding is serialized through one delivery loop that keeps only the newest pending frame, so frames that are already stale are skipped instead of queued. recordingStop now waits for that loop to finish before stopping the MediaRecorder, so the newest frame is still encoded. The encoder page also replaces per-byte atob/charCodeAt conversion with Uint8Array.fromBase64, which the pinned Chrome 157 preview browser supports. Takeover: merged origin/main into the PR head as a merge commit. The only conflict was the test makeSession helper, resolved to main's version, which already has the PR's variadic emit. The author's approach and commits are unchanged; my only edit rewords a test comment that named a specific Chrome version. Both new tests fail against main's ServerBrowser.ts and pass on the branch. Note: the PR's own branch fix/issue-24979 had moved on origin (now 48009761918345a044f4aa81c94fdb4f777706f6, not the brief's 3ba653f), so the push was refused as a non-fast-forward and this work is on factory/pr-25075-a2. The linked issue also reports blurry output, which this change does not address.

Supersedes https://git.cafe/pingdotgg/t3code/pulls/25075. The change is @juliusmarminge's; their commits are kept.

Reproduction on main

Use the test page attached to #24979, serving index.html locally. In T3 Code, have an agent open it with preview_open and resize the Browser viewport to 1600×900 at DPR 2. Start an agent recording with preview_recording_start, invoke runTest() through preview_evaluate, and stop with preview_recording_stop after its 2-second idle, 3-second animation, 3-second scroll, and 2-second idle sequence. Repeat on main and the PR, compare the exported videos, and optionally use the attached decode.py to count surviving barcode frame IDs; the PR should preserve more distinct moving states. These steps were read from the issue and PR, not executed.

Evidence

Being captured: before and after in the real app. This section is filled in before the pull request can merge.

Tests

vp test run src/preview/ServerBrowser.test.ts src/preview/ServerBrowserPage.test.ts (apps/server): 89 passed. Same two new tests with main's ServerBrowser.ts swapped in: both failed as expected, then the branch version was restored. vp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and tests (3 files, 91 tests) all passed.

Not in this change

  • Blurry recording output reported in the linked issue (quality/bitrate) is not addressed by this change.
  • ServerBrowserPage.ts still uses per-byte atob conversion for PNG decoding at line ~482; it is not on the recording hot path.
  • Did not inspect what commit 4800976 on origin/fix/issue-24979 contains; it postdates the PR head given in the brief.

AI-assisted; verified with the tests and tools listed above.

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

    2. Approvability

      Verdict: Approved at ea58c3c

      Macroscope's review found this PR approvable — Preview recordings acknowledge frames promptly and keep only the latest pending frame while decoding, reducing encoder backpressure. The change is confined to recording delivery and preserves recording settings and attachment-size safeguards.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Baseline: b883156 · PR result: ea58c3c · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      Recording now acknowledges screencast frames immediately and serializes encoder delivery while retaining only the newest pending frame. Stopping waits for delivery to drain. The encoder uses Uint8Array.fromBase64 to decode frame data.

      Changes: Recording frame delivery and shutdown

      Layer / File(s)Summary
      Frame delivery and recording shutdown
      apps/server/src/preview/ServerBrowser.ts, apps/server/src/preview/ServerBrowserPage.ts, apps/server/src/preview/ServerBrowser.test.ts
      Frames are acknowledged immediately and delivered to the encoder in sequence, with newer pending frames replacing older ones. Recording shutdown waits for delivery to drain. The encoder uses Uint8Array.fromBase64, and tests cover acknowledgement timing, stale-frame skipping, and stop-time frame delivery.

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix

      Possibly related issues

      • pingdotgg/t3code#26683 — The issue reports low frame rates for large screencasts; this change modifies acknowledgement timing and bounds pending frame delivery.
      • pingdotgg/t3code#24979 — The issue reports dropped frames and delayed acknowledgements; this change modifies acknowledgement and frame-decoding behavior.
      • pingdotgg/t3code#30735 — The issue reports an unbounded screencast backlog; this change retains only the newest pending frame in the recording delivery loop.

      Possibly related PRs

      • pingdotgg/t3code#25075 — Changes the same screencast delivery path, including immediate acknowledgements, newest-frame retention, draining before stop, and native base64 decoding.
      • pingdotgg/t3code#33931 — Coordinates final-frame capture with screencast draining during recording shutdown.
      • pingdotgg/t3code#31555 — Changes recording stop coordination and waiting for in-flight frames in ServerBrowser.

      Suggested labels: bugfix, size:M

      Suggested reviewers: macroscopeapp

      Merge Risk: Minimal · up to ea58c

      This change acknowledges screencast frames immediately to reduce dropped frames in recordings, and stopping waits for pending delivery to finish. No concrete merge-blocking risk was identified.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: reducing dropped frames in agent preview recordings.
      Description checkPassedThe description explains the problem, implementation, tests, reproduction steps, and out-of-scope items. It does not provide explicit scope approval evidence, and real-app evidence is still pending, b…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Description check

      Explanation

      The description explains the problem, implementation, tests, reproduction steps, and out-of-scope items. It does not provide explicit scope approval evidence, and real-app evidence is still pending, but the core required information is present.

      Finishing Touches

      Generate docstrings

      • Commit to this branch
      • Create a new PR
      Generate unit tests (beta)

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

      Usage-based review receipt

      Note

      This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between b883156e269de2002873aebdef6019f336b687a7 and ea58c3cbb930bbaed57a78cf44b13023d95990b3.

      Files selected for processing: 3

      • apps/server/src/preview/ServerBrowser.test.ts
      • apps/server/src/preview/ServerBrowser.ts
      • apps/server/src/preview/ServerBrowserPage.ts

      Limit details: You’ve used all 10 included reviews currently available.

    5. The automated pipeline stopped on this pull request and will not merge it:

      in the real app the problem is still there, and the rework changed nothing:

      Not reworkable as designed: no code changed and nothing pushed. The reviewer is right that the problem persists, and the cause is that the fix targets the wrong bottleneck. I measured the real pipeline with a Playwright harness using the server's pinned Chrome 157 (chrome-headless-shell) and the branch's actual recordingEncoderScript at 1600x900, DPR 2 (frames about 1 MB JPEG, 1.5 MB base64). Per frame, moving the base64 string into the encoder page costs 52-87 ms (raw CDP Runtime.evaluate and callFunctionOn cost the same 84-86 ms as Playwright evaluate, so a different call path will not help), decode costs 29-34 ms and drawImage 6-10 ms. Frames reaching the encoder during the run: main's behaviour (ack after encoding) 36 of 39 screencast frames; this branch (immediate ack, keep newest pending) 24 and 35 of 103 and 131 screencast frames; sending every frame concurrently starves Chrome's screencast itself (36-37 frames sent, 33-39 delivered). Lowering JPEG quality from 90 to 70 (996 KB to 676 KB) delivered about 25 frames, within this VM's run-to-run noise. So the immediate ack only makes Chrome produce frames the keep-newest loop then discards; any pipeline that round-trips every 3200x1800 frame from Chrome through the server back into an encoder page is capped by per-frame transfer and decode cost (about 10 fps here). A real fix needs a different recording architecture, which is the maintainer's call: record inside Chrome via native tab capture (as https://git.cafe/pingdotgg/t3code/pulls/8839 did for desktop), encode server-side from the JPEG bytes the server already receives, or cap the captured resolution or size and accept that ceiling. The Uint8Array.fromBase64 swap is a small, valid decode saving but does not address the reported drops. The blurry output (MediaRecorder bitrate assumes a steady frame rate) is also untouched.

      It stays open for a person to finish or close.

    6. tanstack-source added labelsbug

    7. Thanks for this. Main has the change since #36215.

      Compared the full diff with main: this takeover contains the same recording changes as the original PR, and main now provides immediate acknowledgements, newest-pending-frame delivery, draining before stop, and native base64 decoding. Its alternate single-promise representation adds no behavior missing from main.

      Closing as superseded.

    8. juliusmarminge closed this

Sign in to join this conversation.