Skip to content

Fix stems takeover pause state handling - #2

Merged
cchacs merged 5 commits into
mainfrom
pause-state-handling
Aug 4, 2026
Merged

cchacs merged 5 commits into
mainfrom
pause-state-handling

Conversation

@cchacs

@cchacs cchacs commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Reset and manage _stemsRerouteInProgress during song teardown and stems takeover so intentional HTML5-to-stems pauses do not get treated as real playback failures. This also adds debug logging around song readiness, shim availability, decode completion, and transport startup to help diagnose takeover races and issue got-feedBack#39.

Reset and manage `_stemsRerouteInProgress` during song teardown and stems takeover so intentional HTML5-to-stems pauses do not get treated as real playback failures. This also adds debug logging around song readiness, shim availability, decode completion, and transport startup to help diagnose takeover races and issue got-feedBack#39.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fb0fb17c-80db-4295-8ee2-fd2ec27e8912

📥 Commits

Reviewing files that changed from the base of the PR and between 412e12b and 4096647.

📒 Files selected for processing (1)
  • src/main.js

📝 Walkthrough

Walkthrough

The PR adds _stemsRerouteInProgress handling to distinguish intentional core-audio pauses from playback failures. The flag is reset during teardown, set before pausing core playback, and cleared on streaming failure or success, decode failure, and successful graph setup. Each song load creates one AbortController and passes its signal through streaming and decode operations. Generation guards prevent superseded loads from continuing. Debug logging was added for initialization, shim and worklet availability, pending playback, and decode completion. Transport now emits the play event only after playback starts. The plugin version increments to 0.9.1.

Changes

Stems reroute lifecycle

Layer / File(s) Summary
Reroute state across takeover and initialization
src/main.js
The code tracks intentional core-audio pauses through teardown, streaming, decoding, graph construction, and deferred playback. It adds generation guards and diagnostics.
Load signal propagation
src/streaming.js
setupStreaming accepts an optional abort signal parameter and applies it to both separated-stem and full-mix range fetches.
Transport completion and release metadata
src/transport.js, CHANGELOG.md, plugin.json
transportPlay emits play only after playback starts. The changelog records the fixes, and the manifest version changes from 0.9.0 to 0.9.1.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant onSongReady
  participant CoreAudio as core audio element
  participant StreamingSetup as streaming setup
  participant Decode as decode
  participant Graph as graph construction
  onSongReady->>CoreAudio: pause for stems takeover
  onSongReady->>StreamingSetup: initialize with load abort signal
  StreamingSetup->>Decode: process decode result
  Decode->>Graph: build stems graph
  Graph->>CoreAudio: start deferred playback or complete takeover
Loading

Possibly related issues

  • get-flashbacks/feedBack#39 — The PR implements _stemsRerouteInProgress lifecycle handling to resolve a startup race condition between stems takeover and playback failure.

Suggested reviewers: byrongamatos

🚥 Pre-merge checks | ✅ 21 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Plugin Folder Name Matches Manifest Id ⚠️ Warning Plugin ID in plugin.json is "stems" but repository folder name is "feedBack-plugin-stems". The folder name must match the id field exactly (case-sensitive). This mismatch causes silent skip at plug... Rename the repository folder from "feedBack-plugin-stems" to "stems" or update the plugin.json id field to "feedBack-plugin-stems" to match the actual folder name.
✅ Passed checks (21 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change to stems takeover pause-state handling.
Description check ✅ Passed The description directly explains the pause-state fixes and related debug logging in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
No Print()/Console.Log In Routes.Py ✅ Passed Check is not applicable. PR modifies JavaScript plugin files only. No routes.py or Python backend files are present or modified in this repository.
Sibling Imports Use Load_sibling ✅ Passed This is a JavaScript plugin using ES6 module imports. The custom check applies only to Python plugins using context["load_sibling"]. No new imports were added in this PR.
Routes Namespaced Under /Api/Plugins/Id ✅ Passed No routes.py file exists in the repository, and the PR contains no route registration code. The check for route namespace compliance is not applicable to this JavaScript audio plugin.
Blocking Route Handlers Use Def Not Async ✅ Passed Custom check for routes.py blocking handlers is not applicable. This is a JavaScript plugin repository with no routes.py file and no Python async handler code.
Plugin.Json Version Bumped On Change ✅ Passed Functional source files (src/main.js, src/streaming.js, src/transport.js) were modified with non-comment logic changes, and plugin.json version was bumped from 0.9.0 to 0.9.1 (strictly greater per...
No Per-Frame Dom Queries In Draw/Raf ✅ Passed The modified JS files contain no document.querySelector/querySelectorAll, requestAnimationFrame, draw function, or MutationObserver; the only setInterval is 200 ms and has no DOM query.
Shortcuts Unregistered With Matching Scope ✅ Passed The parent-to-current diff changes only src/main.js and adds no window.registerShortcut call; the shortcut cleanup check is not applicable.
Idempotent Guard On Top-Level Listeners ✅ Passed The PR does not modify screen.js, so the check for idempotent guards on new top-level listeners is not applicable. The check explicitly requires a screen.js diff.
Server_files Entries Are Safe Relpaths ✅ Passed plugin.json contains no server_files entries under settings or diagnostics. The PR only updates the version from 0.9.0 to 0.9.1, with no server_files entries added or modified.
Setrenderer Factory Has Init/Draw/Destroy ✅ Passed The PR does not add or modify any window.feedBackViz_ factory functions. Only src/main.js was changed, with a single line modification to playback resumption logic. The check is not applicable.
Overlay Gates On Isdefaultrenderer Instructions ✅ Passed This PR does not add overlay-style drawing code using highway.project() or highway.fretX(). It only modifies stems takeover state management and debug logging. The existing loading overlay uses DOM...
V3 Ui Mounts Via Playercontrolslot ✅ Passed PR introduces no new player-controls injection code. Changes focus on lifecycle management of _stemsRerouteInProgress flag, debug logging, abort signal handling, and transport play logic. Existin...
New Feedpak Manifest Keys Declared In Spec ✅ Passed This check applies only to feedBack core and feedBack-plugin-feedpakr repositories. This PR is for feedBack-plugin-stems, which is out of scope.
Feedpak Manifest Required Keys Present ✅ Passed Check applies only to feedBack core and feedpak-plugin-feedpakr manifest assembly. This PR modifies the feedback-plugin-stems plugin, which does not assemble manifests, making the check not applica...
Changelog Unreleased Section Updated ✅ Passed CHANGELOG.md was updated in the [Unreleased] section with a bullet point following Keep a Changelog format, documenting the behavioral changes to stems takeover pause-state handling and debug loggi...
New Python Modules Have Pytest Coverage ✅ Passed The pull request contains no new Python files. It only modifies src/main.js (JavaScript). The custom check is not applicable.
No Hardcoded Secrets Or Tokens In Diff ✅ Passed No hardcoded secrets, tokens, AWS keys, or PEM headers found in any added lines. Scan covered AWS-style keys (AKIA pattern), PEM private key headers, and sensitive variable assignments.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • ✅ Committed to branch successfully - (🔄 Check to regenerate)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pause-state-handling

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 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.

Inline comments:
In `@src/main.js`:
- Around line 212-215: Update onSongReady() to capture the current load
generation and create its per-call AbortController immediately after teardown(),
before any await. Guard S.sloppakActive updates, _stemsRerouteInProgress
assignment, and nativeCorePause(core) with a generation check; use the local
controller for all subsequent fetch and decode operations, and ensure stale
invocations exit without affecting the newer song.
- Around line 821-830: In the existing playback check around
nativeCorePaused(core), move both the _stemsRerouteInProgress assignment and
nativeCorePause(core) call inside the branch that confirms the core is currently
playing. Leave the existing check intact so paused cores neither set the reroute
flag nor invoke the no-op pause.
- Line 925: Update the results === null branch in the playback takeover flow to
invoke the same teardown and native playback fallback used by the graph-build
failure path before hiding the overlay and clearing _stemsRerouteInProgress.
Ensure S.sloppakActive is reset and the paused core element resumes native
playback when loadStems() fails.
- Line 904: Update the reroute flow around setupStreaming() and the graph path
so window._stemsRerouteInProgress remains true until transport.playing becomes
true; remove the immediate clear before transportPlay(), and clear the flag only
when playback starts or when takeover fails or is abandoned.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1c94d3ac-9900-4b64-aed5-891231d6ef34

📥 Commits

Reviewing files that changed from the base of the PR and between 7082b23 and 0d989de.

📒 Files selected for processing (1)
  • src/main.js

Comment thread src/main.js Resolved
Comment thread src/main.js Resolved
Comment thread src/main.js Resolved
Comment thread src/main.js Resolved
cchacs added 2 commits August 3, 2026 18:48
Added per-load generation/controller guards and local abort signal usage.
Prevented paused cores from triggering takeover pause logic.
Added teardown/native playback fallback when loadStems() fails.
Kept reroute state active until transport playback begins.
Added the requested Unreleased changelog bullet.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main.js (1)

891-895: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use the current playback intent before fallback playback.

wantedPlay becomes stale during asynchronous loading. A user pause sets S.pendingPlay = false, but all fallback paths still use the earlier value after teardown(). Read S.pendingPlay before teardown, then resume #audio only when the current intent is true.

🤖 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/main.js` around lines 891 - 895, Update the fallback playback logic
around teardown and the `wantedPlay` check to read the current intent from
`S.pendingPlay` before calling `teardown()`. Use that captured value after
teardown, and resume `#audio` only when it is true instead of relying on the
stale `wantedPlay` value.
🤖 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/main.js`:
- Around line 891-895: Update the fallback playback logic around teardown and
the `wantedPlay` check to read the current intent from `S.pendingPlay` before
calling `teardown()`. Use that captured value after teardown, and resume
`#audio` only when it is true instead of relying on the stale `wantedPlay`
value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e5f5fe86-42a8-4528-b4eb-6c279983a6f9

📥 Commits

Reviewing files that changed from the base of the PR and between 734351b and adac78e.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • src/main.js
  • src/streaming.js
  • src/transport.js

Use `S.pendingPlay` instead of the stale local playback flag when stem rerouting fails or decode returns null. This keeps the core audio player resuming only when playback is still pending at fallback time, avoiding incorrect pause/resume behavior during degraded recovery.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main.js (1)

924-937: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Use current pending-play state for graph-build fallback.

The results === null branch now snapshots S.pendingPlay correctly. However, the later buildGraphFromBuffers() failure still uses wantedPlay captured at Line 871, before asynchronous decoding.

If the user changes play intent during decoding, the fallback can resume after a pause or fail to resume after a new play request. Capture S.pendingPlay immediately before buildGraphFromBuffers() because that function calls teardown() and clears the pending state.

Proposed fix
-        const wantedPlay = S.pendingPlay;
...
+        const shouldResume = S.pendingPlay;
         if (!buildGraphFromBuffers(results, fullBuf)) {
...
-            if (wantedPlay) {
+            if (shouldResume) {
🤖 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/main.js` around lines 924 - 937, Update the buildGraphFromBuffers failure
path to snapshot the current S.pendingPlay immediately before calling
buildGraphFromBuffers, then use that snapshot for fallback resume behavior
instead of the stale wantedPlay value captured earlier. Preserve the existing
teardown and overlay cleanup flow.
🤖 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/main.js`:
- Around line 924-937: Update the buildGraphFromBuffers failure path to snapshot
the current S.pendingPlay immediately before calling buildGraphFromBuffers, then
use that snapshot for fallback resume behavior instead of the stale wantedPlay
value captured earlier. Preserve the existing teardown and overlay cleanup flow.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b1cf8152-8431-4f9f-abaf-95fc6274e0c3

📥 Commits

Reviewing files that changed from the base of the PR and between adac78e and 412e12b.

📒 Files selected for processing (1)
  • src/main.js

Use `S.pendingPlay` to decide whether playback should resume when graph rebuilding fails, instead of relying on `wantedPlay`. This preserves the user’s actual pending play intent and avoids leaving the player paused after a failed reroute fallback.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai Bot added a commit that referenced this pull request Aug 4, 2026
Docstrings generation was requested by @carochacs.

* #2 (comment)

The following files were modified:

* `src/main.js`
* `src/streaming.js`
* `src/transport.js`
@get-flashbacks get-flashbacks deleted a comment from coderabbitai Bot Aug 4, 2026
@cchacs
cchacs merged commit f8f2e0d into main Aug 4, 2026
1 check passed
@cchacs
cchacs deleted the pause-state-handling branch August 4, 2026 14:53
@cchacs
cchacs restored the pause-state-handling branch August 6, 2026 16:36
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