Skip to content

fork: agent recordings keep a steady frame rate and fail fast on a hidden tab - #55

Merged
3mdistal merged 3 commits into
fork/mainfrom
fix/preview-recorder-frames
Nov 14, 2026
Merged

3mdistal merged 3 commits into
fork/mainfrom
fix/preview-recorder-frames

Conversation

@3mdistal

@3mdistal 3mdistal commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Problem

Agents record the preview with preview_recording_start and preview_recording_stop, and Alice cuts those videos into clips for review docs by timestamp. A recording of a mostly still page came out at a few frames a second, with long stretches holding no frame at all: her recent agent recordings averaged 0.5–5 fps, with gaps of up to 55 seconds. A cut at a given second landed on whatever frame came before it, so clips around a click showed the wrong moment or froze.

Separately, a recording started on a tab T3 couldn't draw, such as while T3's window was minimized, hung until the request timed out after 15 seconds, with no hint why. The hung start also held the tab's capture lock, so the tab's snapshots and later recordings waited behind it until the tab painted again.

Approach

A steady frame rate. The recorder gets frames from Chromium's screencast, which sends one only when the page changes. The server paints each one into a canvas in a hidden encoder page, and a MediaRecorder records the canvas's stream. That stream produces a video frame only when the canvas is painted, so a still page produced none. The encoder now repaints its newest frame on a timer at the recording's frame rate (30 or 60 fps, from settings). A still stretch records as repeated frames, so a time in the file matches the time on the clock. The click ring, which had its own timer, now fades on those repaints. If the MediaRecorder stops on its own, as on an encoding error, the repaint timer stops with it.

The newest frame wins. Each screencast frame is decoded on its own, and a large frame can finish decoding after a smaller, newer one. The encoder painted whichever finished last, so an older look could replace the page for a moment, like a menu that seems to reopen after it closed. Each frame now carries the order it arrived in, and one that finishes after a newer one is dropped. I didn't find this flash in Alice's recordings, so this fixes a real race rather than a confirmed cause of what she saw.

A clear failure on a tab that never paints. A recording starts by capturing the tab once, so a stop right away still has a frame to encode. That capture had no time limit. It now waits 5 seconds at most, then fails with this error, which releases the tab's lock:

Recording did not start: the tab painted no frame in 5 seconds. T3 can't draw a tab while its window is minimized or hidden. Show the tab with preview_open, or ask the user to bring T3's window into view, then try again.

The Chrome DevTools Protocol (CDP) has no way to cancel a screenshot request. So the first capture now goes over the recording's own CDP session, which startRecording opens first, instead of the tab's shared one. A failed start already detaches that session, and detaching it rejects the unanswered capture. Without this, each retry on a hidden tab would leave another screenshot pending on the tab's session.

What changed

  • apps/server/src/preview/ServerBrowserPage.ts: the repaint timer (cleared on stop and when the recorder stops on its own) and arrival-order check in recordingEncoderScript, and a new recordingFirstFrame that bounds the first capture.
  • apps/server/src/preview/ServerBrowser.ts: startRecording opens the recording's CDP session first and takes its first frame over it with recordingFirstFrame.
  • apps/server/src/preview/ServerBrowserPage.fork.test.ts: new tests.
  • apps/server/src/preview/ServerBrowser.test.ts: upstream's encoder sandbox gets no-op timer stubs, since its tests feed frames by hand, and one fork: test for a failed first frame.
  • FORK.md: a Patches entry.

What users will notice

These change recording output that users and agents see. I recommend keeping all three.

  • Bigger files. Repeated frames cost bytes: a 5-second take of a still page grew from 101 KB to 121 KB, about 20%. A long recording reaches the existing 50 MB cap a little sooner.
  • More work while recording. The hidden encoder page now paints and encodes every frame for the whole recording, even on a still page. This happens only while a recording runs.
  • A new error for agents, quoted above, instead of a 15-second timeout.

The frame-rate setting itself is unchanged; recordings now actually hold it.

Safety and operations

No persisted data, setting or wire contract changes, so stock T3 still opens the fork's data, and rollback is reverting the commit. The encoder runs in the server's headless Chromium for both server and desktop tabs, so desktop recordings change the same way.

Verification

  • The new ServerBrowserPage.fork.test.ts runs the real encoder script with a fake canvas and fake timers. Each test fails without its fix and passes here:
    • a still page gets 30 repaints in a second at 30 fps (on fork/main: none);
    • a frame that finishes decoding after a newer one is closed and never painted (on fork/main, paint order was [1, 3, 2]: the older frame last);
    • a first capture that never answers is still pending at 4.999 seconds and fails at 5 with the new error (on fork/main there was no limit);
    • after the MediaRecorder stops on its own, a second passes with no repaints (the PR's first commit kept repainting).
  • A new fork: test in ServerBrowser.test.ts fails the new session's first screenshot. It checks that the screenshot went over that session, that the failed start detached it, and that a second start succeeds. It fails on the PR's first commit, where the first frame used the tab's session.
  • On the PC, vp test run passes ServerBrowser.test.ts (49 tests, including the existing recording tests) and the new file (4).
  • In real Chromium (Playwright's 1248 build on the PC), a CDP request that never answers was rejected right away ("Target page, context or browser has been closed") when its session detached, and a fresh session on the same page could still take a screenshot.
  • With real headless Chromium on the PC, a throwaway script outside the repo drove the same encoder the server uses through a still page with a dropdown, three clicks and a snapshot pause. Before: 6.6 fps with a 1.5-second gap. After: 30.1 fps with no gap over 80 ms, and an ffmpeg cut at a set time lands on the right frame. Sending a slow-to-decode frame and then a fast one painted the older frame last in 20 of 20 tries before, and 0 of 20 after.
  • vp run check:changed origin/fork/main on the PC passed format, lint, knip and typecheck (3 packages) on the PR's first commit. For the review follow-up commit, the pre-push format, lint and knip checks passed, and Fork CI runs the typecheck. The test files beside the change pass, except ServerBrowserPage.test.ts, which can't start a browser on the PC because Playwright's pinned Chromium build isn't installed there. This PR doesn't touch that file; Fork CI runs it.
  • Not checked in the desktop app: I didn't touch Alice's running T3. Headless Chromium keeps painting even a frozen tab, so the never-painting case is covered only by the unit test. A tab that paints still gives its first frame in about 40 ms.

A review by Sol (OpenAI's gpt-6.1-sol) found the pending-capture and recorder-stop gaps. Both are fixed in the second commit. It found the other paths sound: normal and size-limit stops clear the timer, a failed start closes the encoder and releases the lock, and the encoder's timer isn't throttled, because Playwright launches its headless Chromium with background throttling off.

Review focus

  • The repaint timer runs for the whole recording. Is steady timing worth the size and CPU cost?
  • Is 5 seconds long enough for a slow but visible tab's first frame?
  • The error text agents see.

Written by Claude Opus 5.5 in Claude Code, running in T3 Code.

🤖 Generated with Claude Code

…dden tab

The recording encoder painted only when a screencast frame or cursor move
arrived, so a still page recorded at a few frames a second with long gaps.
It now repaints the newest frame at the recording's frame rate, and drops a
frame whose decode finishes after a newer one's.

A recording's first capture is now bounded at 5 seconds. A tab T3 cannot
draw used to hold the start, and the tab's capture lock, until the request
timed out; it now fails with an error that says what to do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@3mdistal
3mdistal force-pushed the fix/preview-recorder-frames branch from 528a5aa to b557d3d Compare November 14, 2026 11:24
3mdistal and others added 2 commits November 14, 2026 06:31
…ecorder ends the repaint

Review follow-ups for the steady-frame-rate patch:

- startRecording opens the recording's CDP session before the first frame and captures
  over it. A capture a hidden tab never answers used to stay pending on the tab's shared
  session after the 5 s limit; now the failed start detaches the session, which rejects it.
- The encoder clears its repaint timer when the MediaRecorder stops on its own (an encoding
  error), not only in stop()'s active branch.
- Tests: a failed first frame detaches its own session and a retry starts; a recorder that
  stops on its own stops repainting; the first-frame limit stays pending until 5 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`invoke` without a type parameter succeeds with `unknown`, so `Effect.flip` gave the
test an `unknown` error channel, which the Effect language service rejects in typecheck.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@3mdistal

Copy link
Copy Markdown
Owner Author

Landing this on Alice's word. At 8:29 AM ET on Nov 14, 2026, in the T3 thread "big triage" (7542db79-62fe-4b84-a00b-20de26d78285, message 5b6200d0-528f-43a6-8b18-d704999836ec), she wrote "land all of those". That answered a list of rows waiting on a land word, and its first item was this one, the T3 recorder fix.

At merge time the head is 0cd5f6e. All 17 checks pass, the branch is up to date with fork/main, and no review threads are open.

@3mdistal
3mdistal merged commit 37b243a into fork/main Nov 14, 2026
17 checks passed
@3mdistal
3mdistal deleted the fix/preview-recorder-frames branch November 14, 2026 13:55
3mdistal added a commit that referenced this pull request Nov 21, 2026
…dden tab (#55)

* fork: agent recordings keep a steady frame rate and fail fast on a hidden tab

The recording encoder painted only when a screencast frame or cursor move
arrived, so a still page recorded at a few frames a second with long gaps.
It now repaints the newest frame at the recording's frame rate, and drops a
frame whose decode finishes after a newer one's.

A recording's first capture is now bounded at 5 seconds. A tab T3 cannot
draw used to hold the start, and the tab's capture lock, until the request
timed out; it now fails with an error that says what to do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fork: a recording's first frame uses its own session, and a stopped recorder ends the repaint

Review follow-ups for the steady-frame-rate patch:

- startRecording opens the recording's CDP session before the first frame and captures
  over it. A capture a hidden tab never answers used to stay pending on the tab's shared
  session after the 5 s limit; now the failed start detaches the session, which rejects it.
- The encoder clears its repaint timer when the MediaRecorder stops on its own (an encoding
  error), not only in stop()'s active branch.
- Tests: a failed first frame detaches its own session and a retry starts; a recorder that
  stops on its own stops repainting; the first-frame limit stays pending until 5 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fork: type the failed recording start in its test

`invoke` without a type parameter succeeds with `unknown`, so `Effect.flip` gave the
test an `unknown` error channel, which the Effect language service rejects in typecheck.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
3mdistal added a commit that referenced this pull request Nov 21, 2026
…dden tab (#55)

* fork: agent recordings keep a steady frame rate and fail fast on a hidden tab

The recording encoder painted only when a screencast frame or cursor move
arrived, so a still page recorded at a few frames a second with long gaps.
It now repaints the newest frame at the recording's frame rate, and drops a
frame whose decode finishes after a newer one's.

A recording's first capture is now bounded at 5 seconds. A tab T3 cannot
draw used to hold the start, and the tab's capture lock, until the request
timed out; it now fails with an error that says what to do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fork: a recording's first frame uses its own session, and a stopped recorder ends the repaint

Review follow-ups for the steady-frame-rate patch:

- startRecording opens the recording's CDP session before the first frame and captures
  over it. A capture a hidden tab never answers used to stay pending on the tab's shared
  session after the 5 s limit; now the failed start detaches the session, which rejects it.
- The encoder clears its repaint timer when the MediaRecorder stops on its own (an encoding
  error), not only in stop()'s active branch.
- Tests: a failed first frame detaches its own session and a retry starts; a recorder that
  stops on its own stops repainting; the first-frame limit stays pending until 5 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fork: type the failed recording start in its test

`invoke` without a type parameter succeeds with `unknown`, so `Effect.flip` gave the
test an `unknown` error channel, which the Effect language service rejects in typecheck.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
3mdistal added a commit that referenced this pull request Nov 26, 2026
Upstream v0.1.12 (pingdotgg#42445) repaints the newest frame of an agent's recording at
the recording's frame rate, which is what this patch used to add, so the fork
cut it to what upstream still lacks: upstream's repaint timer stops when the
recording stops or grows too large, but not when the MediaRecorder stops on
its own, as on an encoding error. The recorder's onstop now clears it too.

The test that a still page repaints at the frame rate went with the cut;
upstream's own tests cover it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
3mdistal added a commit that referenced this pull request Nov 26, 2026
Upstream v0.1.12 (pingdotgg#42445) repaints the newest frame of an agent's recording at
the recording's frame rate, which is what this patch used to add, so the fork
cut it to what upstream still lacks: upstream's repaint timer stops when the
recording stops or grows too large, but not when the MediaRecorder stops on
its own, as on an encoding error. The recorder's onstop now clears it too.

The test that a still page repaints at the frame rate went with the cut;
upstream's own tests cover it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
3mdistal added a commit that referenced this pull request Nov 26, 2026
Upstream v0.1.12 (pingdotgg#42445) repaints the newest frame of an agent's recording at
the recording's frame rate, which is what this patch used to add, so the fork
cut it to what upstream still lacks: upstream's repaint timer stops when the
recording stops or grows too large, but not when the MediaRecorder stops on
its own, as on an encoding error. The recorder's onstop now clears it too.

The test that a still page repaints at the frame rate went with the cut;
upstream's own tests cover it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
3mdistal added a commit that referenced this pull request Nov 26, 2026
Upstream v0.1.12 (pingdotgg#42445) repaints the newest frame of an agent's recording at
the recording's frame rate, which is what this patch used to add, so the fork
cut it to what upstream still lacks: upstream's repaint timer stops when the
recording stops or grows too large, but not when the MediaRecorder stops on
its own, as on an encoding error. The recorder's onstop now clears it too.

The test that a still page repaints at the frame rate went with the cut;
upstream's own tests cover it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
3mdistal added a commit that referenced this pull request Nov 26, 2026
Upstream v0.1.12 (pingdotgg#42445) repaints the newest frame of an agent's recording at
the recording's frame rate, which is what this patch used to add, so the fork
cut it to what upstream still lacks: upstream's repaint timer stops when the
recording stops or grows too large, but not when the MediaRecorder stops on
its own, as on an encoding error. The recorder's onstop now clears it too.

The test that a still page repaints at the frame rate went with the cut;
upstream's own tests cover it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
3mdistal added a commit that referenced this pull request Nov 30, 2026
Upstream v0.1.12 (pingdotgg#42445) repaints the newest frame of an agent's recording at
the recording's frame rate, which is what this patch used to add, so the fork
cut it to what upstream still lacks: upstream's repaint timer stops when the
recording stops or grows too large, but not when the MediaRecorder stops on
its own, as on an encoding error. The recorder's onstop now clears it too.

The test that a still page repaints at the frame rate went with the cut;
upstream's own tests cover it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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