Flash-Next: engine deadlock when ssd-session-cache is enabled and an incremental session crosses ~131K tokens (2.10.1)
Summary
With --ssd-session-cache enabled (any of on / write-only), an incremental
chat session on Qwen3.8 Flash-Next deadlocks the whole generation engine
the moment the appended transcript crosses roughly the 131K-token line. The
HTTP layer stays up (/v1/models answers), but every generation request —
including a fresh 1-message request — blocks forever. CPU sits at ~0%, all
threads parked in __psynch_cvwait. Reproduced 3/3 at the same turn.
With the cache off, the identical workload runs clean past 184K tokens.
Environment
- MTPLX 2.10.1 (brew), MLX from the 2.10.1 venv
- macOS 26.x, MacBook Pro M5 Max, 128 GB
- Model:
Youssofal/Qwen3.8-Flash-Next-MTPLX-Optimized-Speed - Serve:
--reasoning off --mtp --profile turbo --context-window 262144 --ssd-session-cache on --ssd-session-cache-dir <dedicated dir> --ssd-session-cache-max-size 60GB --temperature 0.3 --top-p 0.9 --top-k 40
Repro
Append user turns of ~23K tokens each (role:user filler + short assistant
"OK"), i.e. the standard agent-transcript growth pattern:
turn1: prompt=22889 ok (20s)
turn2: prompt=45976 ok (26s, cached=22891)
turn3: prompt=69023 ok (26s)
turn4: prompt=91971 ok (26s)
turn5: prompt=115068 ok (27s) <- ~4.7 GB snapshot committed for this prefix
turn6: prompt=138121 HANG <- engine never recovers; all later requests hang
Discrimination matrix (same 8-turn workload)
| config | result |
|---|---|
--ssd-session-cache off (sparse prefill on) |
CLEAN through 184K, ~27s/turn |
--ssd-session-cache on |
HANG at turn 6 (~138K) |
--ssd-session-cache write-only |
HANG at turn 6 |
cache on + MTPLX_SESSION_BANK_MAX_BYTES=40G |
HANG at turn 6 |
cache on + MTPLX_QSA_PREFILL=0 |
HTTP 507 at turn 4 (expected — dense path doesn't fit; not usable as a workaround) |
write-only hanging too points at the cold-tier write path rather than
restore/eviction. The RAM-bank budget override changing nothing points away
from the yield/eviction budget.
Stack sample at the hang
sample <pid> 5 shows the main thread and workers all in
std::condition_variable::wait / __psynch_cvwait; the tokenizers rayon pool
is idle-parked; no thread makes progress. Full sample available on request —
excerpt:
18 _pthread_cond_wait + 980 -> __psynch_cvwait
9 std::condition_variable::wait(std::unique_lock<std::mutex>&) + 32 -> __psynch_cvwait
(rayon WorkerThread::wait_until_cold x16 — idle pool)
Also worth noting
- Restores themselves work beautifully below the line: an 89,600-token prefix restored from the SSD tier in 2.0s after a full server restart (and 2.10.0's snapshots restored fine under 2.10.1).
- The hang window (~131K = half the 262,144 window / the auto "dense-decode ceiling" figure printed at startup) may be a hint: the last successful turn is 115K, the hanging one is 138K.
Happy to run instrumented builds or provide the full sample output.
Root cause narrowed + verified workaround.
The 131,072 trigger is not arbitrary: it coincides exactly with _dense_decode_max_context()'s default in generation.py — the point where decode repages from the contiguous-dense layout to the paged cache class. The deadlock appears to be that repage transition interacting with SessionBank snapshotting, not the cold-tier file write itself (which drops rather than blocks on backpressure, per _admit_write).
Evidence: with MTPLX_SUSTAINED_DENSE_DECODE_MAX_CONTEXT=262144 (decode stays dense across the whole window; this model's KV is ~24 KB/token so the dense slab at 262K is ~6 GB), the identical 8-turn incremental build that deadlocked 3/3 at ~138K now runs clean to 184,324 tokens with --ssd-session-cache on:
turn5: wall=26s prompt=115053 cached=91958
turn6: wall=27s prompt=138121 cached=115055 <- previously hung here, 3/3
turn7: wall=27s prompt=161312 cached=138123
turn8: wall=27s prompt=184324 cached=161314
A full server restart followed by a restore of that session also works: 184,326 tokens restored from SSD in 12 s, correct recall.
So the repro from the issue body becomes a clean bisect: same script, cache on, flip only the dense-ceiling env — hang at the 2^17 crossing with the default, clean through 184K when decode never repages. Suggests looking at snapshot_cache/session_bank.put against the paged cache class (or a session captured mid-transition).
Environment: MTPLX 2.10.1, macOS 26.4.1, M5 Max 128 GB, Qwen3.8-Flash-Next-MTPLX-Optimized-Speed.
Your trigger analysis is confirmed against the source. 131,072 is exactly the default of _dense_decode_max_context() in generation.py, the boundary where decode repages from the contiguous dense layout to the paged cache class, so the deadlock sits in the repage plus SessionBank snapshot interaction your trace points at. The narrowing plus the verified workaround make this directly actionable. It is not fixed in 2.10.2; this stays open until the fix lands. Thank you for the depth of the narrowing, it saved the reproduction hunt.
Tested on 2.11.2 (build 2011020) with your serve line: Flash-Next Optimized-Speed, turbo, --ssd-session-cache on in a dedicated directory with a 60 GB cap, context window 262144, depth 3. One session, eight turns of about 23K new tokens each, prompt growing from 25,124 to 186,151 tokens. It crossed 131,072 at turn 6 (140,143 tokens) and answered every turn: time to first token 20.2 s at turn 1 and 28.9 s at turn 8. No hang. The SSD cache wrote 6.3 GB during the run and the shutdown flushed its last pending write in 7.3 s. Every prefix restore came from RAM in 2 to 10 ms, because on a 128 GB machine the bank kept the whole session.
What this run did not cover is a restore from SSD after the bank evicted the session, which is what a smaller bank or a busier machine would do at that boundary. If 2.11.2 still hangs for you, the serve log around the stall plus the output of mtplx trace live --port <port> from the hung daemon would pin that path down.
On 2.12.0 this looks resolved by the #505 fix.
#403's discrimination matrix pinned the hang to the cold-tier write path — write-only hung too, and the RAM-bank budget override changed nothing — with every thread parked in __psynch_cvwait. That is exactly what #505 addressed: the cold-tier encode used to hold the model owner thread (500+ s in that report) with no bound because the abort check preceded an uninterruptible mx.eval(). 2.12.0 does the SSD save in ≤32 MiB pieces and yields to waiting work in under 200 ms (/health now reports encode_units / encode_slow_units / encode_longest_unit_s).
On the same hardware and model as this report (M5 Max 128 GB, Flash-Next Optimized-Speed, --ssd-session-cache on --context-window 262144), incremental sessions on 2.12.0 cross well past the ~131K line without the engine hang — our deepest reached ~180K.
One honest caveat: we also serve with MTPLX_SUSTAINED_DENSE_DECODE_MAX_CONTEXT=262144, which we had found on 2.10.x defused the >131K repage path, so I can't yet claim the deadlock is gone with a stock config. I can run the exact 8×23K crossing-131K repro on 2.12.0 without that env to confirm the root cause is fixed, and will post the result if useful.
Closing this, since you confirmed it on 2.12.0. The hang matches what #505 fixed: the SSD save held the model thread with no bound, and since 2.12.0 a waiting request pauses the save in under 200 ms. 2.12.1 also changes how saves replace old entries: a new save is written beside the old one, and the old one is retired only after the new one is in place.
Thank you for the thorough narrowing.