mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1959] [CLOSED] serve: --prompt-cache-spread, checkpoints kept spread back from the conversation's end (opt-in) #3776
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#3776
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/1959
Author: @xrip
Created: 10/11/2026
Status: ❌ Closed
Base:
main← Head:pr/prompt-cache-spread📝 Commits (1)
58cf9f4serve: --prompt-cache-spread, checkpoints kept spread back from the conversation's end (opt-in)📊 Changes
4 files changed (+93 additions, -2 deletions)
View changed files
📝
docs/DETAILS.md(+14 -0)📝
include/strata/program/conv_cache.hpp(+22 -0)📝
src/program/conv_cache_test.cpp(+45 -0)📝
src/program/generate.cpp(+12 -2)📄 Description
What
Opt-in
--prompt-cache-spread: when the conversation checkpoints are over--prompt-cache, the one that leaves ischosen so that the kept ones stay spread back from the conversation's end, instead of the least recently used. Without
the flag nothing changes.
Why
The engine keeps 6 checkpoints and rotates them by least recent use. Every turn adds one at its start, so after a few
short turns all of them sit within the last 1-2K tokens (plus the pinned system-prompt root). That is fine while a
client only appends. Agent clients do not always: they trim an old tool output, drop a step, or rewrite an earlier turn
a few thousand tokens back. The new prompt then matches none of the recent checkpoints, the resume falls back to the
system prompt, and the whole conversation is read again.
Found with the pi coding agent (and the pi-blackhole extensions) on a long agent session, from the engine log:
In both, a checkpoint a few thousand tokens before the edit would have saved most of the read; least recent use had
rotated those out.
How
conv_cache::spread_victim(include/strata/program/conv_cache.hpp): over the chain (ascending), the victim is thecheckpoint whose removal leaves the smallest gap for its distance from the newest one,
(len[i+1] - len[i-1]) / (len[newest] - len[i-1]). Dense recent points go first, so the kept ones thin outgeometrically towards the root. Never the root, the newest or a pinned (
strata_prefix) one; the--prompt-cache-tailcheckpoint first, as in the existing policy; with no candidate, the existing policy.generate.cpp: the flag, and the choice between the two policies at the one place a checkpoint is dropped.In a simulation of 200 turns of 1,000 tokens after a 9,525-token system prompt (
conv_cache_test):Measured
2x CMP 50HX (Turing sm_75,
--layer-split auto), 2x Xeon E5-2670 v2, 64 GB RAM, Qwen3.8-Flash-Next IQ3_XXS, CUDA 13.3,GCC 14. An 82,593-token conversation (a 65K-token document, then 20 short turns sent 2 at a time, each request
continuing the previous one), then the same conversation with a turn ~6 steps back rewritten and a question; greedy,
thinking off:
--prompt-cache-spread--prompt-cache 0(read in full)With the expert placement fixed (
--adapt-swaps 0 --pcie-frac 0.17) the answer after the resume was the same text asthe full read. Without fixing it, two full reads already differ in wording (the placement moves with timing), so that
comparison needs the fixed placement.
Tests:
conv_cache_testpasses, with the new cases (the simulation above against least recent use; every candidatepinned and one slot fall back to the existing policy). Not run on Windows or HIP.
Relation to #1937
Found while measuring the disk tier of #1937 on the same agent sessions, with a diagnostic that logs how many tokens a
request read again although a held conversation had them. It is independent of #1937: any long conversation whose
client edits its history benefits, with or without parked conversations.
How to try
Add
"--prompt-cache-spread"to the config'sargs.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.