Skip to content

fix(studio): a scene edit swaps in place and a far scene mounts for selection in a sealed preview - #8162

Merged
miguel-heygen merged 4 commits into
mainfrom
fix/studio-sealed-scenes
Nov 20, 2026
Merged

miguel-heygen merged 4 commits into
mainfrom
fix/studio-sealed-scenes

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What

In a sealed Studio preview, an edit inside one scene of a long film now swaps that scene in place, and selecting an element in a scene that is not mounted mounts it first, as in an unsealed preview. Before, every such edit reloaded the whole film, and selecting an element in a far scene found nothing.

Why

Studio swapped scenes, held them mounted, and marked them stale by reaching into the preview frame's window and document, which a sealed frame does not allow. A sealed preview fell back to a full reload for each edit and never held the scene a selected element lives in. This is one of the remaining writers to move onto the editing port before Studio's preview can run sealed by default.

Related work

Stacked on #8158 (a script edit re-runs in place). Same pattern as the earlier sealed preview units: the frame-side logic lives in core, Studio's unsealed path calls the same code where it can reach the frame, and the sealed path sends one editing port request and reloads when the reply says it did not apply.

How

  • New editing port request kinds hold-scenes, swap-scenes and mark-scenes-stale, in core/runtime/editing/scenes.ts.
  • swap-scenes carries the rebuilt preview document Studio fetched from its own server, the same document a full reload would load, and a deadline; the frame aborts a swap that outlasts it. The frame answers { swapped: true } or { swapped: false, reason }; Studio accepts only exactly { swapped: true }, and anything else, no answer included, reloads the film. The page is host-sourced composition text: Studio fetches it from its own preview server, it is size-capped, it runs only inside the sealed frame, and it is never taken from a frame message.
  • hold-scenes waits until the runtime has mounted the named scenes. Selecting an element in a sealed preview now holds its scenes before asking the frame for the element.
  • Marking scenes stale moves to core and is shared: Studio calls it on a frame it can reach, and sends mark-scenes-stale to a sealed one.
  • The frame refuses unknown fields, more than 256 scene names or files, a document over 50,000,000 characters, and a deadline over a minute.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

fails without the fix: packages/studio/src/player/sceneSwap.sealed.test.ts ("swaps a sealed preview's scenes from the document Studio fetched") fails on the base, where a sealed preview has no scene swap and every edit reloads the film. The same file checks that a refusal, no answer, or a reply with an extra field makes the film reload, that nothing is sent once a newer edit superseded the fetch, and that stale marks go through the frame. packages/studio/src/utils/sceneHold.sealed.test.ts fails on the base, where a sealed preview's scenes are never held. packages/core/src/runtime/editing/scenes.test.ts covers the frame side: the hold waits for the mount, a runtime refusal comes back as data, an overdue swap is aborted, stale marks clear the right hashes, and the parsers refuse extra fields and unbounded input. editingAgent.test.ts sends a hold and a swap through the real port. The existing sceneSwap.test.ts case for an opaque frame now expects a swap.

Before

Studio from main (4a11e46c), built with the preview sealed, on a 12 s film of three scenes (each a sub-composition). With the playhead at 00:06 in scene 2, scene 2's file is saved with a new title and colour. The whole film reloads: one new preview document loads, and the edit shows 428 ms after the save. The restore seek puts the playhead back at 00:06.

Before: a scene edit in a sealed preview on main

After

The same steps at this branch (5208512d): only scene 2 is swapped in place. No preview document loads, the edit shows 104 ms after the save, and the playhead stays at 00:06.

After: the same scene edit on this branch

What I measured

Measured on the whole stack (scene swap, live retime, gesture hold together) after building core so Studio reads it: core 191 tests in the touched files plus the new port test, Studio 311 tests across 21 files (scene swap and hold, live retime including the real-GSAP tests, timing sync, gesture holds, shadow reload and retry, undo history, selection and drafts); core, core runtime and Studio type checks pass, and the subpaths check verifies the new export. With the frame answering before its scenes mount, the hold parser taking extra fields, the sealed swap refused (the base), a swap reply with an extra field accepted, the sealed stale marks dropped, or no sealed hold (the base), the matching test fails each time.

What I did NOT exercise

Selecting an element in a far scene in a real sealed Studio session: selection in a sealed preview is broken on main right now (being fixed separately). The captures above cover the scene swap only. The selection hook's call order (hold, then find) is covered by reading, not by a test of the hook.

@eddy-heygen eddy-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(Eddy's agent) Reviewed by Eddy's Claude agent at commit 88dca71.

Verdict: comment only, not approved (stacked PR, and lint is failing at this head). No blocker found in this PR's own diff.

Summary. The PR adds three request kinds to the editing port a sealed preview frame serves to its parent editor: hold scenes, mark scenes stale, swap scenes. The editor fetches the rebuilt preview document from its own preview server and sends it to the sealed frame to swap edited scenes in place; anything other than exactly { swapped: true } makes the editor reload the whole film. The review was done at 24df97c; the head then moved in a restack, and I compared the two: this PR's own diff is identical file for file. The port handshake and sender check are unchanged, the new requests require an exact key set and are bounded (packages/core/src/runtime/editing/scenes.ts:54-70), and nothing from the frame's reply is executed, inserted as markup or used as a path (packages/studio/src/player/sceneSwap.ts:117-120, which I read myself).

Blockers

None in this PR's own diff.

Non-blockers

  1. packages/studio/src/player/sceneSwap.ts:129: a sealed preview whose film has no scene windows now fetches and posts the whole preview document, gets a refusal, and only then reloads, on every edit (up to 5 tries while the file keeps changing). The end state is correct; the edit loop is slower. Learning once per frame load that the frame cannot swap would avoid it.
  2. packages/studio/src/player/sceneSwap.ts:110: the sealed swap drops the editor's cancel signal and sends the full timeout rather than the time left, so a superseded swap keeps running in the frame and can force an avoidable full reload. Both cases end in a correct reload.
  3. packages/core/src/runtime/editing/scenes.test.ts:88: the refusal tests do not cover the upper bounds (document size, deadline over a minute, name count and length).

CI: at this head 7 checks pass, 6 fail, 2 pending, 3 skipped. I read the failing lint job's log: one lint error, "Unsafe usage of optional chaining"; the log does not name the file. Every PR in this stack fails the same way since the restack, so it most likely comes from a lower branch, but I could not confirm which file from the log. The workflow that runs type checks and unit tests only triggers for pull requests based on the default branch, so this PR's own new tests have not been run by CI.

How this was reviewed: a code-review pass and a security-review pass by a reviewer agent in an isolated checkout of 24df97c; I compared that commit with the current head and read the cited swap code myself. Nothing was built or run.

@miguel-heygen
miguel-heygen force-pushed the fix/studio-sealed-scenes branch from 88dca71 to c66fb25 Compare November 18, 2026 09:27
@miguel-heygen
miguel-heygen force-pushed the fix/studio-sealed-soft-reload branch from b9def7d to 2623310 Compare November 18, 2026 11:50
@miguel-heygen
miguel-heygen force-pushed the fix/studio-sealed-scenes branch from c66fb25 to 9cee4cc Compare November 18, 2026 11:50
@miguel-heygen
miguel-heygen force-pushed the fix/studio-sealed-soft-reload branch from 2623310 to 8943bc0 Compare November 18, 2026 12:36
@miguel-heygen
miguel-heygen force-pushed the fix/studio-sealed-scenes branch from 9cee4cc to f72fee8 Compare November 18, 2026 12:36
@miguel-heygen
miguel-heygen force-pushed the fix/studio-sealed-soft-reload branch from 8943bc0 to 2052ab1 Compare November 18, 2026 13:08
@miguel-heygen
miguel-heygen force-pushed the fix/studio-sealed-scenes branch from f72fee8 to 2539c18 Compare November 18, 2026 13:08
@miguel-heygen
miguel-heygen force-pushed the fix/studio-sealed-soft-reload branch from 2052ab1 to bd2430c Compare November 18, 2026 16:17
@miguel-heygen
miguel-heygen force-pushed the fix/studio-sealed-scenes branch 3 times, most recently from 6fc7a25 to 4791316 Compare November 18, 2026 19:53
Base automatically changed from fix/studio-sealed-soft-reload to main November 18, 2026 22:00
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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

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

Quarantined, measured but not gated (0)

Unstable (1)

  • seqab-none-center-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@miguel-heygen
miguel-heygen force-pushed the fix/studio-sealed-scenes branch from 4791316 to 34b2647 Compare November 18, 2026 22:14
# Conflicts:
#	packages/core/src/runtime/editingAgent.test.ts
#	packages/core/src/runtime/editingAgent.ts
#	packages/core/src/runtime/editingPort.test.ts
#	packages/core/src/runtime/editingPort.ts

@eddy-heygen eddy-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(Eddy's agent) Re-reviewed by Eddy's Claude agent at commit 5208512 (the PR is now based on the default branch; full diff reviewed in an isolated checkout, core read by me).

Verdict: comment only for now; no blocker found in the code. One check on this PR is failing (the captures check on the PR description), so I am not approving yet; I will approve once it passes.

Summary. A sealed preview can now swap edited scenes in place, hold scenes for selection and mark scenes stale, through three new request kinds on the editing channel between the editor and the sealed frame. The editor fetches the rebuilt preview document from its own preview address and posts it into the frame.

Blockers

None in the code.

What I checked

  • What the editor accepts back from the frame (packages/studio/src/player/sceneSwap.ts:110-123): only an answer that is exactly "swapped: true" with no other key. Anything else, including no answer, throws, and the caller reloads the whole film. The frame's stated reason is used only as a truncated string in an error message. Answers to the hold and mark-stale requests are discarded. So an answer from the frame cannot make the editor do more than reload.
  • What the frame accepts (packages/core/src/runtime/editing/scenes.ts:54-70): the three kinds are registered in the same parser table as the existing kinds, with exact key sets and bounds on document size, timeout, and the count and length of names and files. The handshake and sender check are untouched.
  • What is sent into the frame: the same document a full reload would load, fetched from the editor's own preview address with a cache-buster; no value from the frame enters that address.
  • The merge with the default branch: the scene requests sit beside the default branch's newer handling, and the request-kind lists in code and tests agree.
  • An unsealed preview keeps calling the frame's swap function directly, as before.

Non-blockers (all three still open from my earlier review)

  1. A sealed film that cannot swap still fetches and posts the whole document on every edit before reloading. Learning once per frame load that it cannot swap would avoid the extra fetch and large message.
  2. The sealed swap ignores the editor's cancel signal, so a swap superseded by a newer edit keeps running in the frame and ends in an avoidable full reload. The outcome is correct.
  3. The refusal tests cover only one upper bound (file count); the document size cap, the timeout cap, the name count and the name and file length caps are untested.

For the author to check in a real sealed session

  • The existing "would this swap replace a node under a live gesture" check is skipped when the frame's document is unreachable. A sealed preview used to reload at that point and now swaps. I did not trace how gestures are protected under the seal.

CI: my own count at this head: 88 passing, 1 failing, none pending, 12 skipped. The failing check is "Studio and player captures": its log says the PR description's Before and After sections have no image or video. It runs none of this PR's code. The runtime and studio test jobs ran the new test files and passed.

# Conflicts:
#	packages/core/src/runtime/editingPort.ts

@eddy-heygen eddy-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(Eddy's agent) Re-review by Eddy's Claude agent at commit cbcc013.

Verdict: approve.

The default branch was merged in with one import conflict resolved. I compared every file of this PR against the head I reviewed before (5208512): all fifteen are unchanged, so my earlier read stands. The conflict with the default branch is gone and the captures check passes.

CI: 89 pass, 11 skipped, none failing or pending.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 012f263 Nov 20, 2026
100 checks passed
@miguel-heygen
miguel-heygen deleted the fix/studio-sealed-scenes branch November 20, 2026 02:14
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