Conversation
Each session-bank commit queues a snapshot settle and an SSD cold encode that pin the entry's snapshot until the engine is idle. Coalescing is per session, so many one-off sessions under continuous load grow the queue without bound and end in 507 memory refusals. Jobs now carry pinned_bytes; when the pending total exceeds MTPLX_PERSISTENCE_MAX_PENDING_BYTES (default 4G, "off" disables), the oldest pinned jobs are dropped. The newest job is always kept. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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.
Summary
Each session-bank commit queues a snapshot settle and an SSD cold encode on the idle-persistence lane, and every pending job pins its entry's snapshot until the engine is idle. Coalescing is per session, so an agent fan-out with many one-off sessions grows the queue without bound under continuous load. Active memory climbs until requests fail with 507 "sustained critical memory pressure during prefill", including small prompts.
This PR adds a total byte budget for pending persistence work:
pinned_bytes, which is the entry'snbytes.MTPLX_PERSISTENCE_MAX_PENDING_BYTES(default4G;offdisables the budget), the oldest pinned jobs are cancelled. The newest job and unpinned jobs are never dropped.persistence_pending_bytes,persistence_max_pending_bytesandpersistence_budget_dropped.Verification
tests/test_model_scheduler_persistence.pycover drop order, the newest and unpinned exemptions, the disabled budget, coalescing accounting and the env parsing.test_no_mlx_imports,test_public_cliandtest_runtime_kpis: 9test_public_clifailures are identical onmainwithout this change.Note: I made this fix recently and have only run the short load test below so far. I am continuing to test it on longer runs and will update this PR with the results.
Benchmark Evidence
Setup: Apple M5 Max, 128 GB, macOS 26.4, mlx 0.32.2, mtplx 2.12.0 with this change on commit 33a554b. Model
Youssofal/Qwen3.8-Flash-Next-MTPLX-Optimized-Speed, profile turbo, MTP depth 3, fan mode default, 2026-09-26.Load: 4 concurrent clients. Each request is a new session with a ~1.4k-token shared system prompt, max_tokens 120 and thinking off. SSD session cache on.
Without the budget, an overnight agent run hit the 507 wall roughly every 20 minutes (79 refusals). With the budget, the queue still drains to SSD once the engine is idle.