mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #1938] Proposal: Add a Per-Slot Cached-Prefix Limit to Conversation Cache #769
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#769
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?
Originally created by @TwoAnts on GitHub (Oct 11, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1938
In memory-constrained setups (4–8 GiB for conversation cache), full-slot KV snapshots(262144 context) are too large: INT8 KV ≈ 3.3 GiB/slot, FP16 KV ≈ 6 GiB/slot. As a result, only a few slots fit, and new ones evict existing ones.
Add an option like
--conversation-cache-slot-max-preserve N(or shorter:--conversation-cache-slot-prefix N) to cache only the first N tokens of each parked slot. Later updates are not cached. This lets more slots retain a useful common prefix and improves cache utilization.I recently ran into the issue with hermes agent + strata: hermes agent has a background review that reuses the main conversation branch and triggers a fork (according to AI analysis), causing subsequent main-conversation turns to fail to find a prefix. The experience is painful—every background review forces a long re-prefill wait.
Of course, if the issue isn't the slot being evicted into the conversation cache, but rather the fork occupying the main conversation's slot and advancing past several checkpoints, thereby causing the main conversation to lose its prefix, that would be a separate issue.
@CC-David-CC commented on GitHub (Oct 11, 2026):
hey. uhm. you dont want what* you think you want
@CC-David-CC commented on GitHub (Oct 11, 2026):
i'm already working on something better than this
@CC-David-CC commented on GitHub (Oct 11, 2026):
and it is working in generated harness data with high enough accuracy to be called basically lossless - it will speed up your issue compared to per slot prefix cache. if this passes tests on hardware i'll be pushing it live tonight for you.
please take the time to appreciate the beautiful yarn to rope, rope to yarn math i learned just a few days ago being applied in a novel way.
i've not seen this in any other engine......blah
cuda error
@TwoAnts commented on GitHub (Oct 11, 2026):
Haha, looking forward to it!😊😊😊
@CC-David-CC commented on GitHub (Oct 11, 2026):
klsajdf;hklkhjlasdf. 26/27 worked. fffff
the final long run is underway, followed by the queued G1 suite for the corrected build. G3 remains uncertified. but it doesnt matter because 1 of the tests failed.
I think i might need to sleep - been thinking about this longer than overnight. .. ...
it might not clear my brain and give me an answer but will certainly help me be a little nicer
does anyone want to beat their head against a dumb (meaning i dont have the answer already.) problem?
give an agent a reliable way to explore alternatives from the same point. Imagine an agent that has already processed an entire repository. It can try three fixes, test competing assumptions, or follow different tool results while keeping a common starting state.
The payoff is efficiency and trust. Expensive prefix computation can be reused, while every branch must behave as though it had been run independently from the beginning. A failed experiment can be discarded; a useful one can become the current branch. Rewinding has a precise meaning. If every cached checkpoint disappears, the recorded history still defines what must be reconstructed. That turns an expensive conversation into a reusable foundation for experimentation, with an explicit correctness contract for isolation, recovery, and reproducibility.
How it works: keep one immutable history, with movable branch references pointing into it. Snapshots also identify the RNG draw state, grammar state, and generation frontier. Checkpoints accelerate reconstruction. A capable backend shares unchanged memory pages and copies pages when a branch modifies them. Other backends can rebuild. A streamed token becomes part of a committed snapshot only after the engine consumes it and the resulting state is durably published.
The two equations capture correctness and the potential savings. Let P contain n shared tokens, with k alternative suffixes of lengths mᵢ. The tolerance ε is frozen from independent baseline measurements.
Every branch matches a fresh execution, before its suffix and after every consumed token:
With reusable checkpoints, ideal token-processing work counts the shared prefix once
RoPE gives us a useful algebraic trick: position is encoded as rotation. Each query and key gets rotated according to its token position. When attention compares them, the common rotation cancels:
(R(i)q)^{⊤}(R(j)k)=q^{⊤} R(j-i)k
The positional contribution depends on their separation. Moving both positions forward by 10,000 leaves that separation unchanged. This is the coordinate freedom in RoPE’s derivation.
That also gives us a way to reposition an already rotated key, with fixed rotary frequencies:
[
\widetilde{k}{p+\Delta}=R(\Delta),\widetilde{k}{p}
]
You can apply the additional rotation without recomputing the key projection. Consistently translating an entire context preserves its RoPE attention scores in exact arithmetic. Moving only one piece changes its relationship to everything else; deeper-layer cached representations can then become invalid.
YaRN stretches that coordinate system. Think of RoPE as many rotating hands: some turn quickly and distinguish nearby tokens; others turn slowly and describe longer distances. YaRN slows the long-distance rotations while preserving the fast ones, blends the intermediate frequencies, and adjusts attention strength. That lets a longer sequence occupy a positional range the model handles better. Its success is empirical; it changes the computation and needs validation. YaRN paper
For our branching API, the precise trick is simpler: after processing prefix P, its causal computation is already complete. Every alternative can resume at P’s original next position. Exploring 10,000 tokens on branch A does not advance branch B’s position.
That is the “timeless” property i'm working to certify fully at the moment.
@CC-David-CC commented on GitHub (Oct 11, 2026):
@Niko1221 this is the foundational "WHY" behind the other yarn stuff i PR'ed awhile ago.
I'm so close but there's something missing. I dont want to bias anyone else's attempt by posting flawed code.
@CC-David-CC commented on GitHub (Oct 11, 2026):
cause strata already has the disk backed and ram backed stuff that /should/ support this
@CC-David-CC commented on GitHub (Oct 12, 2026):
https://github.com/Niko1221/Strata/pull/2094
limits aren't installed yet but i'm tired and its getting closer
@TwoAnts commented on GitHub (Oct 12, 2026):
No rush at all. Good things take time—the best dishes take the longest to cook. Rest matters too, maybe even more than another test run right now. I'm really optimistic about this implementation and genuinely excited to see it land. Good luck. 👍👍👍
Strata already performs well enough as it is. I'm really enjoying using it and I'm very satisfied. No need to rush. 😊
@CC-David-CC commented on GitHub (Oct 12, 2026):
My Context Cow tests found problem in some of the underlying software. Yak shaving mode enabled. No estimated time to completion. Man i could really fuck up some online cloud gpu workloads with this. Hmm. Maybe I should submit a patch, today? nah its a billion+ dollar company and I couldn't get even an entry level role. Nothing my problem
My Context Cow will graze on TB of ram in future.
Moo
@TwoAnts commented on GitHub (Oct 13, 2026):
The world is all tattered and torn, and somebody's always gotta stitch it back together. lol
@CC-David-CC commented on GitHub (Oct 13, 2026):
yeah. but when i pull the thread tight it will look nothing like the world today
@TwoAnts commented on GitHub (Oct 13, 2026):
Haha, the world is just there—mend it or not, it’s still itself.
@CC-David-CC commented on GitHub (Oct 13, 2026):
https://github.com/CC-David-CC/Public_Context_COW
very much a work in progress. if you wait long enough it will reach main when stable (and niko approves)
this will be the branch i add cached prefix limit to // not there yet