mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #62] [MERGED] serve: the conversation cache keeps its shared prefix; the rest rotates LRU #2435
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#2435
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/62
Author: @j-luwierski
Created: 9/28/2026
Status: ✅ Merged
Merged: 9/28/2026
Merged by: @Niko1221
Base:
main← Head:feat/radix-conv-cache📝 Commits (1)
6fb2085serve: the conversation cache keeps its shared prefix; the rest rotates LRU📊 Changes
5 files changed (+144 additions, -9 deletions)
View changed files
📝
CMakeLists.txt(+4 -0)📝
docs/DETAILS.md(+8 -4)➕
include/strata/program/conv_cache.hpp(+43 -0)➕
src/program/conv_cache_test.cpp(+67 -0)📝
src/program/generate.cpp(+22 -5)📄 Description
What
The serve loop keeps up to six conversation checkpoints (~118 MB each, taken at turn boundaries and
every
--prompt-cache-everyprompt tokens). The old policy was first-in-first-out: the oldest left— and the oldest is in practice the end of the system prompt, the prefix every new chat of the same
client shares. Once it was gone, a new chat re-read the whole prefix at prefill speed.
This changes the retention: the chain's root — the deepest point every kept conversation shares — is
pinned, the rest rotates by least recent use, and mounting through a checkpoint re-dates it.
--prompt-cache 1switches the pin off and returns the old behaviour exactly.Why a policy and not a radix tree
The request loop erases any checkpoint that is not a prefix of the current prompt (the KV cache is
one arena, one branch of history at a time), so the retained checkpoints are always a prefix chain —
a radix cache's tree collapsed onto the one branch the session can hold. A trie over it would have
exactly one path; the live question is only what to drop.
conv_cache.hppis that decision as onepure function, with the reasoning in its header comment.
User-visible effect
A new chat that shares a long system prompt starts reading after the prefix instead of from token 0.
Measured on the first message of a new chat with a 16,747-token system prompt: 14,898 ms → 1,176 ms
(12.7x); a 30K prompt saves roughly 25–30 s per chat start at ~1,100 tok/s. Coding agents and API
clients that open a fresh conversation per task feel it on every task. Continuing an existing
conversation, decode speed, the memory budget (still 6 × 118 MB) and — verified token for token —
the answers themselves are unchanged.
Verification
conv_cache_test.cpp— the policy's scenarios: the root is never a victim, leaves rotate LRU, amount re-dates a checkpoint, the cap<2 guard. Passing (7 checks).
(
--adapt-every 100000); the driver and raw per-request metrics live outside the PR and can beattached on request.
The measured request — the first message of a new chat sharing the system prompt:
--prompt-cache 1(the restored read starts on a 2,048-token chunk boundary, so the fresh part's floating-point
order matches a full read).
(A1 48.4/48.4, B1 56.8/57.1, B2 63.2/63.2, A8 63.2/63.1).
checkpoint_save/checkpoint_restoreand the state format are untouched, soSTRATA_CKPT_REREAD's token-for-token guarantee is unaffected.Docs
docs/DETAILS.md: the conversation-cache paragraph and "Current limits" now describe theshared-prefix retention (switching chats re-reads only the part where they diverge).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.