[GH-ISSUE #4921] [Engine] dsv41: reuse a kept conversation past a changed span (KV splice), opt-in #2261

Open
opened 2026-11-04 01:58:00 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @PhialsBasement on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4921

Area

[Engine] (speed, kernels, models, the server and API)

What do you want to do?

Coding agents put per-session text inside the system prompt, ahead of tens of thousands of tokens that are the same in every session. OpenCode writes the working directory, the date, the git status and the project's instruction files near the top, and synced skills carry a random folder id in their paths. The conversation cache only reuses a prompt's shared start, so every new session (another folder, the next day) reads the whole prompt again.

Measured on my machine (environment below), with OpenCode 1.18.34 and its 6 MCP servers (about 37.5K tokens before the first user message):

New OpenCode session, another project Prompt read
stock 0.1.55 37,452 tokens, 0 reused, 100.3 s (another run: 37,718 tokens, 93.4 s)
with the splice below 37,482 tokens = 36,097 reused + 1,385 read, 26.0 s

I want the engine to reuse a kept conversation past a changed span instead of reading the whole prompt. This matters for coding agents using OpenCode with MCP servers: it saves read time on every new session.

What do you do today instead?

env_to_user moves only the <env> block. Project instruction files and skill paths still differ, so the read starts over at the first of them.

Proposed behavior

When a prompt does not continue the conversation in the model, the engine aligns it with the state in the model and every kept conversation, using token runs of 32 found wherever they sit, so a prompt the engine reordered last turn still matches. It takes the one it can reuse most:

  1. Lines of the kept state the prompt lacks are cut out of the state: later source rows (ckv, ik) move down, every window ring rotates, and the cut is recorded as a RoPE gap (rope_off), added at each Finish.pos site. The cut table is saved with the slot as an optional trailer (DS4CUTS1); an engine without it refuses such a slot and reads the prompt again.
  2. The prompt is rebuilt as the alike part in the state's order, followed by the new lines in the prompt's order, and only those are read.
  3. Changes move as whole lines (line breaks from the pack's vocab.json), and cuts widen to the state's group size (the compress ratio, 2 here), so the model sees complete lines. Without this, a cut mid-line left text such as accuracyddcb1_a438... in the prompt, and the model said its environment info looked garbled.

Proposed as opt-in (STRATA_DS4_REORDER=1), default off.

Tradeoffs

  • Approximate: the reused tokens after a cut were computed with the removed text in their context, and moved lines are read later than the client placed them (the model sees them after the system prompt's tail and before the user turn). For short guidance lines (a folder, a date, a project file) I saw no effect on answers; I have no benchmark numbers for it yet.
  • The RoPE gap leaves a jump in positions where text was cut, rather than re-rotating the moved rows (which would need a dequantize, rotate, requantize pass over the FP4 rows).
  • Alignment costs host time per request (a hash of the prompt's 32-token runs per kept conversation); not measured separately, inside the read times above.

Evidence so far

All on Strata 0.1.55 (c62d5e3a), HIP build of strata-dsv41 from source (system ROCm 7.2.4, gfx1201), RX 9070 XT 16 GB, Ryzen 7 5800X3D, 64 GB DDR4, CachyOS kernel 7.3.0-4, deepseek-v4.1-flash-ist-das-1.75bpw, 1M context.

  • Two synthetic sessions straight to /v1/chat/completions (30 tools, a 19.4K-token system prompt, only the <env> lines differ): the first read 19,428 tokens in 77 to 79 s; the second reused 19,355 and read 72 in about 10 s, and answered with the second session's folder, which only appears in the moved lines.
  • Real OpenCode sessions: the table above; a later follow-up on a 54,273-token conversation reused 53,080 and read 1,193.
  • A multi-turn bug I hit and fixed on the way: with in-order matching, each follow-up turn re-read the moved lines and everything after them (10,740 and 8,405 tokens on two tool turns). Matching runs wherever they sit fixed it; a host-side test of three turns reads exactly the new message and the new tool output.

Not run

CUDA, SYCL and Metal builds; Strata's C++ test suite; a quality benchmark with the option on and off.

OpenCode drops reasoning_content from earlier turns of a custom OpenAI-compatible model unless the model sets "interleaved": { "field": "reasoning_content" }, while V4.1's template keeps earlier reasoning when tools are present. Without that setting, each follow-up cuts the previous reply's reasoning out of the cache. This could be worth a line in the OpenCode connection docs or in strata connect opencode.

The branch is ready to split into a PR once the scope is agreed.

Originally created by @PhialsBasement on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4921 ### Area [Engine] (speed, kernels, models, the server and API) ### What do you want to do? Coding agents put per-session text inside the system prompt, ahead of tens of thousands of tokens that are the same in every session. OpenCode writes the working directory, the date, the git status and the project's instruction files near the top, and synced skills carry a random folder id in their paths. The conversation cache only reuses a prompt's shared start, so every new session (another folder, the next day) reads the whole prompt again. Measured on my machine (environment below), with OpenCode 1.18.34 and its 6 MCP servers (about 37.5K tokens before the first user message): | New OpenCode session, another project | Prompt read | |---|---| | stock 0.1.55 | 37,452 tokens, 0 reused, 100.3 s (another run: 37,718 tokens, 93.4 s) | | with the splice below | 37,482 tokens = 36,097 reused + 1,385 read, 26.0 s | I want the engine to reuse a kept conversation past a changed span instead of reading the whole prompt. This matters for coding agents using OpenCode with MCP servers: it saves read time on every new session. ### What do you do today instead? `env_to_user` moves only the `<env>` block. Project instruction files and skill paths still differ, so the read starts over at the first of them. ### Proposed behavior When a prompt does not continue the conversation in the model, the engine aligns it with the state in the model and every kept conversation, using token runs of 32 found wherever they sit, so a prompt the engine reordered last turn still matches. It takes the one it can reuse most: 1. Lines of the kept state the prompt lacks are cut out of the state: later source rows (`ckv`, `ik`) move down, every window ring rotates, and the cut is recorded as a RoPE gap (`rope_off`), added at each `Finish.pos` site. The cut table is saved with the slot as an optional trailer (`DS4CUTS1`); an engine without it refuses such a slot and reads the prompt again. 2. The prompt is rebuilt as the alike part in the state's order, followed by the new lines in the prompt's order, and only those are read. 3. Changes move as whole lines (line breaks from the pack's `vocab.json`), and cuts widen to the state's group size (the compress ratio, 2 here), so the model sees complete lines. Without this, a cut mid-line left text such as `accuracyddcb1_a438...` in the prompt, and the model said its environment info looked garbled. Proposed as opt-in (`STRATA_DS4_REORDER=1`), default off. ### Tradeoffs - Approximate: the reused tokens after a cut were computed with the removed text in their context, and moved lines are read later than the client placed them (the model sees them after the system prompt's tail and before the user turn). For short guidance lines (a folder, a date, a project file) I saw no effect on answers; I have no benchmark numbers for it yet. - The RoPE gap leaves a jump in positions where text was cut, rather than re-rotating the moved rows (which would need a dequantize, rotate, requantize pass over the FP4 rows). - Alignment costs host time per request (a hash of the prompt's 32-token runs per kept conversation); not measured separately, inside the read times above. ### Evidence so far All on Strata 0.1.55 (c62d5e3a), HIP build of `strata-dsv41` from source (system ROCm 7.2.4, gfx1201), RX 9070 XT 16 GB, Ryzen 7 5800X3D, 64 GB DDR4, CachyOS kernel 7.3.0-4, deepseek-v4.1-flash-ist-das-1.75bpw, 1M context. - Two synthetic sessions straight to `/v1/chat/completions` (30 tools, a 19.4K-token system prompt, only the `<env>` lines differ): the first read 19,428 tokens in 77 to 79 s; the second reused 19,355 and read 72 in about 10 s, and answered with the second session's folder, which only appears in the moved lines. - Real OpenCode sessions: the table above; a later follow-up on a 54,273-token conversation reused 53,080 and read 1,193. - A multi-turn bug I hit and fixed on the way: with in-order matching, each follow-up turn re-read the moved lines and everything after them (10,740 and 8,405 tokens on two tool turns). Matching runs wherever they sit fixed it; a host-side test of three turns reads exactly the new message and the new tool output. ### Not run CUDA, SYCL and Metal builds; Strata's C++ test suite; a quality benchmark with the option on and off. ### Related, client side OpenCode drops `reasoning_content` from earlier turns of a custom OpenAI-compatible model unless the model sets `"interleaved": { "field": "reasoning_content" }`, while V4.1's template keeps earlier reasoning when tools are present. Without that setting, each follow-up cuts the previous reply's reasoning out of the cache. This could be worth a line in the OpenCode connection docs or in `strata connect opencode`. The branch is ready to split into a PR once the scope is agreed.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 1, 2026):

Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:

  • Fill in "Area".

Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

<!-- gh-comment-id:6558332544 --> @github-actions[bot] commented on GitHub (Nov 1, 2026): Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing: - [ ] Fill in "Area". Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@github-actions[bot] commented on GitHub (Nov 1, 2026):

Thanks, this follows the format now.

<!-- gh-comment-id:6558621982 --> @github-actions[bot] commented on GitHub (Nov 1, 2026): Thanks, this follows the format now.
Author
Owner

@PhialsBasement commented on GitHub (Nov 2, 2026):

The implementation is on a branch for anyone who wants to try it: https://github.com/PhialsBasement/Strata/tree/dsv41-kv-splice

Note: on that branch the feature is on by default (STRATA_DS4_REORDER=0 turns it off); a PR would flip it to opt-in as proposed above. Built and tested with HIP on gfx1201 only.

Build (HIP example):

cmake -S . -B build-hip -G Ninja -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DCMAKE_HIP_ARCHITECTURES=gfx1201 -DSTRATA_BUILD_DSV41=ON
cmake --build build-hip --target strata-dsv41
STRATA_DSV41_EXE=$PWD/build-hip/strata-dsv41 strata launch --preset <preset>
<!-- gh-comment-id:6565894217 --> @PhialsBasement commented on GitHub (Nov 2, 2026): The implementation is on a branch for anyone who wants to try it: https://github.com/PhialsBasement/Strata/tree/dsv41-kv-splice Note: on that branch the feature is **on by default** (`STRATA_DS4_REORDER=0` turns it off); a PR would flip it to opt-in as proposed above. Built and tested with HIP on gfx1201 only. Build (HIP example): ``` cmake -S . -B build-hip -G Ninja -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DCMAKE_HIP_ARCHITECTURES=gfx1201 -DSTRATA_BUILD_DSV41=ON cmake --build build-hip --target strata-dsv41 STRATA_DSV41_EXE=$PWD/build-hip/strata-dsv41 strata launch --preset <preset> ```
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#2261
No description provided.