mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #2431] Discussion: Parallel slots don't share KV/prefix, and conversation cache prefix reuse falls back to root-ck #985
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#985
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 14, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2431
My use case is hermes agent + strata. Strata is configured with --batch 2 and --max-context 262144.
In long conversations, the main problem I've run into is that after hermes background review reuses the main conversation and iterates a few rounds, when the main conversation continues, the prefix either falls between root-ck and ck1, or takes up another empty slot, causing a long prefill.
I had the agent analyze the latest Strata code and roughly summarize a few possible optimization issues. I see @CC-David-CC is already working on similar optimizations, so I'm just summarizing the situation here based on my understanding.
Active Parallel slots
Conversation cache (Parked Slots)
root-ckwhenever the reused prefix lies betweenroot-ckandck1.@CC-David-CC commented on GitHub (Oct 14, 2026):
Please make a competitive version to mine. I am learning cuda still and likely dont yet have the most optimized, or even a fully functional, version
@TwoAnts commented on GitHub (Oct 14, 2026):
I'm also a beginner in this area. Perhaps someone can come up with good implementations to address these issues. So I'm filing this issue here to summarize the situation.
@TwoAnts commented on GitHub (Oct 14, 2026):
Cross-slot prefill acceleration for identical prefixes should be achievable through data copying.
As for checkpoint intervals, I discussed an exponential interval scheme with AI, mainly to appropriately retain older checkpoints:
Exponential-Interval Checkpoint Retention for Strata
Scope
The policy lives in the session's checkpoint chain (
checks), which feeds both residency layers:SavedConversationcarries the whole chain into host RAM;best()matches a new request against every parked checkpoint.BSlotholds its own chain (sl.checks), populated from the main chain — the deepest turn-boundary checkpoint at admission, and the root/periodic checkpoints copied over when a long prompt read yields mid-way. The next request matching that slot mounts through the deepest reusable point insl.checks.So changing the retention rule at the source propagates the sparse-head/dense-tail grid to parked conversations and live slots alike; no second policy is needed for slots.
Problem
Today Strata (with default config) drops a checkpoint every 16K prompt tokens, and the chain retains only the root (pinned) plus the 5 most recent checkpoints (stamp-based eviction,
eviction_victim). For a 256K-token conversation, anchors exist only in the tail 96K; the stretch from ~30K to ~176K is a blind zone. Any rollback landing in that zone falls back to the root and re-prefills up to ~146K tokens (~2.5 minutes at ~1000 tok/s). This applies equally to an active batch slot serving a long conversation: itssl.checksinherits the same tail-only coverage.Scheme
Keep the checkpoint cadence unchanged (one snapshot every 16K tokens — same frequency, same overhead). Change only the retention rule: the resident chain = root (pinned) + anchors at exponentially growing offsets from the tail:
Shape (L = 256K, N = 6, B = 16K)
The 16K anchor coincides with the root (~30K, end of the system prompt) and collapses into it:
Gaps grow monotonically from tail to head: 16K → 32K → 64K → 114K.
Dynamics
Parameters
The design inputs are only N (
--prompt-cache, default 6) and B (--prompt-cache-every, currently 16K, explicitly set in our config). The deepest anchor sits attail − B·(2^(N−1) − 1); conversations deeper than that simply keep doubling the head-side gap — graceful degradation, no cliff. The only runtime variable is the current conversation length, which shifts the grid and triggers head-side merges.What stays unchanged
livein place, never through a checkpoint)Implementation
One policy overload of
eviction_victiminconv_cache.hpp(a pure function, with scenario tests inconv_cache_test.cpp) plus a config key such as--prompt-cache-policy log. The checkpoint trigger, parking, and restore paths are untouched.Honest boundary
At L = 256K / N = 6 this is not a strict improvement everywhere: the mid-section (144K–208K) gets 64K gaps, coarser than the current scheme's fully dense tail. In exchange, the mid blind zone shrinks from ~146K to ~64K. The advantage widens as conversations grow (L ≥ 400K). A hybrid variant covers both ends: keep the last 2 slots most-recent and the remaining 2–3 slots as geometric far anchors.
@CC-David-CC commented on GitHub (Oct 14, 2026):
how does your AI say this compares?
https://github.com/CC-David-CC/Public_Context_COW/blob/main/docs/context-cow/CHAT_WORKSPACE_GUIDE.md
@TwoAnts commented on GitHub (Oct 14, 2026):
I'm going to bed, so I just took a quick look. It works pretty well, but the changes are probably not small. In my view, major changes take longer to refine. These modifications may need some time to polish and can't be finished in two or three days. In the short term, we can make some simple fixes; in the long term, we can work on new features and refactor existing functionality.
Both can be done in parallel.
@CC-David-CC commented on GitHub (Oct 14, 2026):
I'm game for that plan. let me know how it goes. i have something semi functional now
@TwoAnts commented on GitHub (Oct 15, 2026):
As I understand it, solving these issues isn't very complicated—it mainly depends on how the author wants to approach it.
Maybe the author will just solve them himself in the next version, in whatever way he thinks is best. In some future version, one day.
@qiuzan2001 commented on GitHub (Oct 15, 2026):
The exponential-interval retention from TwoAnts' note above, as a small opt-in: #2640 adds
--prompt-cache-policy log(the victim is picked against a grid at--prompt-cache-every × (2^k − 1)behind the newest point, root pinned as before; defaultlruuntouched, the function is pure and unit-tested inconv_cache_test).Measured on an RTX 5070 Ti 16 GB (Swift 1.5 IQ3_S, 262K context,
--prompt-cache 6, three alternating rounds, engine restarted each run, identical reuse counts every run): a request that branches at 90,104 tokens of a 178,823-token conversation reused 16,384 tokens in 23.9 s withlruand 66,731 in 8.2 s withlog; the cold read, the last-turn retry and the return to the full conversation were the same on both. Simulated at 256K with the defaults the largest gap between two checkpoints goes from 162K to 96K.It does not touch the cross-slot sharing part of this thread.
@Niko1221 commented on GitHub (Oct 19, 2026):
Thanks for taking the time to report this.
We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.
To reopen it takes about two minutes:
/reopen. A check runs and either reopens the issue or lists what is still missing.The rules are in CONTRIBUTING.md.