[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

Closed
opened 2026-11-04 01:53:28 +07:00 by bsakaguchi · 3 comments
Owner

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 compaction request itself re-read 331,476 to 342,496 tokens in 1,169,295 to 1,207,770 ms (19.5 to 20.1 minutes);
  • the first turn after the summary re-read 95,686 to 103,519 tokens in 326,574 to 355,919 ms (5.4 to 5.9 minutes).

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

  1. Start the engine with --max-context 524288 --kv int8 on a 16 GB card, model Swift 1.5 IQ3_XXS, 6 checkpoints per request.
  2. Use an agent client that compacts by re-sending the conversation with a summarization instruction and an empty tool list; docs/DETAILS.md:1548-1561 describes this request shape and says the tool block sits at the top of the template.
  3. Let the session grow to about 419K tokens so the client compacts.
  4. Read the prompt ... tokens = ... reused + ... read in ... ms line of the compaction request: 0 or 6,127 reused, 331K-342K read, 19.5-20.1 minutes.
  5. Read the line of the first turn after the summary: 0 reused, 95K-104K read, 5.4-5.9 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):

strata serve: prompt 419250 tokens = 419067 reused + 183 read in 1202 ms (152.3 tok/s), 696 generated in 15334 ms (45.4 tok/s), drafts accepted 530 of 578, 6 checkpoints
strata serve: conversation cache: skip parking (snapshot 6910 MiB exceeds available budget)
strata serve: prompt 339637 tokens = 0 reused + 339637 read in 1207770 ms (281.2 tok/s), 7017 generated in 226085 ms (31.0 tok/s), drafts accepted 4187 of 6706, 6 checkpoints
strata serve: conversation cache: skip parking (snapshot 5841 MiB exceeds available budget)
strata serve: prompt 103519 tokens = 0 reused + 103519 read in 355919 ms (290.8 tok/s), 1146 generated in 29149 ms (39.3 tok/s), drafts accepted 710 of 1049, 6 checkpoints
strata serve: prompt 105096 tokens = 104665 reused + 431 read in 1640 ms (262.8 tok/s), 958 generated in 25802 ms (37.1 tok/s), drafts accepted 574 of 878, 6 checkpoints

The other four compaction requests and the first turn after each:

strata serve: prompt 337603 tokens = 6127 reused + 331476 read in 1169295 ms (283.5 tok/s), 2235 generated in 73130 ms (30.6 tok/s), drafts accepted 1299 of 2085, 6 checkpoints
strata serve: prompt 96868 tokens = 0 reused + 96868 read in 329723 ms (293.8 tok/s), 6834 generated in 168697 ms (40.5 tok/s), drafts accepted 4291 of 5622, 6 checkpoints
strata serve: prompt 336001 tokens = 0 reused + 336001 read in 1170580 ms (287.0 tok/s), 4168 generated in 119715 ms (34.8 tok/s), drafts accepted 2450 of 3921, 6 checkpoints
strata serve: prompt 99016 tokens = 0 reused + 99016 read in 336779 ms (294.0 tok/s), 301 generated in 7180 ms (41.9 tok/s), drafts accepted 206 of 262, 6 checkpoints
strata serve: prompt 339898 tokens = 6127 reused + 333771 read in 1171322 ms (285.0 tok/s), 3865 generated in 110868 ms (34.9 tok/s), drafts accepted 2358 of 3507, 6 checkpoints
strata serve: prompt 95740 tokens = 0 reused + 95740 read in 326574 ms (293.2 tok/s), 229 generated in 5703 ms (40.2 tok/s), drafts accepted 147 of 190, 6 checkpoints
strata serve: prompt 342496 tokens = 0 reused + 342496 read in 1200809 ms (285.2 tok/s), 5149 generated in 152896 ms (33.7 tok/s), drafts accepted 2878 of 4887, 6 checkpoints
strata serve: prompt 95686 tokens = 0 reused + 95686 read in 328565 ms (291.2 tok/s), 620 generated in 14577 ms (42.5 tok/s), drafts accepted 405 of 527, 6 checkpoints

The four turns whose prompt changed at the top:

strata serve: prompt 415516 tokens = 6165 reused + 409351 read in 1436198 ms (285.0 tok/s), 5511 generated in 144882 ms (38.0 tok/s), drafts accepted 3649 of 4825, 6 checkpoints
strata serve: prompt 411119 tokens = 0 reused + 411119 read in 1438327 ms (285.8 tok/s), 940 generated in 27780 ms (33.8 tok/s), drafts accepted 490 of 766, 6 checkpoints
strata serve: prompt 417671 tokens = 6165 reused + 411506 read in 1458463 ms (282.2 tok/s), 877 generated in 23835 ms (36.8 tok/s), drafts accepted 556 of 754, 6 checkpoints
strata serve: prompt 411659 tokens = 6165 reused + 405494 read in 1446488 ms (280.3 tok/s), 174 generated in 5190 ms (33.5 tok/s), drafts accepted 95 of 136, 6 checkpoints

The turn before and after the last one:

strata serve: prompt 418637 tokens = 417938 reused + 699 read in 2363 ms (295.8 tok/s), 358 generated in 8887 ms (40.3 tok/s), drafts accepted 240 of 306, 6 checkpoints
strata serve: prompt 412172 tokens = 411833 reused + 339 read in 1613 ms (210.1 tok/s), 976 generated in 25643 ms (38.1 tok/s), drafts accepted 603 of 779, 6 checkpoints

Log file: strata-<model>.log.

Evidence

# compaction prompt reused read time first turn after reused read time
1 337,603 6,127 (1.81%) 331,476 1,169,295 ms (19.49 min) 96,868 0 96,868 329,723 ms (5.50 min)
2 336,001 0 336,001 1,170,580 ms (19.51 min) 99,016 0 99,016 336,779 ms (5.61 min)
3 339,898 6,127 (1.80%) 333,771 1,171,322 ms (19.52 min) 95,740 0 95,740 326,574 ms (5.44 min)
4 342,496 0 342,496 1,200,809 ms (20.01 min) 95,686 0 95,686 328,565 ms (5.48 min)
5 339,637 0 339,637 1,207,770 ms (20.13 min) 103,519 0 103,519 355,919 ms (5.93 min)
total 1,683,381 5,919,776 ms (98.66 min) 490,829 1,677,560 ms (27.96 min)
top change prompt reused read time
1 415,516 6,165 409,351 1,436,198 ms (23.94 min)
2 411,119 0 411,119 1,438,327 ms (23.97 min)
3 417,671 6,165 411,506 1,458,463 ms (24.31 min)
4 411,659 6,165 405,494 1,446,488 ms (24.11 min)
total 1,637,470 5,779,476 ms (96.32 min)

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:

int64_t conversation_prefix(const ConversationCheckpoint& c, const std::vector<Token>& prompt,
                            const std::vector<ConversationImageKey>& images) {
    const size_t n = c.ids.size();
    // The last prompt token always starts the next verify window.
    if (n == 0 || n >= prompt.size() || !std::equal(c.ids.begin(), c.ids.end(), prompt.begin())) return 0;
    size_t j = 0;
    for (const auto& image : images) {
        if (image.start >= (int64_t) n) continue;
        if (j == c.imgs.size() || !(c.imgs[j++] == image)) return 0;
    }
    if (j != c.imgs.size()) return 0;
    return (int64_t) n;
}

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 and tools: []; 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) for compaction returns nothing.

docs/DETAILS.md:1323-1324 — parked snapshots are not persisted across restarts; only session files are.

Root cause

  1. 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]

  2. 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]

  3. 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]

  4. The parked snapshot is refused, so nothing survives. All ten compaction-related turns are preceded by skip parking with 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 in conversation_cache.hpp:275-291 would have used it, about 6.1K tokens of 103,519]

  5. The KV is one positional image. ConversationKv stores cells and 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:

  1. Generalize the compaction render in the engine. Detect a request whose prompt carries a summarization instruction and whose tool list is empty, and render it with the tool block and the system prompt of the previous non-compaction request of the same conversation. This is what the per-client option already does; keying it to the request shape instead of one client's metadata would cover every client. The response parser must still treat tools as absent, as the current option does. The detection needs a guard against a user who asks for a summary with tools off (require a previous request with tools, and the instruction pattern).
  2. Or move the summarization instruction to the end of the history without removing the tool block, so the compaction prompt is a strict extension of the previous prompt and reuses about 100%. This is a client-side change; the engine needs no new code.
  3. Pin the pre-compaction entry when a compaction request arrives, so the post-summary request can borrow the root checkpoint through the existing 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:

  1. Index KV by content segment, not by prefix. Store segments (per message or per 1-2K-token block) with a content hash and the positions they were written at, match them anywhere in the new prompt, and mount them at the new offset. Re-anchor by storing K before the position encoding and applying it at read time, or by re-rotating on mount, and rebuild the GDN state and the indexer rows at segment boundaries. #3584 already 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.
  2. Four reinforcements before enabling it by default: a hard cap on the segment index and KV footprint with GC of unreferenced segments; one canonical position base per segment so the same segment always yields the same logits; append-only log persistence, because parked snapshots do not survive a restart today (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

  1. A compaction request at about 340K tokens reuses at least 95% of the pre-compaction history and prefills in under 60 s (today: 0-1.8% and 1,169-1,208 s).
  2. The first turn after the summary reuses at least 95% of the retained tail and prefills in under 60 s (today: 0% and 327-356 s).
  3. After 500 compactions in one session, the segment index and the KV footprint stay bounded and do not grow linearly with the number of compactions.
  4. Re-anchored logits against a full prefill of the same prompt: max absolute difference at most 1e-3 on the fp16 baseline, with the int8 tolerance stated separately.
  5. After a crash and restart, at least 95% of the active segments are restored.

Searched open and closed issues and pull requests for compaction, conversation cache, prefix reuse, prompt cache, re-read, cold prefill, suffix reuse, tools: [], parking, and skip parking. Closest:

  • #3701 (open) — a post-summary re-read of 154,601 tokens (97.8 s) on 2x V100; its compaction call reused 195,153 of 202,451 tokens (96.4%). This report is the other case: the compaction request itself re-reads 331K-342K, five times.
  • #3928 (open) — the same machine, the Stop path: a cancelled read loses its prefix and the next request re-reads 375,844 tokens. Its root cause 1 notes the post-compaction re-read; this report adds the compaction request's own read, the five-cycle measurements, and the engine-side mechanism.
  • #3584 (open pull request) — suffix reuse with LCP-verified mounts, dense tail checkpoints, and a state ladder; the long-term section above is the compaction acceptance case for it.
  • #2508 (closed) and #2431 (closed) — earlier KV compaction and prefix-sharing proposals.

I found no existing report that measures the compaction request itself across repeated compactions.

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 compaction request itself re-read 331,476 to 342,496 tokens in 1,169,295 to 1,207,770 ms (19.5 to 20.1 minutes); - the first turn after the summary re-read 95,686 to 103,519 tokens in 326,574 to 355,919 ms (5.4 to 5.9 minutes). 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 1. Start the engine with `--max-context 524288 --kv int8` on a 16 GB card, model Swift 1.5 IQ3_XXS, 6 checkpoints per request. 2. Use an agent client that compacts by re-sending the conversation with a summarization instruction and an empty tool list; `docs/DETAILS.md:1548-1561` describes this request shape and says the tool block sits at the top of the template. 3. Let the session grow to about 419K tokens so the client compacts. 4. Read the `prompt ... tokens = ... reused + ... read in ... ms` line of the compaction request: 0 or 6,127 reused, 331K-342K read, 19.5-20.1 minutes. 5. Read the line of the first turn after the summary: 0 reused, 95K-104K read, 5.4-5.9 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): ```text strata serve: prompt 419250 tokens = 419067 reused + 183 read in 1202 ms (152.3 tok/s), 696 generated in 15334 ms (45.4 tok/s), drafts accepted 530 of 578, 6 checkpoints strata serve: conversation cache: skip parking (snapshot 6910 MiB exceeds available budget) strata serve: prompt 339637 tokens = 0 reused + 339637 read in 1207770 ms (281.2 tok/s), 7017 generated in 226085 ms (31.0 tok/s), drafts accepted 4187 of 6706, 6 checkpoints strata serve: conversation cache: skip parking (snapshot 5841 MiB exceeds available budget) strata serve: prompt 103519 tokens = 0 reused + 103519 read in 355919 ms (290.8 tok/s), 1146 generated in 29149 ms (39.3 tok/s), drafts accepted 710 of 1049, 6 checkpoints strata serve: prompt 105096 tokens = 104665 reused + 431 read in 1640 ms (262.8 tok/s), 958 generated in 25802 ms (37.1 tok/s), drafts accepted 574 of 878, 6 checkpoints ``` The other four compaction requests and the first turn after each: ```text strata serve: prompt 337603 tokens = 6127 reused + 331476 read in 1169295 ms (283.5 tok/s), 2235 generated in 73130 ms (30.6 tok/s), drafts accepted 1299 of 2085, 6 checkpoints strata serve: prompt 96868 tokens = 0 reused + 96868 read in 329723 ms (293.8 tok/s), 6834 generated in 168697 ms (40.5 tok/s), drafts accepted 4291 of 5622, 6 checkpoints strata serve: prompt 336001 tokens = 0 reused + 336001 read in 1170580 ms (287.0 tok/s), 4168 generated in 119715 ms (34.8 tok/s), drafts accepted 2450 of 3921, 6 checkpoints strata serve: prompt 99016 tokens = 0 reused + 99016 read in 336779 ms (294.0 tok/s), 301 generated in 7180 ms (41.9 tok/s), drafts accepted 206 of 262, 6 checkpoints strata serve: prompt 339898 tokens = 6127 reused + 333771 read in 1171322 ms (285.0 tok/s), 3865 generated in 110868 ms (34.9 tok/s), drafts accepted 2358 of 3507, 6 checkpoints strata serve: prompt 95740 tokens = 0 reused + 95740 read in 326574 ms (293.2 tok/s), 229 generated in 5703 ms (40.2 tok/s), drafts accepted 147 of 190, 6 checkpoints strata serve: prompt 342496 tokens = 0 reused + 342496 read in 1200809 ms (285.2 tok/s), 5149 generated in 152896 ms (33.7 tok/s), drafts accepted 2878 of 4887, 6 checkpoints strata serve: prompt 95686 tokens = 0 reused + 95686 read in 328565 ms (291.2 tok/s), 620 generated in 14577 ms (42.5 tok/s), drafts accepted 405 of 527, 6 checkpoints ``` The four turns whose prompt changed at the top: ```text strata serve: prompt 415516 tokens = 6165 reused + 409351 read in 1436198 ms (285.0 tok/s), 5511 generated in 144882 ms (38.0 tok/s), drafts accepted 3649 of 4825, 6 checkpoints strata serve: prompt 411119 tokens = 0 reused + 411119 read in 1438327 ms (285.8 tok/s), 940 generated in 27780 ms (33.8 tok/s), drafts accepted 490 of 766, 6 checkpoints strata serve: prompt 417671 tokens = 6165 reused + 411506 read in 1458463 ms (282.2 tok/s), 877 generated in 23835 ms (36.8 tok/s), drafts accepted 556 of 754, 6 checkpoints strata serve: prompt 411659 tokens = 6165 reused + 405494 read in 1446488 ms (280.3 tok/s), 174 generated in 5190 ms (33.5 tok/s), drafts accepted 95 of 136, 6 checkpoints ``` The turn before and after the last one: ```text strata serve: prompt 418637 tokens = 417938 reused + 699 read in 2363 ms (295.8 tok/s), 358 generated in 8887 ms (40.3 tok/s), drafts accepted 240 of 306, 6 checkpoints strata serve: prompt 412172 tokens = 411833 reused + 339 read in 1613 ms (210.1 tok/s), 976 generated in 25643 ms (38.1 tok/s), drafts accepted 603 of 779, 6 checkpoints ``` Log file: `strata-<model>.log`. ### Evidence | # | compaction prompt | reused | read | time | first turn after | reused | read | time | |---|---|---|---|---|---|---|---|---| | 1 | 337,603 | 6,127 (1.81%) | 331,476 | 1,169,295 ms (19.49 min) | 96,868 | 0 | 96,868 | 329,723 ms (5.50 min) | | 2 | 336,001 | 0 | 336,001 | 1,170,580 ms (19.51 min) | 99,016 | 0 | 99,016 | 336,779 ms (5.61 min) | | 3 | 339,898 | 6,127 (1.80%) | 333,771 | 1,171,322 ms (19.52 min) | 95,740 | 0 | 95,740 | 326,574 ms (5.44 min) | | 4 | 342,496 | 0 | 342,496 | 1,200,809 ms (20.01 min) | 95,686 | 0 | 95,686 | 328,565 ms (5.48 min) | | 5 | 339,637 | 0 | 339,637 | 1,207,770 ms (20.13 min) | 103,519 | 0 | 103,519 | 355,919 ms (5.93 min) | | total | | | 1,683,381 | 5,919,776 ms (98.66 min) | | | 490,829 | 1,677,560 ms (27.96 min) | | top change | prompt | reused | read | time | |---|---|---|---|---| | 1 | 415,516 | 6,165 | 409,351 | 1,436,198 ms (23.94 min) | | 2 | 411,119 | 0 | 411,119 | 1,438,327 ms (23.97 min) | | 3 | 417,671 | 6,165 | 411,506 | 1,458,463 ms (24.31 min) | | 4 | 411,659 | 6,165 | 405,494 | 1,446,488 ms (24.11 min) | | total | | | 1,637,470 | 5,779,476 ms (96.32 min) | `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: ```cpp int64_t conversation_prefix(const ConversationCheckpoint& c, const std::vector<Token>& prompt, const std::vector<ConversationImageKey>& images) { const size_t n = c.ids.size(); // The last prompt token always starts the next verify window. if (n == 0 || n >= prompt.size() || !std::equal(c.ids.begin(), c.ids.end(), prompt.begin())) return 0; size_t j = 0; for (const auto& image : images) { if (image.start >= (int64_t) n) continue; if (j == c.imgs.size() || !(c.imgs[j++] == image)) return 0; } if (j != c.imgs.size()) return 0; return (int64_t) n; } ``` `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 and `tools: []`; 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`) for `compaction` returns nothing. `docs/DETAILS.md:1323-1324` — parked snapshots are not persisted across restarts; only session files are. ### Root cause 1. **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] 2. **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] 3. **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] 4. **The parked snapshot is refused, so nothing survives.** All ten compaction-related turns are preceded by `skip parking` with 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 in `conversation_cache.hpp:275-291` would have used it, about 6.1K tokens of 103,519] 5. **The KV is one positional image.** `ConversationKv` stores `cells` and 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: 1. **Generalize the compaction render in the engine.** Detect a request whose prompt carries a summarization instruction and whose tool list is empty, and render it with the tool block and the system prompt of the previous non-compaction request of the same conversation. This is what the per-client option already does; keying it to the request shape instead of one client's metadata would cover every client. The response parser must still treat tools as absent, as the current option does. The detection needs a guard against a user who asks for a summary with tools off (require a previous request with tools, and the instruction pattern). 2. **Or move the summarization instruction to the end of the history** without removing the tool block, so the compaction prompt is a strict extension of the previous prompt and reuses about 100%. This is a client-side change; the engine needs no new code. 3. **Pin the pre-compaction entry when a compaction request arrives**, so the post-summary request can borrow the root checkpoint through the existing `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: 4. **Index KV by content segment, not by prefix.** Store segments (per message or per 1-2K-token block) with a content hash and the positions they were written at, match them anywhere in the new prompt, and mount them at the new offset. Re-anchor by storing K before the position encoding and applying it at read time, or by re-rotating on mount, and rebuild the GDN state and the indexer rows at segment boundaries. `#3584` already 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. 5. **Four reinforcements before enabling it by default:** a hard cap on the segment index and KV footprint with GC of unreferenced segments; one canonical position base per segment so the same segment always yields the same logits; append-only log persistence, because parked snapshots do not survive a restart today (`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 1. A compaction request at about 340K tokens reuses at least 95% of the pre-compaction history and prefills in under 60 s (today: 0-1.8% and 1,169-1,208 s). 2. The first turn after the summary reuses at least 95% of the retained tail and prefills in under 60 s (today: 0% and 327-356 s). 3. After 500 compactions in one session, the segment index and the KV footprint stay bounded and do not grow linearly with the number of compactions. 4. Re-anchored logits against a full prefill of the same prompt: max absolute difference at most 1e-3 on the fp16 baseline, with the int8 tolerance stated separately. 5. After a crash and restart, at least 95% of the active segments are restored. ### 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`, and `skip parking`. Closest: - **#3701 (open)** — a post-summary re-read of 154,601 tokens (97.8 s) on 2x V100; its compaction call reused 195,153 of 202,451 tokens (96.4%). This report is the other case: the compaction request itself re-reads 331K-342K, five times. - **#3928 (open)** — the same machine, the Stop path: a cancelled read loses its prefix and the next request re-reads 375,844 tokens. Its root cause 1 notes the post-compaction re-read; this report adds the compaction request's own read, the five-cycle measurements, and the engine-side mechanism. - **#3584 (open pull request)** — suffix reuse with LCP-verified mounts, dense tail checkpoints, and a state ladder; the long-term section above is the compaction acceptance case for it. - **#2508 (closed)** and **#2431 (closed)** — earlier KV compaction and prefix-sharing proposals. I found no existing report that measures the compaction request itself across repeated compactions.
Author
Owner

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

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

@xvcezrqpbxtpzblrt commented on GitHub (Oct 27, 2026):

Real /compact on 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):

  • Surface before compaction: 282,107 tokens. The conversation parked as a 4.79 GiB snapshot in 1.93 s.
  • Compaction request: 282,474 tokens, reused 282,077 (99.86%), read 397, prefill 3.8 s, summary 5,227 tokens in 137.4 s; the command took 141.6 s. The report's cycles read 331K-342K tokens in 19.5-20.1 minutes each.
  • The summarizer's input was the full 282K prefix, not 0-1.8% of it.
  • First turn after the summary: 11,810 tokens, reused 6,127 + read 5,683, prefill 8.5 s, 9.4 s for the turn. The current Harness retains about 5.7K tokens verbatim, not the 95K-104K of the 0.1.48 log.

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.

<!-- gh-comment-id:6448493376 --> @xvcezrqpbxtpzblrt commented on GitHub (Oct 27, 2026): Real `/compact` on 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): - Surface before compaction: 282,107 tokens. The conversation parked as a 4.79 GiB snapshot in 1.93 s. - Compaction request: 282,474 tokens, **reused 282,077 (99.86%)**, read 397, prefill **3.8 s**, summary 5,227 tokens in 137.4 s; the command took **141.6 s**. The report's cycles read 331K-342K tokens in 19.5-20.1 minutes each. - The summarizer's input was the full 282K prefix, not 0-1.8% of it. - First turn after the summary: 11,810 tokens, reused 6,127 + read 5,683, prefill 8.5 s, 9.4 s for the turn. The current Harness retains about 5.7K tokens verbatim, not the 95K-104K of the 0.1.48 log. 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.
Author
Owner

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

  1. Re-test on 0.2.11. 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:6659842272 --> @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: 1. Re-test on 0.2.11. 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#1721
No description provided.