mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #8] [MERGED] Conversation cache: keep the chat between requests, read only what is new #2410
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2410
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/8
Author: @Mirtraxxx
Created: 9/26/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @Niko1221
Base:
main← Head:conversation-cache📝 Commits (1)
23f6b15serve: conversation cache - keep the chat between requests, read only what is new📊 Changes
5 files changed (+329 additions, -23 deletions)
View changed files
📝
README.md(+2 -2)📝
docs/DETAILS.md(+8 -3)📝
include/strata/core/mtp.hpp(+2 -0)📝
serve/server.py(+4 -0)📝
src/program/generate.cpp(+313 -18)📄 Description
What it does
Right now every request starts from an empty session and reads its whole prompt again. In a long chat or an agent
loop, every turn waits for the full prefill. That's the main complaint in the r/LocalLLaMA thread ("throws away the
KV cache every prompt").
With this change the engine keeps the conversation and reads only the new part:
<|im_start|>of everyprompt, where the history ends and the new assistant header begins, and one every 16K freshly read tokens. A
rebuilt chat history (the client re-sends the messages, the template re-renders them) still matches the one
taken before its last turn, so only the last reply and the new message are read.
and the PLE history: the same set
Verifier::commitrolls back. The KV cache and the pooled indexer keys arepositional. A query only reads cells below it, and
deadfor its own block, so stale cells past a rewind pointare never read and get overwritten.
compared by a hash of their embeddings and grid, so a different picture of the same size never matches.
Checkpoints whose cells the next request will overwrite are dropped.
Measured
RTX 3090 24 GB, Ryzen 7 5700X, 64 GB DDR4-3000, Windows 11, Swift 1.5 IQ2_XS,
--expert-cache auto, MTP--spec 4.Agent-style session through
serve/server.py: OpenAI streaming, one tool, thinking on, reasoning sent back each turn.Is it exact?
STRATA_CKPT_REREAD=1makes the engine read a checkpoint's tokens again from position 0, in the same chunks therequest that saved it used, instead of restoring it.
STRATA_STATE_HASH=1prints a fingerprint of every part of the session after each request: GDN states, PLEhistory, indexer tails, pooled keys, the KV cells
[0, L)of all 12 QSA layers, the MTP K/V, andple_prev.--adapt-swaps 0, sothe VRAM expert set is fixed. Restore and re-read gave identical fingerprints for every component after every
turn, and identical tokens and draft counts.
Protocol (backward compatible)
RESUME <n>before reading,PP <pos> <n> <ms> <fresh tok/s>per chunk, andREUSED <n>oncethe prompt is read.
DONEgains<drafts accepted> <drafts offered> <reused>after the existing fields.serve/server.pyignores lines it doesn't know. One change:PPlines now count as a heartbeat. They arriveevery few seconds, which kept resetting the 10 s wait, so a long prompt sent no keep-alives at all: 0 in a
41-second prefill before this change, 6 after.
Options
--prompt-cache N: checkpoints kept (default 6;0restores the old behaviour).--prompt-cache-every N: periodic checkpoint spacing (default 16384;0= only at the turn boundary).--turn-token ID: the token that opens a turn (default 248045,<|im_start|>).Limits
even for a few dozen tokens.
Made with Claude Code (Claude Opus 5.5); tested on the hardware above.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.