Skip to content

fix(desktop-windows): recover muted Rewind capture tracks - #10829

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
tianmind-studio:codex/windows-rewind-muted-track
Jul 29, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
tianmind-studio:codex/windows-rewind-muted-track

Conversation

@tianmind-studio

@tianmind-studio tianmind-studio commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Addresses #10737's recurrence after #10549.

#10549 made Rewind recover when a desktop-capture track reaches readyState === "ended". A browser can also report that the source is unable to provide media by setting MediaStreamTrack.muted while leaving readyState === "live". The existing isLive() check accepted that state, so the hidden capture video could keep producing and saving blank frames without taking the recovery path.

This change defines one usable-track predicate (live && !muted), listens for both mute and ended, and routes both states through the existing generation-fenced two-second restart. It also checks the initial track after video.play() and avoids duplicate recovery if a lifecycle event fired while play() was pending.

This deliberately does not add pixel-based black-frame heuristics, which would misclassify legitimate dark screens. It closes the remaining browser-declared unavailable-track state; a post-merge recurrence would need runtime health telemetry for a different source of blank pixels.

Product invariants affected

none

How it was verified

  • Before the implementation change, the new live-but-muted regression failed because rewindSaveFrame was called once after the mute event.
  • RewindCaptureHost.test.tsx: 10/10 passed, including runtime mute and initially-muted stream recovery.
  • All Rewind component tests: 20/20 passed.
  • Full Windows desktop Vitest suite: 5,070 passed, 18 skipped across 532 test files.
  • Node and renderer TypeScript checks passed.
  • Focused ESLint and Prettier checks passed.
  • Failure-class CLI tests: 17/17 passed.
  • The Windows manifest preflight passed all 11 selected checks; the isolated verification worktree included fix(ci): make Windows preflight path-safe #10825's pending path-portability fix because current main still contains Bug: manifest preflight compares MSYS and Win32 temp paths literally #10824.

Tests

  • A live track becomes muted without ending: no frame is saved, the stream reopens, and the replacement resumes capture.
  • getUserMedia resolves an already-muted stream: no sample is scheduled before the replacement stream is usable.
  • Existing ended-track, mid-save generation, quality, and unmount coverage remains green.

Failure class (fixes)

Failure-Class: new

Registers FC-media-track-output-liveness: a long-lived capture loop must treat every browser-declared media-output unavailable state as non-capturable and recover before persisting another frame. #10549 is the historical evidence PR, and RewindCaptureHost.test.tsx is the canonical prevention artifact.

New guards (only when adding a check or ratchet)

The behavioral regression lives with RewindCaptureHost because that component is the sole owner of the Windows desktop MediaStreamTrack, sampling timer, and generation fence. There is no second media-track capture owner to justify a shared repository primitive; the single usable-track predicate is reused by event recovery, initial admission, and every sample.

Review in cubic

Treat a live-but-muted MediaStreamTrack as unavailable, route mute and ended events through the existing generation-fenced restart path, and refuse to sample an initially muted stream.

Failure-Class: new

Verification: Rewind tests (20 passed); full Windows desktop suite (5070 passed, 18 skipped); Node/Web typecheck; focused ESLint and Prettier; failure-class tests (17 passed).

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this clean fix. The muted-but-live track state is a real gap — MediaStreamTrack.muted can be true while readyState stays "live", and the old isLive() accepted that, persisting blank frames.

Your single-predicate approach (live && !muted) unified through one onTrackUnavailable handler is the right design. Two details stand out as well done:

  • The post-play() usability re-check closes a subtle race where mute could fire during the pending play() promise.
  • The hasUsableVideoTrack() guard inside onTrackUnavailable correctly prevents duplicate recovery when another usable track still exists.

Both new behavioral tests (runtime mute + initially-muted stream) directly assert the no-save-before-recovery contract. The failure-class registration follows the established schema.

Approving — small, well-scoped, low-risk fix with solid test coverage.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added bug Something isn't working desktop labels Jul 29, 2026

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

Desktop bug fix for #10737's recurrence: isLive() accepted live-but-muted tracks so Rewind kept saving blank frames. Single usable-track predicate plus mute/ended listeners, with regressions for both runtime-mute and initially-muted streams. Green CI.

@kodjima33
kodjima33 merged commit 99c838e into BasedHardware:main Jul 29, 2026
40 of 41 checks passed
Git-on-my-level added a commit that referenced this pull request Jul 30, 2026
## What changed and why

Closes #8498. Closes #10488.

Windows Rewind now reacts to foreground-window changes and follows that
window across displays without keeping multiple capture streams alive.

- The existing WinEvent hook requests an immediate sample on a
foreground change.
- Screen sources are cached as an ID-to-display map instead of caching
only the primary source.
- The foreground window's physical Win32 rectangle is converted to
Electron DIP coordinates and matched to its display, with cursor and
primary fallbacks.
- The renderer replaces its single persistent 1 fps stream only when the
target display changes, preserving the current quality tier and capture
cadence.
- Each save includes its capture source ID. The main process revalidates
that source before ingestion and drops stale frames when focus moved
displays during stream setup or JPEG encoding.
- The stream replacement path retains the `ended`/`mute` recovery merged
in #10829, including initial-muted rejection and generation-fenced
late-event handling.

Capture-disabled, lock/idle, excluded-app, sensitive-title, size, and
duplicate-frame guards remain authoritative in the existing
`ingestRewindFrame` path.

## Product invariants affected

none

## How it was verified

- Synced with current `origin/main` (`df314540b`) at head `c92147266`.
- `npm run build` passed with the final code, including main/preload and
renderer typechecks, bytecode verification, extension bundling, and the
production renderer bundle.
- A detached Windows integration used #10825 solely as the path-safe
preflight runner; the committed 44-file composition passed all 70
selected checks in 188.34s. This PR's own diff remains 10 files.
- Targeted ESLint and Prettier passed for the two conflict-resolved
capture-host files.
- `git diff --check` passed.
- A native Windows Electron smoke probe previously exercised
`SetWinEventHook -> foregroundCaptureTrigger -> BrowserWindow IPC`; two
programmatic foreground-window changes produced `events=2`.
- The current Windows host exposes one physical display, so a real
dual-monitor switch was not hardware-tested here. Multi-display source
selection, per-monitor DPI conversion, stream replacement, stale-source
rejection, and muted/dead-track recovery are covered by tests.

## Tests

- `vitest run src/main/rewind/sourceId.test.ts
src/main/rewind/foregroundCaptureTrigger.test.ts
src/renderer/src/components/rewind/RewindCaptureHost.test.tsx` passed: 3
files, 29 tests.
- Coverage includes source-map caching and invalidation,
foreground/cursor/primary display selection, physical-to-DIP conversion,
source switching, late old-track events, stale-source rejection, burst
coalescing, muted/dead-track recovery, and disabled/unmounted capture.
- A full Windows Vitest run on the prior head reached one unrelated
`Apps.errorToast.test.tsx` timeout under full-suite load; that untouched
file passed 2/2 immediately on an isolated rerun. All Rewind tests
remained green.

## Failure class (fixes)

Failure-Class: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working desktop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants