Skip to content

fix(desktop): reopen Rewind capture when the display stream dies (#10504) - #10549

Merged
kodjima33 merged 2 commits into
mainfrom
watchdog/issue-10504-rewind-capture-recovery
Jul 25, 2026
Merged

kodjima33 merged 2 commits into
mainfrom
watchdog/issue-10504-rewind-capture-recovery

Conversation

@kodjima33

@kodjima33 kodjima33 commented Jul 25, 2026 •

Copy link
Copy Markdown
Collaborator

Bug

#10504 — on Windows, after Omi Desktop has been running for a few hours the Rewind timeline fills with dark/blank screenshots while the app still reports capture as active.

Root cause

RewindCaptureHost opens one persistent getUserMedia desktop stream into a hidden <video> and samples it on a self-pacing timer. Nothing observed the track's lifecycle. When the OS tears the capture source down mid-session (display sleep, GPU/driver reset, resolution or session change) the track ends, but:

  • grabAndSchedule kept drawing the now-dead <video> (its videoWidth/videoHeight stay non-zero) and saving those frames — the blank frames in the timeline, exactly the issue's own hypothesis "the timeline is receiving blank frames while the app still thinks capture is active";
  • nothing ever reopened the stream, so capture stayed dead for the rest of the session.

Fix

Commit 1 — recover from a dead capture track:

  • Skip sampling while no video track is live — no more blank frames from a dead stream.
  • Listen for the track's ended event and reopen the stream after a 2s delay. Our own teardown uses track.stop(), which per spec does not fire ended, so this cannot self-trigger or loop on unmount/settings changes.

Commit 2 — keep exactly one sampling loop across a restart:

  • A frame save is an IPC round-trip, so the track often dies while a grab is in flight. That grab's finally still rescheduled itself after the teardown, orphaning the restart timer's handle and leaving the old loop alive — every mid-save recovery added another parallel sampling loop, doubling capture work each time.
  • Each scheduling chain now carries a generation that stop() bumps, so a grab from a torn-down stream neither saves its frame nor reschedules itself.

Plus a changelog fragment for the user-visible behavior. Scope: ~30 changed lines in one component plus regression tests.

Tested

  • pnpm vitest run src/renderer/src/components/rewind/RewindCaptureHost.test.tsx → 3/3 pass. The tests drive the real component against a fake desktop stream: baseline frame saved → track dies → no frames while the stream is down → getUserMedia called again and saving resumes; a mid-save death yields exactly one frame per interval after recovery; and no reopen after unmount.
  • Teeth checks (both directions). With the commit-1 component change reverted, 2/3 fail — a frame is still saved from the dead video and the stream never reopens (the reported symptom). With only the commit-2 generation guard reverted, the mid-save case fails with 2 frames per interval after recovery (the duplicated loop).
  • Whole rewind suite: pnpm vitest run src/renderer/src/components/rewind/ → 13/13 pass.
  • pnpm run typecheck → clean; pnpm run lint → 0 errors (pre-existing prettier warnings only, including one on an untouched line of this file that is already present on main).
  • make preflight → 10/10 checks pass on this diff.

Not claimed: this was not reproduced on a real multi-hour Windows session. It fixes a confirmed mechanism for #10504 (blank frames plus no recovery once the capture track dies), not a bisected repro.

🤖 automated by hourly watchdog — tested, then merged in the same run

Failure-Class: none

)

Windows Rewind opens one persistent getUserMedia desktop stream and samples
it on a timer. Nothing observed the track's lifecycle, so when the capture
source went away (display sleep, GPU/driver reset, resolution or session
change) the host kept drawing a dead <video> — the timeline filled with
blank frames and capture never came back for the rest of the session.

Watch the video track's 'ended' event: skip sampling while no track is live,
and reopen the stream after a short delay. Our own teardown calls
track.stop(), which does not fire 'ended', so this cannot self-trigger.

Failure-Class: none

Verified: pnpm vitest RewindCaptureHost.test.tsx 2/2 pass; with the fix
reverted the same test fails exactly on the reported symptom (a frame is
still saved from the dead video, stream never reopens). pnpm run typecheck
and pnpm run lint clean (0 errors).
The recovery added in the previous commit tears the stream down and reopens
it, but a grab already in flight (a frame save is an IPC round-trip) still
ran its own reschedule afterwards. That both orphaned the restart timer's
reference and left the old loop alive, so every recovery that happened
mid-save added another sampling loop — doubling capture work each time.

Stamp each scheduling chain with a generation that stop() bumps, so a grab
from a torn-down stream neither saves its frame nor reschedules itself.

Failure-Class: none

Verified: pnpm vitest RewindCaptureHost.test.tsx 3/3 pass, including a new
case that kills the track while a save is pending and asserts exactly one
frame per interval after recovery; that case fails (2 frames per interval)
with this commit reverted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants