Skip to content

fix(studio): keep the editor responsive when a preview asks for paused frames - #8943

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/paused-frame-asks-bound
Nov 27, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/paused-frame-asks-bound

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

Studio now reads a paused-frame decode message only when its asks list has no gaps and at most PAUSED_FRAME_SOURCES (4) entries. A longer list is dropped before any entry is read. The runtime checks the same limit before it sends, so a decode naming more than four sources still fails at once with "Preview decode over budget".

Why

parsePausedFrameAsk accepted any array and then ran map and every over its declared length. A message can declare a length of up to 2^32-1 with no entries behind it, and walking that kept the editor busy for minutes. The four-source limit was checked by the host only after the parse finished.

Related work

Uses the isMessageList check the other preview-frame readers use (packages/core/src/runtime/protocol.ts).

How

  • parsePausedFrameAsk: Array.isArray(data.asks) becomes isMessageList(data.asks, PAUSED_FRAME_SOURCES). This checks the length first and then looks for gaps in at most four slots.
  • portPausedVideoProvider.decode (runtime side): throws "Preview decode over budget" when it gets more than four requests. Before this change, the host sent that reply after the decode reached it. With the parser now dropping such a message, a decode over the limit would otherwise wait with no reply.
  • pausedFrameHost.decode: drops its now-unreachable > PAUSED_FRAME_SOURCES branch and keeps the empty-list reply.
  • I checked every other message listener and port handler in packages/studio/src (15 in all). None walks a list from the frame before bounding it.

Test plan

  • Unit tests added/updated:
    • pausedFrames.test.ts: a decode of 1 to 4 sources is read; a declared length of 2^32-1, five sources and a list with a gap are each refused in under a second; the runtime fails a five-source decode without posting anything.
    • pausedVideoProvider.test.ts: five sources and a 2^32-1 list reach no decode, and the port still answers a suspend straight after.
  • fails without the fix: on main's pausedFrames.ts the core file did not finish within 90 s (the parser walking the declared length). On its own, fails a decode of more sources than Studio reads without asking timed out at 5 s with no reply.
  • With the change: pausedFrames.test.ts 5/5 and the four pausedVideoProvider* / pausedVideoDecoder test files 42/42, each 3 runs in a row. editingPort, editingAgent and pausedVideoFrames tests 220/220. Studio tsc --noEmit is clean, and oxlint and oxfmt are clean on the changed files.
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

No visible change

Message parsing and tests only; no .tsx, .css or .html changed. A valid paused-frame decode behaves as before.

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 90 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Quarantined, measured but not gated (0)

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is clean at 5a25a46. I am not approving yet because two Windows checks are red and I cannot tie them to main. Approval follows green.

What I checked:

  • Bound before the walk: pausedFrames.ts:89 now uses isMessageList(data.asks, PAUSED_FRAME_SOURCES). refuseMessageList checks length > max first and then looks for holes in at most 4 slots, so a declared length of 2^32-1 is refused before map/every run.
  • Refusal is explicit for a real ask: pausedFrames.ts:160 throws "Preview decode over budget" in portPausedVideoProvider.decode before anything is posted. A hostile frame message is dropped by the parser, like the other readers. pausedVideoProvider.ts:139 still replies "failed" for an empty list.
  • Tests cover both cases: pausedFrames.test.ts has one test for the sparse list (hole) and 2^32-1, plus the over-cap list (5 sources), each under 1 s. A separate test covers the runtime throw with no post. pausedVideoProvider.test.ts checks that over-cap and 2^32-1 asks reach no decode and that suspend is still answered.
  • "fails without the fix:" is in the body and names real tests at this head.
  • Siblings: the studio message readers in previewChannel.ts already use isMessageList. I found no other unbounded frame-message reader.

Non-blocking, for a follow-up: packages/studio/src/hooks/useConsoleErrorCapture.ts:106 does raised.map(String) on window[STUDIO_PREVIEW_ERRORS], an array the composition itself can set. It is a same-origin read, not a message, but a sparse array there is the same shape of problem.

CI at 5a25a46: the checks finished with 2 red, "Tests on windows-latest: engine-cli-3" and "Tests on windows-latest". The failing tests are engine/src/services/chunkEncoder.test.ts and engine/src/utils/ffprobe.test.ts (ffprobe exit code 1). This PR touches only core/runtime/editing and studio/player/lib. Main's latest Windows run (f00e934) is green, and the other red Windows run (renovate branch) failed different tests. So I cannot call it not-this-PR or a flake. A rerun that goes green, or a link to the cause on main, clears it.

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Thanks. On the two points:

  • useConsoleErrorCapture.ts:106: that line runs only for a frame that is not opaque (previewFrameOpaque returns early at :87), so the composition shares Studio's own thread there. Script that can set window[STUDIO_PREVIEW_ERRORS] can already keep that thread busy directly, so a bound on this read would not change what the page can do. I'm leaving it as is. The opaque path (readSealedErrors) goes through previewConsoleErrors, which is bounded and accepts strings only.
  • Windows: the three failures are 5 s timeouts in chunkEncoder.test.ts and ffprobe.test.ts, all finishing at 22:10:03. Nothing in the engine imports the changed files. I'll re-run the failed jobs once the run completes and post the result here.

@vanceingalls vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 5a25a46. The code was clean on my earlier pass. The decode-ask list is bounded by isMessageList(data.asks, PAUSED_FRAME_SOURCES) before any iteration, an over-cap ask is refused explicitly, and tests cover the sparse, 2^32-1 and over-cap cases. The two red Windows checks (engine ffprobe/chunkEncoder tests, files this PR does not touch) passed on a rerun of the failed jobs, so they were flakes. Every check is now green at this head. Follow-up, not blocking: useConsoleErrorCapture.ts:106 does raised.map(String) on a composition-settable array without a bound.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 5d0d994 Nov 27, 2026
114 of 116 checks passed
@miguel-heygen
miguel-heygen deleted the fix/paused-frame-asks-bound branch November 27, 2026 00:22
@jrusso1020 jrusso1020 mentioned this pull request Nov 27, 2026
4 of 5 tasks
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.

2 participants