Skip to content

fix(studio): a clip deleted while the preview reloads leaves the frame on screen - #8819

Merged
miguel-heygen merged 10 commits into
mainfrom
fix/sealed-delete-across-promotion
Nov 25, 2026
Merged

miguel-heygen merged 10 commits into
mainfrom
fix/sealed-delete-across-promotion

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A clip deleted while the preview reloads now leaves the frame on screen. Studio sends the delete to the frame that replaced the old one, instead of a frame that is no longer shown. In a sealed preview, a delete still waiting for its lookup when the reload swaps frames runs again, once, on the new frame.

Why

A preview reload loads the film in a hidden second frame and swaps it in when it is ready (useShadowPreviewReload.ts, promoteWhenReady). Studio then retires the old frame's editing client. A sealed delete looks its clips up over that client before it removes them. When the swap lands between the two, the lookup gets no answer, and the delete was dropped without a word. The clip stayed drawn until the next load.

In the desktop app, saving a timeline edit reloads the preview in both modes, and the swap lands about half a second later. A sealed delete made right after a move missed this way in 1 of 20 instrumented real-app runs. An unsealed delete acts at once on the frame it is given. The same stale frame, handed to it after a swap, removed the clip from a frame no longer on screen.

Related work

Stacked on #8817, whose samePreviewLoad this uses to see that a load was replaced. Refs #8816 (the selection box after a sealed reload). Like those, previewChannel.ts stays the one place that knows which client answers for the frame on screen.

How

  • player/lib/previewChannel.ts: notePreviewPromoted(retired, live) records which frame replaced which, and shownPreviewFrame(iframe) follows that record to the frame on screen.
  • player/sceneSwap.ts: announcePreviewPromoted, which every promotion already calls, records the swap.
  • hooks/previewTimingPatch.ts: removeIframeTimelineElements acts on shownPreviewFrame(iframe) in both modes. A sealed delete whose lookup went unanswered because its load was replaced runs again once, on the frame now shown. Element handles belong to one load, so the lookup and the removal both run again; neither is re-sent alone.
  • Not changed: a lookup that goes unanswered with no reload behind it still removes nothing. A second replacement during the rerun is not followed either.

Test plan

  • previewTimingPatch.browser.test.ts (real Chrome): a delete given the frame a reload just replaced removes the clip from the frame now shown (unsealed and sealed). A sealed delete still waiting on its lookup when the reload is promoted removes the clip from the new frame.

  • fails without the fix: packages/studio/src/hooks/previewTimingPatch.browser.test.ts, run at the test commit 7f262e0 alone, fails all 3 new cases (the shown frame drops the deleted clip: expected true to be false); the 4 others pass.

  • Dropping the record in announcePreviewPromoted fails all 3 again. Dropping only the rerun fails the sealed lookup case.

  • The browser test passed 3 runs in a row. previewChannel.test.ts, sceneSwap.test.ts, sceneSwap.sealed.test.ts, previewTimingPatch.test.ts, timelineTimingSync.test.ts, timelineTimingSync.sealed.test.ts, useTimelineSyncCallbacks.test.ts and useTimelineSyncCallbacks.sealed.test.ts pass (110 tests). The Studio type check passes.

  • 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

No visible change

A layout or style capture would show nothing new. The change decides which frame a delete goes to while a reload swaps frames, and the clip ends up gone in both cases. Before, it stayed drawn until the next load.

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Real-app walk at a79fce9 (desktop app built locally against this branch's packages, which include #8817; Linux). A clip dragged past the film's end, then deleted right after the save:

runs delete answered and removed unanswered reran on the new frame
sealed 20 20 0 4
unsealed 3 3 0 n/a

Counted from Studio's own log of each delete's lookup and the frame's reply. No frame held the deleted clip afterwards in any sealed run. On main, the same walk left a sealed delete unanswered in 3 of 11 runs.

Known timing cost, not changed here: after a promotion, a sealed refresh first asks the new frame to swap scenes. A film without scene parts refuses, and the refresh then reloads as an unsealed one does at once. That extra round trip measured 43, 50, 54 and 82 ms over 4 refreshes in 2 sealed runs. Those runs used an earlier build; this PR does not touch the refresh path.

@miguel-heygen

miguel-heygen commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

Removal time on screen, same walk at a79fce9:

  • Sealed: in 10 of 10 instrumented runs the delete went to the frame on screen. From the moment just before the Delete key to the frame's reply took 37 to 92 ms (median 50), from Studio's own log. A separate check of the on-screen frame, run every 100 ms, found the clip already gone at its first look in 8 of 10 runs.
  • Unsealed: 0 to 1 ms in 3 of 3 runs, measured by a change observer inside the frame from the delete's save.

The sealed time is the round trip through the editing port: look up the clip, then remove it. The two figures are measured differently, so compare the size of the gap, not single values.

@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.

Reviewed at a79fce9, own diff against #8817's branch. Comment only, not an approval: this PR is stacked on #8817, so I approve after #8817 merges and this retargets main.

The code reads right. SECOPS-3848 is a sealed clip delete dropped without a word when the shadow reload swaps frames between the lookup and the removal. announcePreviewPromoted records which frame replaced which, shownPreviewFrame follows that record, and removeIframeTimelineElements acts on the shown frame in both modes. The sealed path reruns the lookup and the removal once on the new frame when a lookup went unanswered (undefined) and its load was replaced. I checked that undefined means no reply and null means not found in previewSelection.ts, so a clip that is simply gone is not retried. The promotion chain cannot loop, because each promotion's live frame is a new slot element keyed by gen. The retry fails closed: one rerun, then nothing removed.

One gap, not a blocker for a comment review but worth closing before this merges: the rerun only fires on found.includes(undefined). If every lookup is answered on the old load and the swap lands before remove-elements goes out, replaced is true but the code still sends the old load's handles to the retired frame, and the delete is dropped the same way. Retrying on replaced && !retried alone would cover that window too. Please confirm whether leaving it out was deliberate.

fails without the fix: is present and names previewTimingPatch.browser.test.ts at 7f262e0 with the 3 new cases, and "No visible change" is stated. CI on this head shows no Studio test or typecheck jobs, since the base is a PR branch, so the real-Chrome test has not run in CI here. It will on the retarget.

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Two additions at 005da51:

  • A sealed delete now runs again on the frame on screen whenever its load was replaced before the removal went out, not only when a lookup went unanswered. Before, a reload promoted after the lookups answered but before remove-elements still sent the delete to the retired frame.
  • After a delete, the frame's film length and the readout follow the clips that are left (syncContentDuration, as timing edits already do), in both modes. Before, the frame kept its old root duration and reported it again. The sealed delete is asynchronous, so that report landed after the save's shorter duration and put the old length back on the readout until the next reload. The open film only showed the right length because its report arrived first.

fails without the fix: packages/studio/src/hooks/previewTimingPatch.browser.test.ts, at the test commit 22f4f5c alone, "deleting the clip that ended the film shortens the frame's film and the readout" fails in both modes ({ reported: 4, readout: 4 }, expected 2 and 2), and "a sealed delete whose lookups answered just before the reload is promoted removes the clip from the new frame" fails. With the fix all 10 cases pass, 3 runs in a row. Dropping the duration sync fails the two duration cases again; restoring the old rerun condition fails the promotion case again.

@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.

Re-reviewed at 005da51 (delta a79fce9...005da51: previewTimingPatch.ts and its browser test).

The gap I raised is closed. removeSealedElements now reruns whenever the load was replaced before the removal (!sameLoad() || shownPreviewFrame(given) !== iframe), whatever the lookups answered. The rerun is bounded: retried is set on the second pass, so there is one retry and no loop. The rerun re-resolves the handles against the newly shown frame, so handles from the retired frame are not sent. The new test ("lookups answered just before the reload is promoted") delivers the held answers and promotes in one task, so every lookup answers and the swap lands before remove-elements. The old condition required an unanswered lookup, so on the old code the delete would go to the retired frame and the clip would stay in the new one. I read that as red-first, though I did not run it.

The duration readout change reads correct. The sealed path syncs from a fresh document copy after remove-elements is awaited, and it does not re-enter inOrder, so there is no deadlock. The unsealed path syncs only when something was removed, since findTimelineElementInIframe returns null on a miss. The new case covers both modes: clip A ended the film at 4 s, and both the reported duration and the readout drop to 2 s.

Two small things, neither blocking. If a second swap lands during the retry, that pass is not retried again. If the delete empties the film, syncContentDuration returns early on end <= 0 and the readout keeps the old value. The body's fails without the fix: line still describes the earlier test commit, so please add the new cases to it.

CI on this head: 10 checks passed, 0 failed. The Studio jobs (Preflight lint/format, regression shards, perf shards) show as skipped, as expected on a PR-branch base, so the browser tests did not run in CI. I am relying on the author's local runs.

I'm commenting rather than approving because this is stacked on #8817's branch (#8817 is still open). Approval follows once #8817 merges and #8819 retargets main and the Studio jobs run. Nothing else blocks.

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Thanks. On the three notes:

  • A second swap during the retry: kept to one rerun on purpose, so a delete cannot chase a reload that keeps restarting. In the real-app walk the rerun fired 4 times in 20 sealed runs and never needed a second one.
  • A delete that empties the film: the save path does the same today (useTimelineDeleteOps.ts sets the duration only when the remaining content ends after 0), so the readout matches the file in both modes. Changing what an empty film shows is its own change, not this one.
  • fails without the fix: for the new cases: the description is kept as first posted, so the new cases are named in issuecomment-7156165023 (test commit 22f4f5c).

Base automatically changed from fix/sealed-timeline-read-across-reload to main November 25, 2026 09:23
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

#8817 merged and this now targets main, so Studio CI ran. At 005da51 Test (studio 2/3) fails, and I'm not approving past it.

useTimelineEditing.test.tsx > "rolls back the store duration and live root when a delete persist fails" gets expected 2 to be 4 at line 971. That test is green on main (Studio 1/3, 2/3 and 3/3 all pass there), so the change causes it.

Cause: the new unsealed branch of removeIframeTimelineElements calls syncContentDuration when it removes something. That call sets the store duration to the shrunk value synchronously. In useTimelineDeleteOps.ts the removal runs at line 145, but captureDurationRollback is only taken at line 193. So the rollback snapshot is already the shrunk 2s, and a failed delete persist no longer restores the 4s readout and live root. That is a real regression for a failed delete in an unsealed preview.

Fix: take the rollback snapshot before the removal, or drop the sync from removeIframeTimelineElements and let useTimelineDeleteOps do its own sync after capture. The sealed path syncs after the await, so check it keeps the same order.

The rest still reads right, and my earlier comment on the sealed rerun stands. I'll approve once this is green.

@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.

Requesting changes at 005da51, now that this targets main and Studio CI ran: Test (studio 2/3) fails on useTimelineEditing.test.tsx ("rolls back the store duration… when a delete persist fails", expected 4, got 2), and it passes on main. The new unsealed-removal duration sync in useTimelineDeleteOps.ts (line 145) runs before the rollback snapshot is taken (line 193), so a failed delete no longer restores the duration readout. Take the snapshot before the sync (or include the duration in it). The rest still reads right per my earlier comment.

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed at b1489d9. The delete now takes its duration snapshot before removeIframeTimelineElements shortens the film, as the move and group edits already do (useTimelineClipTimingEditing.ts, useTimelineGroupEditing.ts: snapshot before the optimistic updates). It is one move in useTimelineDeleteOps.ts: the capture left the queued rewrite and now sits just above the removal. A sealed removal shortens the film after a frame round trip, so the late snapshot could catch it there too; taking it first covers both modes.

fails without the fix: packages/studio/src/hooks/useTimelineEditing.test.tsx, "rolls back the store duration and live root when a delete persist fails" fails at f50e38d (expected 2 to be 4) and passes at b1489d9, 3 runs in a row.

Also ran: every test under src/hooks/, plus previewChannel.test.ts and the sceneSwap tests (2055 pass), previewTimingPatch.browser.test.ts in Chrome (10 pass), and the Studio type check. f50e38d merges main in; the only conflict was the new block in previewChannel.ts, kept as it was.

@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 b1489d9. The earlier blocker is fixed.

  • useTimelineDeleteOps.ts: captureDurationRollback now runs at :145, before removeIframeTimelineElements, so the snapshot holds the pre-delete length and a failed persist puts it back. The sealed removal's duration sync and the rollback both go through inOrder, so the rollback lands after the sync. The unsealed sync is synchronous and the rollback sees the shortened value. studio 2/3 and 3/3 are green, useTimelineEditing included.
  • Frame-swap fix: shownPreviewFrame and the one-time rerun in removeSealedElements look right. The rerun redoes lookup and removal together, so handles from the old load are never reused.
  • The browser tests cover the unsealed and sealed swap cases and the film-shortening case. The "fails without the fix" line in the PR body covers the 3 swap cases at 7f262e0.

Required checks are green on this head. The one red is Comments (comment ratchet): useTimelineDeleteOps.ts rose from 14.5% to 14.8% because of the new comment above captureDurationRollback. It is not a required check. Please cut that line or move the explanation into a name, so the ratchet is green before merge.

Nit: the PR body says nothing about the new behaviour where a delete shortens the film and the readout, and its "Not changed" notes are stale. Add a line for it.

@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.

Re-approving at 2cbe654. The only change since b1489d9 is one deleted comment line in useTimelineDeleteOps.ts; the code is identical to the head I approved. Checks are green.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 7d7378b Nov 25, 2026
81 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-delete-across-promotion branch November 25, 2026 10:38
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