Repository navigation
Jetsam-proof stem separation: headroom gates and playback-start hold - #86
Merged
sanylax0 merged 1 commit intoJul 18, 2026
Conversation
RCA identified the ORT session load (~600 MB transient) plus the first HT-Demucs window's attention arena (up to ~1.7 GB) as the app's largest allocation, landing exactly when playback, UI, and (first run) the model download are also ramping — a per-process-limit kill on devices with a tight cap. Three structural guards: - Hard start gate: a separation may not begin unless os_proc_available_memory headroom exceeds a required budget (1400 MB to start; tune from mem[] breadcrumbs). Deferred work retries on later ensureStems passes. - Per-window floor: abort before the next window if headroom falls under 600 MB, via the existing abort/cleanup path. - Playback-start hold: the session's first stem demand arms a 60 s hold so the peak never stacks on engine/UI ramp-up; one scheduled retry re-drives ensureStems after the hold.
sanylax0
approved these changes
Jul 18, 2026
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
PR 2 of the jetsam RCA plan — makes the leading kill scenario structurally impossible instead of hoping mitigations fit under the (possibly iOS-26-tightened) per-process cap.
The RCA sized the stem-separation peak at: ~330 MB fp32-upcast weights + ~300 MB protobuf load transient + up to ~1.7 GB first-window attention arena — landing exactly when playback, UI, and (first run) the silent 158 MB model download are also ramping. The merged arena shrinkage only frees memory after a run, so it cannot cap the first-window peak.
How
Three guards, all reusing existing plumbing:
PreparationQueue+Stems.separateStems): after acquiring the separation slot, the task checksos_proc_available_memoryheadroom againstStemSeparationBudget.requiredStartMB(1400 MB initial value — tune from themem[]breadcrumbs of the diagnosis run) and defers cleanly (slot released, in-flight key removed, session freed if idle) when short. Deferred tracks retry on every subsequentensureStemspass.StemSeparator.ortInference): abort before the next window if headroom drops under 600 MB — proactive version of the existing memory-warning abort, using the same partial-stems cleanup path.ensureStems): the session's first stem demand arms a 60 s hold; separations are skipped during it and one scheduled retry re-drivesensureStemsafter the hold, so the ORT peak never stacks on engine/UI/download ramp-up and stems still arrive mid-song.MemoryFootprintgains a reusableheadroomMBaccessor.Testing
On device (after merging with #85's diagnostics): fresh launch → play an un-separated track → the console should show either the hold ("no separation in the first minute") followed by a normal separation, or a
deferring separation … MB headroomnotice — and no kill. Note: if the diagnosis run shows the real cap is lower than assumed, adjustStemSeparationBudget.requiredStartMBaccordingly.🤖 Generated with Claude Code
https://claude.ai/code/session_013TJoWkqg8bzkGdzxWhWjWP
Generated by Claude Code