Skip to content

Jetsam-proof stem separation: headroom gates and playback-start hold - #86

Merged
sanylax0 merged 1 commit into
mainfrom
claude/repo-review-improvements-yvk3t7-separation-headroom-gate
Jul 18, 2026
Merged

sanylax0 merged 1 commit into
mainfrom
claude/repo-review-improvements-yvk3t7-separation-headroom-gate

Conversation

@sanylax2

Copy link
Copy Markdown
Collaborator

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:

  1. Hard start gate (PreparationQueue+Stems.separateStems): after acquiring the separation slot, the task checks os_proc_available_memory headroom against StemSeparationBudget.requiredStartMB (1400 MB initial value — tune from the mem[] 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 subsequent ensureStems pass.
  2. Per-window floor (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.
  3. Playback-start hold (ensureStems): the session's first stem demand arms a 60 s hold; separations are skipped during it and one scheduled retry re-drives ensureStems after the hold, so the ORT peak never stacks on engine/UI/download ramp-up and stems still arrive mid-song.

MemoryFootprint gains a reusable headroomMB accessor.

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 headroom notice — and no kill. Note: if the diagnosis run shows the real cap is lower than assumed, adjust StemSeparationBudget.requiredStartMB accordingly.

🤖 Generated with Claude Code

https://claude.ai/code/session_013TJoWkqg8bzkGdzxWhWjWP


Generated by Claude Code

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
sanylax0 merged commit e1f6b17 into main Jul 18, 2026
1 of 4 checks passed
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.

3 participants