MTPLX icon indicating copy to clipboard operation
MTPLX copied to clipboard

[BUG] 2.1.0: SSD session restore degrades tool-call quality, then the SessionBank writer crashes the server ("There is no Stream(gpu, 1) in current thread")

Open druide67 opened this issue 4 months ago • 1 comments

Summary

With --ssd-session-cache on, tool sessions restored after a daemon restart first lose tool-call quality, then the SSD writer crashes the whole server. On a fresh server the cache is quality-neutral. The failure only appears on the restore path, which 2.1.0 ships as a headline feature (#159).

Disclosure up front, in the spirit of #151: numbers were measured with asiai, an open-source Apple Silicon bench tool I build; the report was drafted with AI assistance; every number below reproduces from the commands included.

Environment

  • MacBook Pro M5 Max, 128 GB, macOS 26.5.1 (25F80)
  • MTPLX 2.1.0 (brew tap, venv-2.1.0, mlx 0.32.0), Python 3.13.14
  • Model: Youssofal/Qwen3.6-27B-MTPLX-Optimized-Speed (backend qwen3_next, contract=true)

Repro

Server (loopback, serial scheduler, MTP depth 3, turbo):

python -m mtplx.server.openai --model ~/.mtplx/models/Youssofal--Qwen3.6-27B-MTPLX-Optimized-Speed \
  --host 127.0.0.1 --port 8081 --depth 3 --generation-mode mtp --profile turbo \
  --reasoning-mode off --scheduler-mode serial --batching-preset latency \
  --ssd-session-cache on --ssd-session-cache-max-size 20GB \
  --tool-prompt-mode hybrid --chat-template-profile local_qwen36 \
  --temperature 0.6 --top-p 0.95 --top-k 20 --no-enable-thinking --no-stats-footer

Load: a deterministic 8-turn agentic file-editing session with tool calls (uv tool install asiai, then asiai bench --code --code-suite tool-call --runs 1 --url http://127.0.0.1:8081 --code-output out.json). Then kill the server, relaunch with the same flags, re-run the suite, and repeat once more. The per-turn scores and cached_tokens land in out.json.

What happens

Run Condition clean turns Notes
1 fresh server, cache on 22/24 (91.7%) identical to --ssd-session-cache off; cache active (cached_tokens 768 to 2048/turn)
2 after restart 1 (SSD restore active from turn 1) 6/8 (75%) 2 broken edit_file turns
3 after restart 2 3/8 (37.5%), then server death see below

Run 3 sequence: on turn 3 the tool call leaks as raw <tool_call> XML into content (never parsed into tool_calls), then the SSD writer crashes and every subsequent request fails at the socket (server process gone, health unreachable):

SessionBank SSD write failed entry_id=c27ed9f36a966b486a29b5e6b48b942a: RuntimeError: There is no Stream(gpu, 1) in current thread.

The postcommit log lines just before the crash show mode: retokenized_history with unsafe_reason: "tool_call_history_rewrite". macOS wrote a crash report for the process (Python-2026-07-17-184608.ips, bug_type 309); happy to attach it.

Baseline for comparison: --ssd-session-cache off, same server flags, same suite, 24/24 turns across 3 runs with zero incidents (91.7% clean, the 2 misses being a separate template issue I'm filing right after this one).

Expected

Restored sessions should either serve correct state or fall back to a cold prefill; and a failed SSD write should never take the serving thread down.

Happy to run instrumented builds or provide the full JSON/logs.

druide67 avatar Jul 17 '26 19:07 druide67

Fixed in 2.2.0. Your diagnosis was right: the SessionBank writer thread was touching MLX tensors off the model-owner thread, which is what produced the "There is no Stream(gpu, 1) in current thread" crash under write pressure.

The fix restructures the writer so tensors are encoded at enqueue time on the owner thread, and the background writer only ever handles plain bytes. The writer thread can no longer touch MLX at all, by construction. The restore-quality half of your report (degraded tool calls after an SSD restore) came from the same lane and is covered by the boundary-retention work in this release.

Update to 2.2.0 and this crash is gone. Thanks for the clean stack trace, it pointed straight at the thread boundary.

youssofal avatar Jul 19 '26 07:07 youssofal