8000 fix(preview): jump-vs-natural seek policy + shared sync helper by johannboehme · Pull Request #43 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

fix(preview): jump-vs-natural seek policy + shared sync helper - #43

Merged
johannboehme merged 1 commit into
mainfrom
claude/preview-stutter-mitigation
May 9, 2026
Merged

johannboehme merged 1 commit into
mainfrom
claude/preview-stutter-mitigation

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

Summary

The Triage and Arrange small CamPreviews and the editor's VideoElementPool all wrote videoEl.currentTime = X whenever drift exceeded a tight threshold. On large phone recordings the browser tears the decoder open from the nearest keyframe on every write — back-to-back ticks turn into a positive-feedback stutter loop.

This PR introduces a single jump-vs-natural classification used in both surfaces:

  • local/timing/cam-preview-sync.ts (relocated from components/triage/): a pure decision function returning {pause-before-start, pause-after-end, hold, seek}. A meaningful master jump (chunk click, scrub, loop wrap) always seeks with a precise 50 ms drift threshold; natural ~16 ms RAF advance only seeks when drift becomes catastrophic (>500 ms). The Triage and Arrange CamPreview components consume this helper.
  • editor/render/video-element-pool.ts: the editor pool gets the same policy, plus a mid-seek skip (v.seeking → don't write currentTime) so two-in-flight seeks can't stack on one element. Also resets prevTargetSourceT on off-PROGRAM cams so a re-entry tick is treated as first contact and snaps precisely.

Out of scope

The 1-frame upside-down flicker on pill change in the editor compositor remains. It's a Chrome copyExternalImageToTexture(<video>) codec-orientation hiccup, not addressable without a structural rewrite of the preview render pipeline (e.g. WebCodecs VideoDecoder + VideoFrame).

Test plan

  • 975 unit tests pass
  • Triage CamPreview: scrubbing + chunk-click no longer stutters on long phone recordings
  • Arrange CamPreview: same
  • Editor compositor: scrubbing smooth (1-frame pill-change flicker still present, separate concern)

🤖 Generated with Claude Code

…small previews

The Triage and Arrange small CamPreviews and the editor's VideoElementPool
all wrote `videoEl.currentTime = X` whenever drift exceeded a tight
threshold. On large phone recordings (multi-GB) the browser tears the
decoder open from the nearest keyframe on every write, which on
back-to-back ticks turns into a positive-feedback stutter loop —
"the post-seek stutter loop the user reports".

This change introduces a single jump-vs-natural classification used in
both surfaces:

- `local/timing/cam-preview-sync.ts` (relocated from `components/triage/`):
  a pure decision function returning {pause-before-start, pause-after-end,
  hold, seek}. A meaningful master jump (chunk click, scrub, loop wrap)
  always seeks with a precise 50 ms drift threshold; natural ~16 ms RAF
  advance only seeks when drift becomes catastrophic (>500 ms). The
  Triage and Arrange CamPreview components now consume this helper.

- `editor/render/video-element-pool.ts`: the editor pool gets the same
  policy, plus a mid-seek skip (`v.seeking` → don't write currentTime)
  so two-in-flight seeks can't stack on one element.

The pool also resets `prevTargetSourceT` on off-PROGRAM cams so a
re-entry tick is treated as first contact and snaps precisely.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@johannboehme
johannboehme merged commit e078163 into main May 9, 2026
1 check passed
@johannboehme
johannboehme deleted the claude/preview-stutter-mitigation branch May 9, 2026 20:28
johannboehme added a commit that referenced this pull request May 9, 2026
#44)

* fix(preview): drop seeking-guard that froze playback in Triage + Arrange

#43 added a defensive `if (videoEl.seeking) return` guard to the sync
effects in both CamPreview surfaces. Intent was to avoid stacking
currentTime writes during the 100-400 ms decoder warmup. In practice it
broke responsive scrubbing and froze Arrange playback:

- Triage: continuous scrubs / loop-wraps land during the previous
  seek's warmup → guard skips → user sees stale frames jump-cut to
  catch up = visible "ruckeln".
- Arrange: initial play() seeks; while seeking the guard skips every
  subsequent tick, including the `if (isPlaying && videoEl.paused)
  play()` recovery path. Browser's seek-implicit pause is never
  re-played → video frozen.

The jump-vs-natural classifier already prevents the original stutter
loop (natural advance with a generous 500 ms threshold; only jumps
trigger seeks). The seeking-guard was redundant and harmful — browsers
handle "newer setCurrentTime supersedes in-flight seek" internally.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(preview): drop seeking-guard in editor compositor pool too

Same bug as Triage+Arrange (3f21766) — the pool's syncSlot had its own
`if (v.seeking) return` that suppressed the play() recovery while the
browser had implicitly paused the element during a seek. Result: editor
preview videos froze on the first seek.

The jump-vs-natural classifier already prevents the original stutter
loop. Browsers handle a fresh currentTime write supersession during an
in-flight seek internally — we don't need the guard.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
503E

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0