Skip to content

Preserve GLM prompt cache across last-turn rewinds - #569

Closed
otarkhan wants to merge 1 commit into
ashhart:python-0.6from
otarkhan:fix/glm-rewind-checkpoints
Closed

otarkhan wants to merge 1 commit into
ashhart:python-0.6from
otarkhan:fix/glm-rewind-checkpoints

Conversation

@otarkhan

Copy link
Copy Markdown
Contributor

Deleting or replacing the latest user exchange made GLM discard a reusable prompt prefix and prefill the shared history again. This change retains a checkpoint immediately before the latest user message alongside the existing prompt-end checkpoint, so replacements can resume from the shared history while ordinary continuations still use the later checkpoint.

Prefill stops at the rewind boundary to capture recurrent, convolution, pending MTP, and DFlash ring state before later rows overwrite it. Rank 0 sends the boundary to its peer, and cache eviction preserves the newest checkpoint while favoring rewind history within the existing entry and byte limits.

Validation: 28 targeted CPU tests passed, 1 skipped. The new request-flow test runs the real GLM engine and prefill cache path with GPU arithmetic stubbed. A CUDA state-parity test was added but could not run on this Mac. Live CUDA tensor-parallel and client behavior have not been tested or deployed.

@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @otarkhan. Keeping a checkpoint just before the latest user message, so that a rewind or an edited last turn doesn't prefill the shared history again, is exactly the right idea, and stopping the prefill at that boundary to capture the recurrent, convolution and ring state is the hard part done carefully.

This changes the Python GLM engine, which main no longer carries: the Python engine is frozen at 0.6.6 and we're retiring it rather than adding to it, so we're closing this instead of merging it. The idea carries straight over to the native engine's shared prompt cache (zig/src/core/prompt_cache.zig), which GLM, Flash Next and the Qwen3.8-27B use. A pull request there that keeps a state at the last user message's boundary, with a resumed prompt equal to a fresh one, would be very welcome.

@ashhart ashhart closed this Oct 10, 2026
@otarkhan

Copy link
Copy Markdown
Contributor Author

Sorry, my bad. Lemme re-open it on the latest TensorFold

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.

2 participants