mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #3998] [Engine] Compaction re-reads 331K-342K tokens five times (19.5-20.1 min each) because checkpoints match only from token 0 #1721
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#1721
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 @xvcezrqpbxtpzblrt on GitHub (Oct 24, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/3998
Area
[Engine] (speed, kernels, models, the server and API)
Desktop app, Terminal or source?
Desktop app (Windows, Linux or Mac).
What happened
A 512K-context agent session on engine 0.1.48 compacted five times in this log. Each compaction cost two full prompt reads:
The five cycles alone re-read 2,174,210 tokens and spent 7,597,336 ms (126.6 minutes). Turns that continue the same prompt are cheap by comparison: 417,938 of 418,637 reused in 2.4 s, 411,833 of 412,172 in 1.6 s, 419,067 of 419,250 in 1.2 s. The cost is in the prompt shape, not in the model or the card.
The same rule explains other cold reads in the log. Four turns that were not compactions reused only the 6,165-token system prompt (or 0), so the prompt had changed at the top; the engine re-read 405,494 to 411,506 tokens in 1,436,198 to 1,458,463 ms (23.9 to 24.3 minutes each). One of them is the 411,659-token turn in Logs. The log does not record what changed. [inference: the tool block at the top; the next turn reused the new prompt, 411,833 of 412,172]
In total, these fourteen turns re-read 3,811,680 tokens and spent 13,376,812 ms (223.0 minutes) on prompts the engine had already read.
Smallest steps or command that reproduce it
--max-context 524288 --kv int8on a 16 GB card, model Swift 1.5 IQ3_XXS, 6 checkpoints per request.docs/DETAILS.md:1548-1561describes this request shape and says the tool block sits at the top of the template.prompt ... tokens = ... reused + ... read in ... msline of the compaction request: 0 or 6,127 reused, 331K-342K read, 19.5-20.1 minutes.Reproduction status
Reproduced locally: five compactions in one session, read from the engine log. The log spans two engine runs of the same engine version. Not a controlled benchmark, and not repeated on a second machine.
Strata version
Engine 0.1.48, Windows x86-64 CUDA build (all five compactions). Code and documentation line numbers below are from the public tree as of 2026-10-24; the installed engine was built earlier, so the lines may shift, but the log strings match.
Graphics card, memory and system
NVIDIA GeForce RTX 3080 Ti Laptop GPU, 16 GB VRAM, compute capability 8.6 · 64 GB RAM (63.8 GiB guard limit) · Windows 11 Pro · 16 physical cores, 24 threads.
Model, size and settings
Swift 1.5 IQ3_XXS (GSQ-RCO IQ3_XXS) ·
--max-context 524288·--kv int8·--rope-scaling yarn --rope-scale 2·--vram-reserve-mib 1536·--spec 4· conversation cache auto-sized to 3,840 MiB for up to 4 parked conversations · 6 checkpoints reported per request.Logs
One full cycle (the fifth compaction):
The other four compaction requests and the first turn after each:
The four turns whose prompt changed at the top:
The turn before and after the last one:
Log file:
strata-<model>.log.Evidence
include/strata/core/conversation_cache.hpp:187-199— a checkpoint matches only if it is an exact prefix of the new prompt, starting at token 0:conversation_cache.hpp:275-291— a new conversation can borrow a parked entry when it starts with one of its checkpoints, and the comment names "a compacted history" as a case; the match is still a prefix.conversation_buffer.hpp:15-20— snapshot storage is 16 MiB segments with one owner: "No sharing or copy-on-write is needed because a parked image and its retained active buffers have one owner."kv_q8.hpp:5-8— K and V are stored as int8 codes with one FP16 scale per 64 values; the KV is a positional image, not a set of movable blocks.gdn.hpp:7-10, 44-46— 48 layers are GDN; their recurrent state is(S, h_v, S)f32 and is updated in place, so a segment mounted at a new position also needs that state rebuilt at the boundary.docs/DETAILS.md:1548-1561— documents the exact request shape: when the context fills, the client re-sends the conversation once with a summarization instruction andtools: []; the template writes the tools at the top, so that prompt shares only its first few tokens and is read again from the start. The same section documents an opt-in that re-renders such a request with the previous conversation's tools: with it, 84,895 of 84,997 tokens were reused; without it, 41 of 80,683 were.serve/server.py:3831, 7351-7373, 8491— the only compaction handling in the tree is that opt-in, in the server, off by default. A search of the C++ sources in the tree (src/program/generate.cpp,core/conversation_*,kernels/*.hpp) forcompactionreturns nothing.docs/DETAILS.md:1323-1324— parked snapshots are not persisted across restarts; only session files are.Root cause
The cache matches only from token 0.
conversation_prefix()returns 0 unless the checkpoint's ids are an exact prefix of the new prompt (std::equal(c.ids.begin(), c.ids.end(), prompt.begin())). A change anywhere in the first N tokens makes every checkpoint of length N or more unusable, and reuse is capped at the longest common prefix. [measured: code above]A compaction breaks the prefix twice: in the request, and in the turn after the summary. The documented compaction shape re-sends the conversation with a summarization instruction and
tools: [](docs 1548-1561); the tool block sits at the top, so the prompt stops matching right after the system prompt. The log agrees: the two cycles that kept a root checkpoint reused exactly 6,127 tokens — only the system-prompt prefix. The turn after the summary starts with system + summary + retained tail; the tail is byte-identical but now sits at different positions, so no checkpoint matches and reuse is 0. [measured: the table; inference: this session uses the documented shape, and the exact position shift, since the log reports only token counts]The engine has no compaction request type. It cannot tell a compaction from an ordinary prompt, so it cannot keep the previous tools or a parent handle for it. The only handling is the per-client, opt-in re-render in the server. Every other client, and the same client with the option off, gets a full read. [measured: code search above]
The parked snapshot is refused, so nothing survives. All ten compaction-related turns are preceded by
skip parkingwith a snapshot of 5,742-6,926 MiB against a 3,840 MiB budget. The pre-compaction entry is gone, and with it the root checkpoint that would have let the first post-summary turn reuse the system prompt instead of 0. [measured: log; inference: the borrow path inconversation_cache.hpp:275-291would have used it, about 6.1K tokens of 103,519]The KV is one positional image.
ConversationKvstorescellsand a contiguous buffer, and positions are implicit in the cell index. A retained tail cannot be mounted at a new offset without re-applying the position encoding and rebuilding the GDN state and the indexer rows at the boundary. [measured: code; inference: the cost of a re-anchor, not measured]Proposed fix
Short term, no format change:
borrows()path. This saves only about 6.1K tokens of 103,519 today, but it removes one full read of the system prompt and proves the borrow path on the compaction case.Long term, a segment-addressed KV cache:
#3584already implements the first layer of this (LCP-verified suffix mount, dense tail checkpoints, state ladder); the compaction case below is the acceptance test for it.docs/DETAILS.md:1323-1324); and single-writer + RCU for concurrent requests, because the current buffer has one owner and no sharing or copy-on-write (conversation_buffer.hpp:15-17).Acceptance criteria
Duplicate search
Searched open and closed issues and pull requests for
compaction,conversation cache,prefix reuse,prompt cache,re-read,cold prefill,suffix reuse,tools: [],parking, andskip parking. Closest:I found no existing report that measures the compaction request itself across repeated compactions.
@xvcezrqpbxtpzblrt commented on GitHub (Oct 27, 2026):
Measured the same path on the reporter's machine (engine 0.1.50, RTX 3080 Ti Laptop 16 GB, 64 GB RAM, IQ3_XXS 512K, int8). The compaction request is a prefix of the conversation, and it loses its cache because the conversation is never parked: every slow read is preceded by
skip parking (snapshot N MiB exceeds available budget).The budget is the blocker in this report too. The log says "conversation cache auto-sized to 3,840 MiB", and one snapshot at 340K is 5,742-6,926 MiB. With room for the snapshot, the same 359K conversation parked 5.88 GiB in 2.76 s, restored in 0.94 s, and its follow-up after a side request reused 359,254 of 359,272 tokens in 2.3 s (without it: 359,283 tokens read in 1,105.8 s).
Proposed scope: size the auto budget for one snapshot of --max-context (18 KiB per token; 17.6 KiB measured with int8, 11.3 with q4_0) when the RAM above the floor allows it. Contexts where the old 40% already fits a snapshot keep the same budget, and the physical-RAM gate still refuses a snapshot the machine cannot hold. PR: #4338.
The first turn after the summary (95K-104K, 5.4-5.9 min) is a different case: the summary is new, so prefix-only matching cannot reuse the retained tail. That still needs the segment-addressed cache (#3584).
@xvcezrqpbxtpzblrt commented on GitHub (Oct 27, 2026):
Real
/compacton a copy of this session, engine 0.1.50, same machine (RTX 3080 Ti Laptop 16 GB, 64 GB RAM, IQ3_XXS 512K int8,--kv-grow, explicit 16 GiB budget and 1 GiB floor):The missing piece was the budget: the log in this report says "auto-sized to 3,840 MiB", and one snapshot here is 4,354-6,926 MiB. PR #4338 sizes the auto budget for one snapshot of
--max-context(18 KiB per token) when the RAM above the floor allows it; the engine log then reports 9,216 MiB on this machine, and the compaction request reuses its prefix as above. The first turn after the summary still cannot reuse the retained tail (the summary is new text, matching is prefix-only); that remains #3584.@Niko1221 commented on GitHub (Nov 5, 2026):
Thanks for taking the time to report this.
Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. 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.