8000 fix(playback): detect silent media stalls, surface load errors by johannboehme · Pull Request #149 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

fix(playback): detect silent media stalls, surface load 8000 errors - #149

Merged
johannboehme merged 1 commit into
mainfrom
fix/silent-playback-stall
Aug 29, 2026
Merged

johannboehme merged 1 commit into
mainfrom
fix/silent-playback-stall

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

Problem

The <audio> transport (editor, triage, arrange — all on the shared ping-pong engine) has exactly two failure channels: play() rejecting (autoplay policy) and the element's error event (resource error). A third state slips through both: the element accepts the src, fires loadstart, and then never delivers a byte — readyState stays 0, no progress, no error, and per spec play()'s promise stays pending forever (it only settles when playback actually starts or aborts).

Observed in the wild with a wedged Chrome media pipeline (browser-wide HTMLMediaElement stall; fetch, WebAudio and WebCodecs all healthy — the render pipeline worked while every transport froze): all three screens showed a "playing" transport with a frozen clock, forever, with zero feedback. On top of that, the editor's existing "Decoding studio audio" / error overlay was painted underneath the compositor canvas (later sibling, same stacking context, z auto) — so even the state that should have been visible wasn't: the stage just looked black.

Fix

  • stall-detector.ts — pure clock-progress detector (any change counts as progress, including backward jumps from loop wraps). Wired as a 250 ms setInterval watchdog (not RAF — background tabs) in useAudioMaster (editor) and use-pingpong-transport (triage + arrange): store says playing but the active element's clock hasn't moved for 1.5 s →
    • editor: error surfaced in the stage overlay + pushNotice("AUDIO STALLED — PLAYBACK STOPPED") + setPlaying(false)
    • triage/arrange: new optional onStalled callback, defaulting to the existing onPlayRejected path → transport honestly flips back to Play
    • deliberately not gated on isReady: the not-ready case is exactly where the editor's play effect no-ops while the transport already shows "playing"
  • Metadata timeout (editor) — loadedmetadata lands in milliseconds for local OPFS/blob sources; after 5 s of silence the load is declared dead and the overlay explains itself ("audio never loaded — the browser is not delivering media data …") instead of pulsing forever.
  • Overlay z-order (MasterAudio.tsx) — z-10 so the existing decoding/error overlay actually paints above the canvas; the pulse bar hides once an error is shown.

Verified

  • Unit: 8 new stall-detector tests + 5 new useAudioMaster watchdog/timeout tests (fake timers incl. performance); full unit suite: 1695 passed. The 6 failures in src/editor/render/feature-flag.test.ts are pre-existing — they fail identically on unmodified main in this environment.
  • Browser (real Chromium, real <audio>): useAudioMaster.loop.browser.test.tsx green — 6+ s of real playback across loop wraps and chunk hops without a false-positive stop. Full browser suite: failure set identical to a main baseline run in the same environment (74 env-related failures on both, same test names — none playback-related).
  • Live repro: in the wedged-Chrome environment where the bug was found — editor now shows the metadata error in the stage overlay after 5 s; pressing play flips back after ~1.75 s with the toast; triage's Play → Pause → auto-back-to-Play instead of a phantom frozen transport.

🤖 Generated with Claude Code

https://claude.ai/code/session_011JCm6qu9qx6kKGPCbiWaeu

The <audio> transport's failure telemetry covered exactly two channels:
play() rejecting (autoplay policy) and the element's `error` event
(resource error). A third state slipped through both: the element
accepts the src, fires loadstart, and then never delivers a byte —
readyState stays 0, play()'s promise stays pending forever (per spec it
only settles when playback starts or aborts), and no error ever fires.
Observed with a wedged Chrome media pipeline: every screen showed a
"playing" transport with a frozen clock, forever, with zero feedback.

Three fixes:

- stall-detector.ts: pure clock-progress detector. Wired as a
  setInterval watchdog (not RAF — background tabs) in useAudioMaster
  (editor) and use-pingpong-transport (triage + arrange): store says
  playing but the active element's clock hasn't moved for 1.5 s →
  editor surfaces an error + notice and flips isPlaying back; triage/
  arrange fall back to the onPlayRejected path (honest stopped
  transport instead of a phantom playing one). Deliberately not gated
  on isReady — the not-ready case is exactly where the editor's play
  effect no-ops while the transport already shows "playing".

- Metadata timeout (editor): loadedmetadata lands in milliseconds for
  local OPFS/blob sources; after 5 s of silence the load is declared
  dead and the decoding overlay explains itself instead of pulsing
  forever.

- MasterAudio overlay z-order: the compositor canvas is a later sibling
  in the same stacking context and painted OVER the decoding/error
  overlay — on a stuck load the stage just looked black. z-10 makes the
  existing overlay actually visible; the pulse bar hides once an error
  is shown.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011JCm6qu9qx6kKGPCbiWaeu
@johannboehme
johannboehme merged commit acb3581 into main Aug 29, 2026
1 check passed
@johannboehme
johannboehme deleted the fix/silent-playback-stall branch August 29, 2026 11:49
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.

1 participant

0