/
/
# What does this implement/fix? The audio-analysis controller frees a provider's ML models after 5 minutes with nothing being analysed. It decides "nothing is being analysed" from the active-session list — but a session is removed from that list the moment `finalize()` is *dispatched*, and `finalize()` is exactly where the heavy whole-track work runs (beat inference, DBN decode, vocal inference, CLAP windows). So a track whose analysis takes longer than the idle window has its models freed out from under it. Smart Fades then records a retryable failure and skips that track for 24 hours; Sonic Analysis silently drops the CLAP windows that were still queued and stores the track without them — permanently, since the track counts as analysed. Measured on an M-series core (single thread, the same per-op budget a 4-core Pi gets), the finalize inference alone is ~21s for a 5-minute track, ~38s for 10 minutes and ~111s for 30 minutes — and it doubles again while a player is streaming, because of the beat-window pacing. On the ARM/low-power hardware Music Assistant targets that comfortably passes the 5-minute window for longer tracks, and tracks up to 30 minutes are analysed. The fix is to stop lying about what "idle" means: in-flight finalizes now count as activity, so the models stay loaded until the analysis that is using them is actually done. ## Changes - Track the dispatched `finalize()` tasks in the controller. - The idle-model monitor treats an in-flight finalize like an active session and keeps its timer fresh, so the models are only freed once the last analysis has finished. - Add a regression test covering both halves: no unload while a finalize is running, and the unload happening once it completes. ## Types of changes - [ ] Bugfix (non-breaking change which fixes an issue) — `bugfix` - [ ] New feature (non-breaking change which adds functionality) — `new-feature` - [ ] Enhancement to an existing feature — `enhancement` - [ ] New music/player/metadata/plugin provider — `new-provider` - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) — `breaking-change` - [ ] Refactor (no behaviour change) — `refactor` - [ ] Documentation only — `documentation` - [x] Maintenance / chore — `maintenance` - [ ] CI / workflow change — `ci` - [ ] Dependencies bump — `dependencies` ## Checklist - [x] The code change is tested and works locally. - [x] `pre-commit run --all-files` passes. - [x] `pytest` passes, and tests have been added/updated under `tests/` where applicable. - [ ] For changes to shared models, the companion PR in `music-assistant/models` is linked. - [ ] For changes affecting the UI, the companion PR in `music-assistant/frontend` is linked. - [x] I have read and complied with the project's [AI Policy](https://github.com/music-assistant/.github/blob/main/AI_POLICY.md) for any AI-assisted contributions. - [ ] I have [raised a PR against the documentation repository](https://github.com/music-assistant/music-assistant.io/blob/main/CONTRIBUTING.md) targeting the main or beta branch as appropriate.