Repository navigation
feat(prompt-cache): add opt-in periodic prefill checkpoints - #2973
Merged
Merged
Conversation
An agent that rewrites or compacts its history deep into a long context loses the history-boundary snapshot, and the system-prompt root is far behind the edit, so the whole span after the root is prefilled again. With MLXCEL_PROMPT_CACHE_CHECKPOINT_INTERVAL on, a snapshot-family prefill also splits at every multiple of the interval (16,384 by default) before its history boundary and stores a Checkpoint snapshot there. The points are absolute multiples, so a hit on a checkpoint forwards the same pieces as the cold run of the same prompt. PrefillSplits now holds up to 16 points and the scheduler reserves room for the root and the history boundary. Checkpoints are exempt from the session-chain supersede rule and evicted by plain LRU. The chat_request test helper boxes its future so the root render tests pass on the default test stack. Replay on Qwen3.8-Flash-Next-OptiQ-2bit (M3 Ultra, 8 GiB snapshot budget): the turn that edits history 20K tokens into a 28K prompt adopts 16,384 tokens instead of 4,744, TTFT 22.16 s to 11.25 s; total TTFT 70.18 s to 58.66 s. Targeted unit tests, clippy and fmt pass. Refs #2885
4 tasks
3 tasks
This was referenced Nov 22, 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.
Second PR of #2885 Part B. An agent that rewrites or compacts its history deep into a long context loses the history-boundary snapshot, and the system-prompt root (#2950) is far behind the edit, so everything after the root is prefilled again. This adds opt-in periodic checkpoints.
Behavior
MLXCEL_PROMPT_CACHE_CHECKPOINT_INTERVAL=1(or an interval of at least 256 tokens) splits a snapshot-family prefill at every multiple of 16,384 before its history boundary and stores aCheckpointsnapshot at each point. Off by default, and ignored whenMLXCEL_DISABLE_BOUNDARY_SNAPSHOT=1.k * intervaltokens splits there. A hit on a checkpoint forwards the same pieces as the cold run of the same prompt.PrefillSplitsnow holds up to 16 points instead of 4. The scheduler reserves room for the root and the history boundary and keeps the deepest checkpoints, so a very long prompt never drops its history boundary.Measurement
Qwen3.8-Flash-Next-OptiQ-2bit on M3 Ultra, root on in both arms, 8 GiB snapshot budget. Session A turn 9 rewrites turn 6's user message, about 20K tokens into a 28K-token prompt:
docs/benchmark_results/qwen4-exp-prefill-checkpoints-replay-m3ultra-2026-11-12.md.Validation
Unit tests cover the checkpoint positions, the policy parser, the store's supersede exemption, and a scheduler run where an edited history adopts the last checkpoint and reproduces its cold run (chunked and unchunked). Targeted lib tests, clippy
-D warningsand fmt pass. Thechat_requesttest helper now boxes its future, because one #2950 test overflowed the default 2 MiB test stack outside the Makefile'sRUST_MIN_STACK.Not run: CUDA/ROCm, a small-memory Mac (#2883), the full workspace suite.
Refs #2885