Stop the audio analysis background scan from spawning a task per track - #6384
Merged
marcelveldt merged 3 commits intoSep 19, 2026
Merged
Conversation
Contributor
|
✅ The title and description are good to go. Thanks! |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The worker-count regression needs a targeted automated test.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Bounds background audio-analysis scans to fixed worker concurrency, preventing task counts from scaling with library size.
Changes:
- Replaces per-candidate tasks and semaphore with iterator-driven workers.
- Counts unclaimed candidates as deferred.
File summaries
| File | Description |
|---|---|
music_assistant/controllers/streams/audio_analysis.py |
Implements the bounded worker pool and deferred counting. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
_run_background_scan fetched every candidate (limit=0) and handed the whole list to asyncio.gather, so one Task was created per library track before any analysis began. A profiler capture from a 10,709-track install showed 7,914 tasks parked on the semaphore for the whole run, out of 8,005 in the process. The semaphore bounded the concurrent work but not the task objects, and the cost grows linearly with library size. Spawn `concurrency` workers that pull from a shared iterator instead. Only that many tasks exist at a time, which makes the semaphore redundant. Candidates left unpulled when the run budget expires are counted as deferred, as before. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M3jXPrteRvvgAPD7xvXcFH
It narrated the change rather than the code as it stands. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M3jXPrteRvvgAPD7xvXcFH
marcelveldt
force-pushed
the
fix/background-scan-worker-pool
branch
from
September 19, 2026 12:24
dff9a13 to
bdf4bef
Compare
marcelveldt
marked this pull request as draft
September 19, 2026 12:25
marcelveldt
marked this pull request as ready for review
September 19, 2026 12:36
github-actions Bot
pushed a commit
that referenced
this pull request
Sep 19, 2026
#6384) The nightly background audio-analysis scan created one asyncio task per candidate track up front. On large libraries that parked thousands of idle tasks for the whole run. Workers now pull from a shared iterator, so only the configured concurrency runs at a time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What does this implement/fix?
This PR is best reviewed ignoring white space.
The nightly background audio-analysis scan created one asyncio task per candidate track up front, before any analysis started. On a large library that parks thousands of idle tasks for the whole run (one live install held 7,914 on a 10,709-track library), adding to event-loop pressure.
Workers now pull from a shared iterator, so only the configured concurrency runs at a time, no matter how big the library is. Deferred tracks are counted from what the workers never reached. The run budget, provider-availability skips, the processed counter and the existing log lines are unchanged.
Changes
Related issue (if applicable):
Types of changes
bugfixnew-featureenhancementnew-providerbreaking-changerefactordocumentationmaintenancecidependenciesChecklist
pre-commit run --all-filespasses.pytestpasses, and tests have been added/updated undertests/where applicable.music-assistant/modelsis linked.music-assistant/frontendis linked.