Skip to content

fix(studio): a sealed move that rewrites no script rebinds in place instead of reloading the film - #8814

Open
miguel-heygen wants to merge 8 commits into
mainfrom
fix/sealed-timing-rebind
Open

miguel-heygen wants to merge 8 commits into
mainfrom
fix/sealed-timing-rebind

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A timeline move or resize whose save rewrites no script now keeps a sealed preview's film loaded, as it already does in a frame Studio can script. Studio asks the frame to re-derive its clip windows from the live timing attributes (a new rebind-timing request), instead of reloading the whole film. A delete made right after the move then lands on the same load and takes the clip out at once.

Why

A sealed preview must give exactly the same output as an unsealed one. After a move that rewrote no script, Studio rebinds the timing in place (applySoftReloadFinalization), which reads the frame's window directly. A sealed frame refuses that read, so the rebind reported failure and Studio fell back to reloadPreview(). The refresh then could not swap scenes on a plain film and reloaded it whole. In a real-app walk (drag a clip past the film's end, then delete it), a sealed film reloaded after the move in 11 of 15 runs and an unsealed one in 0 of 3. A delete sent while that reload ran got no answer from the frame, so the clip stayed drawn until the next load (2 of 5 instrumented sealed runs; 0 of 3 unsealed).

Related work

Follows #8684 (sealed timing patches) and #8719 (sealed clip removal), whose delete this keeps on one load. Same port pattern as live-retime (packages/core/src/runtime/editing/liveRetime.ts:244) and the sealed soft reload (packages/studio/src/utils/gsapSoftReload.ts:238).

How

  • Frame (packages/core/src/runtime/editing/rebindTiming.ts, new): rebind-timing takes one finite, non-negative time and nothing else (validated in editingPort.ts like set-loop-start). It runs the runtime's own finalizeSoftReload under __hfSuppressSceneMutations and answers { rebound: true }. It answers { rebound: false } while a scene swap waits (its own rebind follows, as liveRetime does) or when the runtime has no rebind hook. No page script runs.
  • Studio (hooks/previewTimingPatch.ts, rebindIframeTiming): one owner for "rebind in place, else reload". In a sealed frame the request joins the frame's inOrder queue, behind the move's own timing patches and ahead of any later delete. Anything but { rebound: true } (no answer, a refusal, a runtime without the request) reloads exactly as before. An unsealed frame keeps applySoftReloadFinalization.
  • hooks/timelineTimingSync.ts calls it where it called the unsealed-only rebind.
  • Not changed: timelineTrackVisibility.ts:149 (hiding a track) falls back to a seek, not a reload, when the rebind is refused. That is a separate gap, left for its own change.

Test plan

  • previewTimingPatch.browser.test.ts (real Chrome, unsealed and sealed): a move that rewrites no script hides the moved clip in place with no reload, and a delete right after it leaves the same load.

  • fails without the fix: the test commit, run alone, fails the sealed case (the rebind hides #b, which now starts at 3 s: expected false to be true); the 5 other cases pass.

  • Breaking the frame side (rebind-timing always answers { rebound: false }) fails the sealed case again; the unsealed case still passes.

  • editingAgent.test.ts: the request rebinds, refuses a negative, NaN, missing or extra parameter, and answers { rebound: false } while a swap waits or with no rebind hook. Dropping the swap check fails it.

  • editingAgent.test.ts (189), editingPort.test.ts (13), previewTimingPatch.test.ts, timelineTimingSync.test.ts (29), timelineTimingSync.sealed.test.ts, and the browser test (6) pass. Core and Studio type checks pass.

  • 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

Before and After captures from the real-app walk follow in a comment on this PR.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 — Reload when the live timing patch did not apply. packages/studio/src/hooks/previewTimingPatch.ts:67–70 silently returns on a missing handle and discards the boolean from editPreviewElement(...).drawn. sealedTimingQueue.ts:18–21 then suppresses the reload whenever the separate rebind answers true. That answer only means the frame rebuilt timing from its current attributes. If the live patch missed or was refused, the save can succeed while the frame stays on the old timing. The previous sealed fallback reloaded from disk in this case. Carry the patch result into the rebind decision and test a saved edit whose frame patch was unavailable.

The captures job is red because it found no Before/After evidence in the body or an eligible author comment. Please also name previewTimingPatch.browser.test.ts or its test title directly on the fails without the fix: line. Captures check

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed at 89be938: the patch result now feeds the reload decision.

  • sealedTimingQueue.ts owns a per-frame record of live timing patches that did not land (noteTimingPatch). patchSealedTiming returns the frame's drawn answer (false when no handle was found or the edit was refused), and the open path records a missing element or a throw. rebindIframeTiming consumes that record: after a missed patch it reloads the saved file instead of rebinding, in both modes (the open path had the same gap: a missed findTimelineElementInIframe was followed by a successful rebind).
  • fails without the fix: packages/studio/src/hooks/previewTimingPatch.browser.test.ts, "a move whose live patch found no clip reloads the saved file, in a %s preview", committed alone in ca471ae, fails in both modes (expected +0 to be 1); with the fix it passes. Making noteTimingPatch a no-op fails both again.
  • The original fail-first evidence for this PR, named directly: previewTimingPatch.browser.test.ts, "a move that rewrites no script rebinds in place, and a delete right after it leaves the same load, in a sealed preview", fails at the test commit c7f7d12 alone (the rebind hides #b, which now starts at 3 s: expected false to be true). The description is kept as first posted, so the test is named here.
  • Fallow: the import cycle at c16281b's parent was removed by moving the queue into sealedTimingQueue.ts; fallow audit is clean locally.

Captures: posted separately as their own comment once the real-app walk finishes.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The missed-patch path now requests a reload. A separate playback regression remains.

P2 — A queued rebind can rewind a newer scrub. packages/studio/src/hooks/timelineTimingSync.ts:94–96 captures the playhead time before the queued callback runs. sealedTimingQueue.ts:24–29 sends that older time after waiting for the earlier patch, and the frame seeks to it. A scrub while that patch is outstanding can therefore be undone. The previous head reproduced this in Chrome, and a focused check of this head confirms the same queue behavior. Preserve the frame’s current playhead or guard the rebind against a newer seek. Cover a scrub while the patch is awaiting its reply.

The captures check is still red at this head. The current fails without the fix: line also still refers to the test indirectly. Please put previewTimingPatch.browser.test.ts on that line. Captures check

— tai (automated review)

@miguel-heygen

miguel-heygen commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

No visible change

The film looks the same before and after in both modes: the change is in when the frame catches up, not what it draws. A move that rewrites no script used to send a sealed film to a full reload, which Studio draws behind its shadow preview, so there is no frame to capture. The proof is the browser test below, which drives Studio's own timing sync against a real sealed frame. A real-app walk (Desktop linked to this branch's packages, Linux, a clip dragged past the film's end, then deleted) gives the same picture and timings on this branch and on main, so it does not separate the two; it is not offered as evidence of the fix.

fails without the fix: packages/studio/src/hooks/previewTimingPatch.browser.test.ts, "a move that rewrites no script rebinds in place, and a delete right after it leaves the same load, in a sealed preview" (test commit c7f7d12 alone: the rebind hides #b, which now starts at 3 s: expected false to be true).

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The rebind now reads the playhead when its queued callback runs. A focused comparison sent the old time at the previous head and the newer scrub time at this head. The captures check passed.

The remaining requirement is the PR body’s fails without the fix: line. It still says “the test commit” without naming the test. Please add previewTimingPatch.browser.test.ts or the new timelineTimingSync.sealed.test.ts regression directly to that line.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

The description is kept exactly as first posted (only its capture sections may change), so the fail-first evidence is named here instead:

fails without the fix: packages/studio/src/hooks/previewTimingPatch.browser.test.ts, "a move that rewrites no script rebinds in place, and a delete right after it leaves the same load, in a sealed preview" (fails at c7f7d12 alone); previewTimingPatch.browser.test.ts, "a move whose live patch found no clip reloads the saved file" (fails at ca471ae alone, both modes); packages/studio/src/hooks/timelineTimingSync.sealed.test.ts, "a queued rebind takes the playhead the person scrubbed to while it waited" (fails at f4054f3 alone: sent time 1, expected 4).

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 84 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)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

The description stays as first posted, so here is that line with the tests named:

fails without the fix: packages/studio/src/hooks/timelineTimingSync.sealed.test.ts, "a queued rebind takes the playhead the person scrubbed to while it waited" (fails at f4054f3 alone: sent time 1, expected 4); packages/studio/src/hooks/previewTimingPatch.browser.test.ts, "a move that rewrites no script rebinds in place, and a delete right after it leaves the same load, in a sealed preview" (fails at c7f7d12 alone).

# Conflicts:
#	packages/studio/src/hooks/previewTimingPatch.browser.test.ts

This branch has not been deployed

No deployments
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