[GH-ISSUE #2431] Discussion: Parallel slots don't share KV/prefix, and conversation cache prefix reuse falls back to root-ck #985

Closed
opened 2026-11-04 01:47:31 +07:00 by bsakaguchi · 9 comments
Owner

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

slot1   root-ck ... ... ... [ck1, ck2, ck3, ck4, ck5]
slot2   root-ck ... ... ... [ck1, ck2, ck3, ck4, ck5]
...
slotN   root-ck ... ... ... [ck1, ck2, ck3, ck4, ck5]
  1. No KV-cache sharing across slots, so memory cannot be saved.
  2. No prefix sharing across slots, so the same prefix cannot be prefill-accelerated.

Conversation cache (Parked Slots)

slotX   root-ck ... ... ... [ck1, ck2, ck3, ck4, ck5]
  1. For a long conversation's slot (whether it's active or parked), prefix reuse falls back to root-ck whenever the reused prefix lies between root-ck and ck1.
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** ``` slot1 root-ck ... ... ... [ck1, ck2, ck3, ck4, ck5] slot2 root-ck ... ... ... [ck1, ck2, ck3, ck4, ck5] ... slotN root-ck ... ... ... [ck1, ck2, ck3, ck4, ck5] ``` 1. No KV-cache sharing across slots, so memory cannot be saved. 2. No prefix sharing across slots, so the same prefix cannot be prefill-accelerated. **Conversation cache (Parked Slots)** ``` slotX root-ck ... ... ... [ck1, ck2, ck3, ck4, ck5] ``` 3. For a long conversation's slot (whether it's active or parked), prefix reuse falls back to `root-ck` whenever the reused prefix lies between `root-ck` and `ck1`.
Author
Owner

@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

<!-- gh-comment-id:6169912791 --> @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
Author
Owner

@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.

<!-- gh-comment-id:6169998586 --> @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.
Author
Owner

@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:

  • Parked conversations: SavedConversation carries the whole chain into host RAM; best() matches a new request against every parked checkpoint.
  • Active batch slots: each BSlot holds 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 in sl.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: its sl.checks inherits 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:

retained positions ≈ tail−16K, tail−48K, tail−112K, tail−240K, ...
                    (successive gaps: 16K, 32K, 64K, 128K, ...)

when the chain exceeds N slots, evict the point furthest from its
target position (equivalently: merge the smallest gap nearest the head)

Shape (L = 256K, N = 6, B = 16K)

The 16K anchor coincides with the root (~30K, end of the system prompt) and collapses into it:

absolute:  root(30K)          144K          208K        240K      256K(tail)
             ●─────────────────●────────────●───────────●─────────●
  gap:          ~114K              64K          32K         16K
             ←—— sparse head ——→            dense tail ——→

Gaps grow monotonically from tail to head: 16K → 32K → 64K → 114K.

Dynamics

  • Conversation < 96K: the whole chain stays uniformly dense (16K).
  • Beyond that, the head coarsens first (16K gaps merge into 32K, then 64K, ...), while the tail always stays 16K-dense.
  • The density profile matches rollback frequency: recent rollbacks (retries, edits) land in the dense zone nearly free; deep rollbacks (compaction, forks) mount the nearest far anchor, paying a cost that grows as a power of two instead of falling off a cliff.

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 at tail − 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

  • RAM cost (6 checkpoints × ~118 MB of running state)
  • Snapshot frequency and copy overhead
  • Park/restore copy size (the leaf anchor is always within 16K of the tail)
  • The hot path (normal turns resume from live in place, never through a checkpoint)

Implementation

One policy overload of eviction_victim in conv_cache.hpp (a pure function, with scenario tests in conv_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.

<!-- gh-comment-id:6172605428 --> @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: - **Parked conversations**: `SavedConversation` carries the whole chain into host RAM; `best()` matches a new request against every parked checkpoint. - **Active batch slots**: each `BSlot` holds 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 in `sl.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: its `sl.checks` inherits 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**: ``` retained positions ≈ tail−16K, tail−48K, tail−112K, tail−240K, ... (successive gaps: 16K, 32K, 64K, 128K, ...) when the chain exceeds N slots, evict the point furthest from its target position (equivalently: merge the smallest gap nearest the head) ``` ## Shape (L = 256K, N = 6, B = 16K) The 16K anchor coincides with the root (~30K, end of the system prompt) and collapses into it: ``` absolute: root(30K) 144K 208K 240K 256K(tail) ●─────────────────●────────────●───────────●─────────● gap: ~114K 64K 32K 16K ←—— sparse head ——→ dense tail ——→ ``` Gaps grow monotonically from tail to head: 16K → 32K → 64K → 114K. ## Dynamics - Conversation < 96K: the whole chain stays uniformly dense (16K). - Beyond that, the **head coarsens first** (16K gaps merge into 32K, then 64K, ...), while the tail always stays 16K-dense. - The density profile matches rollback frequency: recent rollbacks (retries, edits) land in the dense zone nearly free; deep rollbacks (compaction, forks) mount the nearest far anchor, paying a cost that grows as a power of two instead of falling off a cliff. ## 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 at `tail − 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 - RAM cost (6 checkpoints × ~118 MB of running state) - Snapshot frequency and copy overhead - Park/restore copy size (the leaf anchor is always within 16K of the tail) - The hot path (normal turns resume from `live` in place, never through a checkpoint) ## Implementation One policy overload of `eviction_victim` in `conv_cache.hpp` (a pure function, with scenario tests in `conv_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.
Author
Owner

@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

<!-- gh-comment-id:6174499266 --> @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
Author
Owner

@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.

<!-- gh-comment-id:6174637479 --> @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.
Author
Owner

@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

<!-- gh-comment-id:6175043500 --> @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
Author
Owner

@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.

<!-- gh-comment-id:6192396287 --> @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.
Author
Owner

@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; default lru untouched, the function is pure and unit-tested in conv_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 with lru and 66,731 in 8.2 s with log; 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.

<!-- gh-comment-id:6193286113 --> @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; default `lru` untouched, the function is pure and unit-tested in `conv_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 with `lru` and 66,731 in 8.2 s with `log`; 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.
Author
Owner

@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:

  1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6271040485 --> @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: 1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#985
No description provided.