Repository navigation
fix(stems): guard handleNaturalEnd on playback; test + document the seek guard - #36
Conversation
…eek guard Step 11.1 — the deferred streaming/transport hardening. 1. handleNaturalEnd() now returns unless transport.playing. In worklet mode a queued worklet 'ended' can arrive just after transportPause()/lightStop() flipped playing=false (stopSources posts 'stop' but can't unqueue an in-flight 'ended'), which would dispatch a spurious 'ended' and jump the playhead to duration. Pre-existing (CodeRabbit on #35); buffer mode was already safe since stopSources nulls src.onended before stop(). No genuine natural-end enters with playing===false (it's set false inside the handler). 2. Export appendRound + tests/streaming.test.mjs cases pinning the step-9.1 seek-token guard: posts only when the captured token matches ST.streamSeekToken, drops the block (no post, frontier unchanged) otherwise. 3. Document the synchronous t.done=true invariant in cancelStreamReaders that keeps reader-reopen seek-safe. This is why Copilot's immutable-per-generation track refactor isn't needed: the steal is unreachable given that invariant (readers reopen only after a network fetch, a macrotask after the cancelled read resolves with t.done already true) plus appendRound's per-track guard. node 47/47, pytest 10/10. Codex 0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a ChangesStreaming and transport race hardening
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR hardens playback end-handling for worklet mode and adds unit coverage around the streaming seek-token guard, while documenting an important streaming-reader safety invariant.
Changes:
- Guard
handleNaturalEnd()so queued workletendedmessages don’t fire after a user pause/stop. - Export
appendRound()(test-only intent) and add unit tests that pin the seek-token guard behavior. - Document the synchronous
t.done=trueinvariant incancelStreamReaders()to clarify seek safety.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/transport.js |
Prevents spurious ended dispatches by requiring transport.playing when handling worklet ended. |
src/streaming.js |
Exports appendRound() for unit testing and documents reader-cancellation invariants for seek safety. |
tests/streaming.test.mjs |
Adds unit tests for appendRound’s seek-token guard behavior. |
CHANGELOG.md |
Records the step 11.1 hardening, the new tests, and the documented invariant. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/transport.js (1)
285-297: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winGate worklet
endedmessages by playback session.
!transport.playingdrops the queued'ended'that arrives after pause/stop, but the sameAudioWorkletNodeis reused for the whole song andplay()setstransport.playing = trueagain on restart. Without a session/generation id on'ended', a stale message from the previous run can still end the next playback and snap the playhead totransport.duration.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/transport.js` around lines 285 - 297, The current `handleNaturalEnd` guard only checks `transport.playing`, so a stale worklet `'ended'` message can still affect a later restart when `play()` has already flipped playback back on. Add a playback session/generation identifier to the worklet end flow, and have `handleNaturalEnd` ignore `'ended'` events whose session does not match the current transport run; update the `play()`/`transportPause()`/`lightStop()` path and the `AudioWorkletNode` message handling so only the active session can trigger the natural-end behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/transport.js`:
- Around line 285-297: The current `handleNaturalEnd` guard only checks
`transport.playing`, so a stale worklet `'ended'` message can still affect a
later restart when `play()` has already flipped playback back on. Add a playback
session/generation identifier to the worklet end flow, and have
`handleNaturalEnd` ignore `'ended'` events whose session does not match the
current transport run; update the `play()`/`transportPause()`/`lightStop()` path
and the `AudioWorkletNode` message handling so only the active session can
trigger the natural-end behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 65384a46-8432-42c8-b877-50649cfa9283
⛔ Files ignored due to path filters (1)
tests/__pycache__/test_manifest.cpython-314-pytest-9.0.3.pycis excluded by!**/*.pyc
📒 Files selected for processing (4)
CHANGELOG.mdsrc/streaming.jssrc/transport.jstests/streaming.test.mjs
Address Copilot on #36 — assert a block was posted and the frontier advanced by exactly the posted frame count, instead of hard-coding 8192. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What
Step 11.1 — the deferred streaming/transport hardening (from CodeRabbit's Major on #35 + Copilot's suggestion on #33).
1. Guard
handleNaturalEnd()ontransport.playing(real fix). In worklet mode a queued workletendedcan arrive just aftertransportPause()/lightStop()flippedplaying=false—stopSources()postsstopbut can't unqueue an in-flightended— which would dispatch a spuriousendedand jump the playhead toduration. Buffer mode was already safe (stopSourcesnullssrc.onendedbeforestop()). No genuine natural-end enters withplaying===false(it's set false inside the handler), so the guard only filters the spurious case.2. Export
appendRound+ unit-test the step-9.1 seek-token guard. New cases pin the contract:appendRoundposts to the worklet only when its captured token still matchesST.streamSeekToken, and drops the block (no post, frontier unchanged) once a seek supersedes it.3. Document the reader-reopen safety invariant in
cancelStreamReaders— it setst.done=truesynchronously beforerepositionStreamyields, so a stale in-flight dequeue resolves off its cancelled reader (witht.donealready true) and can't loop onto a reopened one (readers reopen only after a network fetch, a macrotask later). This is why Copilot's immutable-per-generation-track refactor isn't needed: the steal is unreachable given that invariant +appendRound's per-track token guard. Documented rather than restructured.Tests
node47/47 (2 new token-guard cases),pytest10/10. Codex preflight: 0.Summary by CodeRabbit
Bug Fixes
endedevents after pause/stop by hardening natural-end handling.Tests
Documentation