fix(timeline): isolate preview renders from concurrent exports#38
Merged
Conversation
Intermediate segment/text/fold filenames were deterministic (tl-seg-<index>-<clip>), so a preview frame render and a concurrent export wrote and ffmpeg -y-overwrote the SAME files — and each unlinked the other's in run-plan's finally — yielding a transient garbled frame or 500. The timeline doc (source of truth) was never touched, so it self-healed on retry, but it is a real race on the unauthenticated localhost dev server. Add an optional tag to CompileContext, mixed into the intermediate names. Export stays deterministic (no tag); the clip ui sets a per-request tag on each frame render (next commit), so previews get their own paths and cannot collide. Default (untagged) paths are unchanged — existing plans/tests are untouched.
- The frame route passes a per-request tag to buildFrameAtPlan, so a preview's intermediate segments never collide with a concurrent export's. - Frame and export routes translate a non-CompileError (a transient FFmpeg failure) into a clean 503 instead of a raw 500. - Viewer fetches the frame as a blob behind an AbortController, so a superseded scrub is cancelled instead of left rendering, and a 503 reads as a message rather than a broken img. The previous frame stays on screen until the next decodes — no blank flash.
This was referenced Jun 19, 2026
|
🎉 This PR is included in version 0.3.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix concurrent frame/export render collisions
Closes the last v0.3.0 pre-release-audit follow-up (non-blocking). On the localhost
clip ui, scrubbing the viewer during an export could produce a transient garbled frame or a raw 500.Root cause
compile.tsnamed intermediate segments deterministically —tl-seg-<index>-<clip>.mp4— with no random component (unlikenewOutputPath).run-plan.tsrunsffmpeg -ythen unlinks intermediates in afinally, and nothing serializes the UI render path. So a preview frame render and a concurrent export wrote/-y-overwrote the same segment files and unlinked each other's → a transient 500 or garbled frame. Self-healing on retry, and the timeline document (source of truth) is never touched — hence low severity — but a real race on the unauthenticated dev server.Fix
CompileContextgains an optionaltagmixed into intermediate (segment/text/fold) filenames. Export stays deterministic (no tag); the frame route sets a per-requesttag = frame-<rand>, so previews get their own paths and can't collide — with an export or with each other. Default (untagged) paths are unchanged, so existing plans and tests are untouched.CompileError(a transient FFmpeg failure) into a clean 503 instead of a raw 500.CompileError(a real doc problem) stays 422.Viewerfetches the frame as a blob behind anAbortController, so a superseded scrub is cancelled instead of left rendering server-side, and a 503 reads as a message rather than a broken<img>. The previous frame stays on screen until the next decodes — no blank flash.Verification
pnpm type-check✓ · 543 tests ✓ (new: tagged context → collision-free segment path, untagged unchanged) ·pnpm lintexit 0 ·pnpm build✓ (Vite compiles the newViewer).🤖 Generated with Claude Code