[GH-ISSUE #4206] [Engine] --prompt-cache-every is a no-op when N is below the prefill chunk size #1849

Closed
opened 2026-11-04 01:54:42 +07:00 by bsakaguchi · 5 comments
Owner

Originally created by @3chet on GitHub (Oct 26, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4206

Version: Strata 0.1.50 | engine 0.1.50

Hardware: 2x AMD Radeon Pro VII 16 GB (gfx906) | 64 GB RAM | Ubuntu 26.04.1 | ROCm 7.1.1 (Docker)

Model: Qwen3.8-Flash-Next IQ3_S | 163840 context | pictures off | layer split K=12 | MTP self-speculation on

Reproduction status: reproduced locally

What happened

A client that appends one turn to the end of an existing history — the prefix is
byte-identical, nothing is edited, nothing is re-generated — still re-reads the whole
prompt:

conversation cache: parked 12750 tokens
prompt 12747 tokens = 0 reused + 12747 read in 25838 ms (493.3 tok/s), 8 generated in 158 ms, 1 checkpoints

I expected ~12742 of those to be reused. Two separate things combine to make it zero,
and I think the first one is a documentation/behaviour mismatch rather than a design
choice.

1. --prompt-cache-every is clamped up to the prefill chunk size.

The help text says:

--prompt-cache-every N  --serve: also checkpoint every N fresh prompt tokens (default 16384, 0 = off)

but the checkpoint is only created inside the chunk callback, where done is the end of
a whole chunk (generate.cpp:9934 and :9942 in 0.1.50):

const int64_t done = p0 + T;                 // T = the whole chunk
...
const bool periodic_checkpoint = o.prompt_cache_every > 0 && done >= pp_next_check;
...
if (periodic_checkpoint) pp_next_check = done + o.prompt_cache_every;   // :9965

done never takes an intermediate value, so the effective spacing is
max(--prompt-cache-every, chunk). With the default --prefill auto:16384, a 12742-token
prompt is exactly one chunk, which yields exactly one checkpoint, at the very end — and
setting --prompt-cache-every 4096 changes nothing at all (measured below).

2. That single end checkpoint is then unusable, because it is longer than the new prompt.

conversation_prefix() (include/strata/core/conversation_cache.hpp:187) requires a
strict prefix that is shorter than the incoming prompt:

const size_t n = c.ids.size();
if (n == 0 || n >= prompt.size() || !std::equal(c.ids.begin(), c.ids.end(), prompt.begin())) return 0;

The end checkpoint carries the tokens that opened the turn (the session parks at 12750),
so for an incoming 12747-token prompt n >= prompt.size() is true and the whole
checkpoint is discarded. There is no earlier checkpoint to fall back to, so the prompt is
read from zero.

--prompt-cache-spread does not help here, which is consistent with its help text — it
only changes which checkpoint is evicted (conv_cache::spread_victim, generate.cpp:9885),
not how many exist. Reports of "rewriting the tail still re-reads everything" will
probably land on --prompt-cache-spread first, so it may be worth noting that the
checkpoint density is bounded by the chunk size.

What does work: lowering the chunk cap. --prefill auto:8192 produces two
checkpoints for the same prompt; the 8192 one sits before the divergence and is usable:

conversation cache: restored 8192 tokens (checkpoint) in 73.6 ms
prompt 12747 tokens = 8192 reused + 4555 read in 12077 ms (377.2 tok/s), 8 generated in 157 ms, 2 checkpoints

So the workaround is to treat the chunk size as the checkpoint granularity.

Smallest steps or command that reproduce it

Probe: send A (12742 tokens), then B (12743 tokens, different prefix, to force A to be
parked), then A + "\n\nReply with OK." (12747 tokens — A's entire prefix unchanged,
five tokens appended at the end).

With --prefill auto:16384 --prompt-cache 8192 --prompt-cache-every 4096, the third
request reports 0 reused + 12747 read, 1 checkpoints.

Restart the same server with --prefill auto:8192 only, repeat the probe, and the third
request reports 8192 reused + 4555 read, 2 checkpoints, restored 8192 tokens (checkpoint) in 73.6 ms.

Same probe, four configurations, two runs each:

config reused on the third request wall
--prefill auto:16384 (default) + --prompt-cache-spread 0 25.19 s
--prefill auto:16384 + --prompt-cache-spread + --prompt-cache-every 4096 0 25.18 s
--prefill auto:4096 8192 12.09 s
--prefill auto:8192 8192 12.26 s

Cost of the smaller chunk on a cold 24k-token prompt (two runs each, --short-read 256):

chunk cap fresh prompt tokens/s
16384 599.3 / 599.0
8192 567.6 / 587.2
4096 559.9 / 588.3

So the workaround costs 3–4% prefill throughput on long prompts, and halves the wall time
of a tail-appended turn (25.2 s → 12.1 s). Decode and expert-cache hit rate are unchanged
(50.5–50.8 tok/s, 0.985–0.988).

What would fix it

Option A, smallest: when --prompt-cache-every < chunk, treat every as an upper bound
on the chunk too, so the requested density is honoured instead of silently clamped. This
is exactly what I am doing by hand now, and it makes the option mean what its help text
says.

Option B: split the chunk at pp_next_check internally, so a checkpoint can land
mid-way through what would otherwise be one chunk.

Either way, a line in the help text saying "effective spacing is max(N, chunk)" would
avoid this report for the next person.

A question about the checkpoint at the end of the last chunk

With --prefill auto:8192 there are 2 checkpoints, but only 8192 is reused — even
though a checkpoint at 12742 would be a valid strict prefix of the 12747-token prompt
(12742 < 12747). Is the last chunk's checkpoint being dropped, or stored past the
prompt end? In the multi-GPU path I see a completeness test that discards a set that is
not fully assembled (generate.cpp:9958):

bool complete = parts.size() == stages.size() + 1;
saved = !complete || checkpoint_at(done, &parts);   // an incomplete set: no checkpoint here

If the last (short) chunk tends to produce an incomplete set, that would explain it, and
it would mean that on multi-GPU a tail-appended turn can never reuse the deepest
checkpoint. If that checkpoint could be kept, this case would go from 8k reused to ~12.7k
(roughly 12.1 s → 4 s).

Related, and lower priority: --prompt-cache-tail says "single GPU" in its help text, and
the code excludes it with !multi_gpu (generate.cpp:9946). Since part_at already
assembles per-stage checkpoints for the multi-GPU path, extending the tail checkpoint there
would give layer-split users the one mechanism that directly covers an appended turn.

Originally created by @3chet on GitHub (Oct 26, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4206 **Version**: Strata 0.1.50 | engine 0.1.50 **Hardware**: 2x AMD Radeon Pro VII 16 GB (gfx906) | 64 GB RAM | Ubuntu 26.04.1 | ROCm 7.1.1 (Docker) **Model**: Qwen3.8-Flash-Next IQ3_S | 163840 context | pictures off | layer split K=12 | MTP self-speculation on **Reproduction status**: reproduced locally ### What happened A client that **appends** one turn to the end of an existing history — the prefix is byte-identical, nothing is edited, nothing is re-generated — still re-reads the whole prompt: ``` conversation cache: parked 12750 tokens prompt 12747 tokens = 0 reused + 12747 read in 25838 ms (493.3 tok/s), 8 generated in 158 ms, 1 checkpoints ``` I expected ~12742 of those to be reused. Two separate things combine to make it zero, and I think the first one is a documentation/behaviour mismatch rather than a design choice. **1. `--prompt-cache-every` is clamped up to the prefill chunk size.** The help text says: ``` --prompt-cache-every N --serve: also checkpoint every N fresh prompt tokens (default 16384, 0 = off) ``` but the checkpoint is only created inside the chunk callback, where `done` is the end of a whole chunk (`generate.cpp:9934` and `:9942` in 0.1.50): ```cpp const int64_t done = p0 + T; // T = the whole chunk ... const bool periodic_checkpoint = o.prompt_cache_every > 0 && done >= pp_next_check; ... if (periodic_checkpoint) pp_next_check = done + o.prompt_cache_every; // :9965 ``` `done` never takes an intermediate value, so the effective spacing is `max(--prompt-cache-every, chunk)`. With the default `--prefill auto:16384`, a 12742-token prompt is exactly one chunk, which yields exactly one checkpoint, at the very end — and setting `--prompt-cache-every 4096` changes nothing at all (measured below). **2. That single end checkpoint is then unusable, because it is longer than the new prompt.** `conversation_prefix()` (`include/strata/core/conversation_cache.hpp:187`) requires a strict prefix that is *shorter* than the incoming prompt: ```cpp const size_t n = c.ids.size(); if (n == 0 || n >= prompt.size() || !std::equal(c.ids.begin(), c.ids.end(), prompt.begin())) return 0; ``` The end checkpoint carries the tokens that opened the turn (the session parks at 12750), so for an incoming 12747-token prompt `n >= prompt.size()` is true and the whole checkpoint is discarded. There is no earlier checkpoint to fall back to, so the prompt is read from zero. `--prompt-cache-spread` does not help here, which is consistent with its help text — it only changes which checkpoint is evicted (`conv_cache::spread_victim`, `generate.cpp:9885`), not how many exist. Reports of "rewriting the tail still re-reads everything" will probably land on `--prompt-cache-spread` first, so it may be worth noting that the checkpoint *density* is bounded by the chunk size. **What does work: lowering the chunk cap.** `--prefill auto:8192` produces two checkpoints for the same prompt; the 8192 one sits before the divergence and is usable: ``` conversation cache: restored 8192 tokens (checkpoint) in 73.6 ms prompt 12747 tokens = 8192 reused + 4555 read in 12077 ms (377.2 tok/s), 8 generated in 157 ms, 2 checkpoints ``` So the workaround is to treat the chunk size as the checkpoint granularity. ### Smallest steps or command that reproduce it Probe: send A (12742 tokens), then B (12743 tokens, different prefix, to force A to be parked), then `A + "\n\nReply with OK."` (12747 tokens — A's entire prefix unchanged, five tokens appended at the end). With `--prefill auto:16384 --prompt-cache 8192 --prompt-cache-every 4096`, the third request reports `0 reused + 12747 read`, `1 checkpoints`. Restart the same server with `--prefill auto:8192` only, repeat the probe, and the third request reports `8192 reused + 4555 read`, `2 checkpoints`, `restored 8192 tokens (checkpoint) in 73.6 ms`. Same probe, four configurations, two runs each: | config | reused on the third request | wall | |---|---|---| | `--prefill auto:16384` (default) + `--prompt-cache-spread` | 0 | 25.19 s | | `--prefill auto:16384` + `--prompt-cache-spread` + `--prompt-cache-every 4096` | 0 | 25.18 s | | `--prefill auto:4096` | 8192 | 12.09 s | | `--prefill auto:8192` | 8192 | 12.26 s | Cost of the smaller chunk on a cold 24k-token prompt (two runs each, `--short-read 256`): | chunk cap | fresh prompt tokens/s | |---|---| | 16384 | 599.3 / 599.0 | | 8192 | 567.6 / 587.2 | | 4096 | 559.9 / 588.3 | So the workaround costs 3–4% prefill throughput on long prompts, and halves the wall time of a tail-appended turn (25.2 s → 12.1 s). Decode and expert-cache hit rate are unchanged (50.5–50.8 tok/s, 0.985–0.988). ### What would fix it Option A, smallest: when `--prompt-cache-every < chunk`, treat `every` as an upper bound on the chunk too, so the requested density is honoured instead of silently clamped. This is exactly what I am doing by hand now, and it makes the option mean what its help text says. Option B: split the chunk at `pp_next_check` internally, so a checkpoint can land mid-way through what would otherwise be one chunk. Either way, a line in the help text saying "effective spacing is `max(N, chunk)`" would avoid this report for the next person. ### A question about the checkpoint at the end of the last chunk With `--prefill auto:8192` there are `2 checkpoints`, but only 8192 is reused — even though a checkpoint at 12742 would be a valid strict prefix of the 12747-token prompt (`12742 < 12747`). Is the last chunk's checkpoint being dropped, or stored past the prompt end? In the multi-GPU path I see a completeness test that discards a set that is not fully assembled (`generate.cpp:9958`): ```cpp bool complete = parts.size() == stages.size() + 1; saved = !complete || checkpoint_at(done, &parts); // an incomplete set: no checkpoint here ``` If the last (short) chunk tends to produce an incomplete set, that would explain it, and it would mean that on multi-GPU a tail-appended turn can never reuse the deepest checkpoint. If that checkpoint could be kept, this case would go from 8k reused to ~12.7k (roughly 12.1 s → 4 s). Related, and lower priority: `--prompt-cache-tail` says "single GPU" in its help text, and the code excludes it with `!multi_gpu` (`generate.cpp:9946`). Since `part_at` already assembles per-stage checkpoints for the multi-GPU path, extending the tail checkpoint there would give layer-split users the one mechanism that directly covers an appended turn.
bsakaguchi 2026-11-04 01:54:42 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 26, 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".
  • Fill in "Desktop app, Terminal or source?".
  • Fill in "Reproduction status".
  • Fill in "Strata version".
  • Fill in "Graphics card, memory and system".

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:6413706310 --> @github-actions[bot] commented on GitHub (Oct 26, 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". - [ ] Fill in "Desktop app, Terminal or source?". - [ ] Fill in "Reproduction status". - [ ] Fill in "Strata version". - [ ] Fill in "Graphics card, memory and system". 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

@3chet commented on GitHub (Oct 26, 2026):

Correction: the end checkpoint is not lost to the length check — appending more text does not help

In the report above I assumed the end checkpoint would become usable once the incoming prompt
grew past it (n >= prompt.size()). I went back and tested that instead of leaving it as a
guess, and it does not hold.

Same probe, only the appended text differs:

appended to the same 12742-token prompt prompt reused wall
"\n\nReply with OK." (~5 tokens) 12747 8192 11.8 s
40 extra words (~110 tokens) 13652 8192 13.2 s

The second prompt is longer than any checkpoint this conversation can hold, so
n >= prompt.size() is no longer what rejects it — and the reuse is still 8192, not ~12742.

Both runs log the same shape: 2 checkpoints on the prompt line, but
restored 8192 tokens (checkpoint) on the way in. So a second checkpoint is recorded, and it
is simply not the one that gets restored.

With a layer split, restored checkpoints are merged back per stage
(generate.cpp:12945-12950):

if (stages.empty()) {
    checks = std::move(incoming->checkpoints);
} else {   // give each checkpoint back its stage parts (moved, not copied); none if they do not line up
    strata::core::ConversationCheckpointSplit cs;
    cs.stage0 = std::move(incoming->checkpoints);
    for (auto& si : incoming->stage_images) cs.parts.push_back(std::move(si.checkpoints));
    if (!strata::core::conversation_checkpoints_merge(std::move(cs), checks)) checks.clear();
}

So the end checkpoint stops being usable at one of two places: the completeness test at save
time (generate.cpp:9958, parts.size() == stages.size() + 1), or this merge on restore,
which keeps only what lines up across stages. Which one is it — is the last chunk's
checkpoint expected to be unavailable on a multi-GPU layer split?

From the outside the effect is that on a layer split the deepest usable checkpoint is much
shallower than the prompt: 8192 for a 12.7k conversation. It also stays 8192 at
--prefill auto:4096 (measured 12.09 s, same 8192 reused), so lowering the chunk below 8192
does not deepen the reuse at all.

That last point narrows the workaround I had in the first post: --prefill auto:8192 is the
useful setting (25.2 s → 12.1 s on this prompt), and going lower only costs prefill speed
without buying anything back.

<!-- gh-comment-id:6413819973 --> @3chet commented on GitHub (Oct 26, 2026): **Correction: the end checkpoint is not lost to the length check — appending more text does not help** In the report above I assumed the end checkpoint would become usable once the incoming prompt grew past it (`n >= prompt.size()`). I went back and tested that instead of leaving it as a guess, and it does not hold. Same probe, only the appended text differs: | appended to the same 12742-token prompt | prompt | reused | wall | |---|---|---|---| | `"\n\nReply with OK."` (~5 tokens) | 12747 | 8192 | 11.8 s | | 40 extra words (~110 tokens) | 13652 | 8192 | 13.2 s | The second prompt is longer than any checkpoint this conversation can hold, so `n >= prompt.size()` is no longer what rejects it — and the reuse is still 8192, not ~12742. Both runs log the same shape: `2 checkpoints` on the prompt line, but `restored 8192 tokens (checkpoint)` on the way in. So a second checkpoint is recorded, and it is simply not the one that gets restored. With a layer split, restored checkpoints are merged back per stage (`generate.cpp:12945-12950`): ```cpp if (stages.empty()) { checks = std::move(incoming->checkpoints); } else { // give each checkpoint back its stage parts (moved, not copied); none if they do not line up strata::core::ConversationCheckpointSplit cs; cs.stage0 = std::move(incoming->checkpoints); for (auto& si : incoming->stage_images) cs.parts.push_back(std::move(si.checkpoints)); if (!strata::core::conversation_checkpoints_merge(std::move(cs), checks)) checks.clear(); } ``` So the end checkpoint stops being usable at one of two places: the completeness test at save time (`generate.cpp:9958`, `parts.size() == stages.size() + 1`), or this merge on restore, which keeps only what lines up across stages. Which one is it — is the last chunk's checkpoint expected to be unavailable on a multi-GPU layer split? From the outside the effect is that on a layer split the deepest usable checkpoint is much shallower than the prompt: 8192 for a 12.7k conversation. It also stays 8192 at `--prefill auto:4096` (measured 12.09 s, same 8192 reused), so lowering the chunk below 8192 does not deepen the reuse at all. That last point narrows the workaround I had in the first post: `--prefill auto:8192` is the useful setting (25.2 s → 12.1 s on this prompt), and going lower only costs prefill speed without buying anything back.
Author
Owner

@3chet commented on GitHub (Oct 26, 2026):

Root cause found: the deepest checkpoint is not dropped, it is moved by two tokens

I instrumented conversation_prefix() to log the first diverging position and the two windows
around it, and then tested a patch. Both hypotheses I wrote above were wrong, including the
one I made in my previous comment — so, answering my own question first: the completeness
test (parts.size() == stages.size() + 1) and the per-stage merge are not involved.
The end
checkpoint is saved, it comes back as a candidate, and it is then rejected for a genuine
content mismatch.

1. What the checkpoint at turn_at actually contains.

turn_at is the index of the last <|im_start|> (generate.cpp:14025). A checkpoint saved
there covers the history up to that header — which means it also covers the previous
message's <|im_end|> and the \n after it. A client that appends to the last message, or
extends/rewrites it, puts its own content exactly where those two tokens were:

ckpt   [12730..12738): 33976 55980 29076 10604 635 76411 248046 198
prompt [12730..12738): 33976 55980 29076 10604 635 76411 1122 11234

248046 is <|im_end|>, 198 is \n. Six tokens match, the last two do not, so the whole
12738-token checkpoint is unusable — and because it is the deepest one, reuse falls back to
the previous chunk boundary (8192), which is exactly the "8192 for a 12.7k conversation" I
reported.

2. This is also why --prompt-cache-every cannot fix it, even if it worked.

Every checkpoint it produces lands on a chunk boundary, and the body end is not one. Same for
Option B — splitting the chunk at pp_next_check gives you more checkpoints, but not one at
turn_at - 2. The missing checkpoint is at a semantic position, not at a multiple of N, so
density and granularity are two different knobs here.

3. One more cut at turn_at - k does fix it.

Local patch, three places (env-gated with STRATA_CKPT_BODY_AT=<k> in my build so I could
A/B the same binary; k = 0 is stock):

// after `turn_at` is resolved, before `cuts` is built
const int64_t body_at = k > 0 && turn_at - k > resume && turn_at - k < n - 1 ? turn_at - k : -1;

std::vector<int64_t> cuts = {reread_to, root_at, message_at, turn_at, n - 1};
if (body_at > 0) { cuts.push_back(body_at); std::sort(cuts.begin(), cuts.end()); }

// the save condition, alongside the other named cuts
if ((to == turn_at || to == body_at || to == root_at || to == message_at || to == pin_at) &&
    !checkpoint_at(to, nullptr, ...))

k = 2 for this chat template (<|im_end|> + \n); it should be derived from the template
rather than hardcoded.

4. Measurements. Same probe, same binary family, --prefill auto:8192 on both arms
(--prefill is the other variable and I did not want it in the comparison):

tail-appended 12747 long append 13652 cold read 22342
stock 8192 reused, 11.54 s 8192 reused, 13.29 s 572.4 / 578.8 tok/s
body_at k=2 12735 reused, 0.78 s 13535 reused, 3.28 s 574.8 / 563.6 / 580.0 / 579.4 tok/s
conversation cache: restored 12735 tokens (checkpoint) in 76.7 ms
prompt 12747 tokens = 12735 reused + 12 read in 784 ms (15.3 tok/s), 8 generated in 180 ms, 4 checkpoints
prompt 13652 tokens = 13535 reused + 117 read in 3278 ms (35.7 tok/s), 8 generated in 176 ms, 4 checkpoints

12735 of 12747 is the whole history minus the 12 tokens that really do differ. Cold-read
throughput is unchanged (−0.2% on average, inside run-to-run noise), decode is unchanged, and
multi-turn appends are identical to stock (cached 3578 / 7355 / 11132 / 14909 / 18686 over six
turns). The cost is one more checkpoint per conversation, so with --prompt-cache 24 evictions
get marginally more frequent.

5. Correction on --prefill auto:4096.

In my previous comment I said reuse stays at 8192 with auto:4096, "so lowering the chunk
below 8192 does not deepen the reuse". That measurement was real but the reason is not the
cache: auto: is clamped (generate.cpp:2584-2586):

o.prefill_auto_max = want_max >= 32768 ? 32768 : want_max >= 16384 ? 16384 : 8192;

auto:4096 runs as 8192, so that row never tested a 4096 chunk at all. Same family of
mismatch as the --prompt-cache-every one: the value in the flag is not the value in effect.
A fixed --prefill 4096 does work, and it is slower (--prefill 12288 was −9% on cold read
here, 4096 worse), so I would rather not buy density that way.

If adding the body-end cut as a default is acceptable, I am happy to send it as a PR — the
diff is the three hunks above. Otherwise it might be the natural thing to teach
--prompt-cache-tail to do on a layer split: keep the checkpoint at the end of the last
message's body, not at the end of the prompt.

<!-- gh-comment-id:6415458606 --> @3chet commented on GitHub (Oct 26, 2026): ### Root cause found: the deepest checkpoint is not dropped, it is *moved* by two tokens I instrumented `conversation_prefix()` to log the first diverging position and the two windows around it, and then tested a patch. Both hypotheses I wrote above were wrong, including the one I made in my previous comment — so, answering my own question first: **the completeness test (`parts.size() == stages.size() + 1`) and the per-stage merge are not involved.** The end checkpoint is saved, it comes back as a candidate, and it is then rejected for a genuine content mismatch. **1. What the checkpoint at `turn_at` actually contains.** `turn_at` is the index of the last `<|im_start|>` (`generate.cpp:14025`). A checkpoint saved there covers the history *up to* that header — which means it also covers the previous message's `<|im_end|>` and the `\n` after it. A client that appends to the last message, or extends/rewrites it, puts its own content exactly where those two tokens were: ``` ckpt [12730..12738): 33976 55980 29076 10604 635 76411 248046 198 prompt [12730..12738): 33976 55980 29076 10604 635 76411 1122 11234 ``` `248046` is `<|im_end|>`, `198` is `\n`. Six tokens match, the last two do not, so the whole 12738-token checkpoint is unusable — and because it is the deepest one, reuse falls back to the previous chunk boundary (8192), which is exactly the "8192 for a 12.7k conversation" I reported. **2. This is also why `--prompt-cache-every` cannot fix it, even if it worked.** Every checkpoint it produces lands on a chunk boundary, and the body end is not one. Same for Option B — splitting the chunk at `pp_next_check` gives you more checkpoints, but not one at `turn_at - 2`. The missing checkpoint is at a *semantic* position, not at a multiple of N, so density and granularity are two different knobs here. **3. One more cut at `turn_at - k` does fix it.** Local patch, three places (env-gated with `STRATA_CKPT_BODY_AT=<k>` in my build so I could A/B the same binary; `k = 0` is stock): ```cpp // after `turn_at` is resolved, before `cuts` is built const int64_t body_at = k > 0 && turn_at - k > resume && turn_at - k < n - 1 ? turn_at - k : -1; std::vector<int64_t> cuts = {reread_to, root_at, message_at, turn_at, n - 1}; if (body_at > 0) { cuts.push_back(body_at); std::sort(cuts.begin(), cuts.end()); } // the save condition, alongside the other named cuts if ((to == turn_at || to == body_at || to == root_at || to == message_at || to == pin_at) && !checkpoint_at(to, nullptr, ...)) ``` `k = 2` for this chat template (`<|im_end|>` + `\n`); it should be derived from the template rather than hardcoded. **4. Measurements.** Same probe, same binary family, `--prefill auto:8192` on both arms (`--prefill` is the other variable and I did not want it in the comparison): | | tail-appended 12747 | long append 13652 | cold read 22342 | |---|---|---|---| | stock | 8192 reused, 11.54 s | 8192 reused, 13.29 s | 572.4 / 578.8 tok/s | | `body_at` k=2 | **12735 reused, 0.78 s** | **13535 reused, 3.28 s** | 574.8 / 563.6 / 580.0 / 579.4 tok/s | ``` conversation cache: restored 12735 tokens (checkpoint) in 76.7 ms prompt 12747 tokens = 12735 reused + 12 read in 784 ms (15.3 tok/s), 8 generated in 180 ms, 4 checkpoints prompt 13652 tokens = 13535 reused + 117 read in 3278 ms (35.7 tok/s), 8 generated in 176 ms, 4 checkpoints ``` 12735 of 12747 is the whole history minus the 12 tokens that really do differ. Cold-read throughput is unchanged (−0.2% on average, inside run-to-run noise), decode is unchanged, and multi-turn appends are identical to stock (cached 3578 / 7355 / 11132 / 14909 / 18686 over six turns). The cost is one more checkpoint per conversation, so with `--prompt-cache 24` evictions get marginally more frequent. **5. Correction on `--prefill auto:4096`.** In my previous comment I said reuse stays at 8192 with `auto:4096`, "so lowering the chunk below 8192 does not deepen the reuse". That measurement was real but the reason is not the cache: `auto:` is clamped (`generate.cpp:2584-2586`): ```cpp o.prefill_auto_max = want_max >= 32768 ? 32768 : want_max >= 16384 ? 16384 : 8192; ``` `auto:4096` runs as 8192, so that row never tested a 4096 chunk at all. Same family of mismatch as the `--prompt-cache-every` one: the value in the flag is not the value in effect. A fixed `--prefill 4096` does work, and it is slower (`--prefill 12288` was −9% on cold read here, `4096` worse), so I would rather not buy density that way. If adding the body-end cut as a default is acceptable, I am happy to send it as a PR — the diff is the three hunks above. Otherwise it might be the natural thing to teach `--prompt-cache-tail` to do on a layer split: keep the checkpoint at the end of the last message's body, not at the end of the prompt.
Author
Owner

@3chet commented on GitHub (Oct 26, 2026):

Follow-up: once the body-end cut exists, the turn_at cut is redundant — dropping it halves the tail read

With body_at (= turn_at - k) saved as its own checkpoint, keeping the turn_at cut splits the tail into
three parts instead of two, and the part in between carries only the k tokens the client moves
(<|im_end|> and \n in this template). Those two tokens pay a full fixed overhead — stage sync, copies,
buffers — measured at 341 ms on this box. The body_at checkpoint already covers everything before them.

One small change on top of the patch in my previous comment:

std::vector<int64_t> cuts = {reread_to, root_at, message_at, turn_at, n - 1};
if (body_at > 0) {
    cuts.push_back(body_at);
    // the body end replaces turn_at: the tokens between them are the ones the client moves
    cuts.erase(std::remove(cuts.begin(), cuts.end(), turn_at), cuts.end());
    std::sort(cuts.begin(), cuts.end());
}

Same probe, same binary, --prefill auto:8192, STRATA_CKPT_BODY_AT=2; the only variable is the two lines above:

tail-appended, 12747 tokens long append, 13652 tokens
body_at only 12 read in 784 / 723 / 791 ms, 4 checkpoints 117 read in 3278 / 2754 ms
body_at, turn_at cut dropped 12 read in 443 ms, 3 checkpoints 117 read in 2683 ms
prompt 12747 tokens = 12735 reused + 12 read in 443 ms (27.1 tok/s), 8 generated in 180 ms, 3 checkpoints

Multi-turn appends still land on the same checkpoints, at the cost of re-reading exactly those k tokens:

turn 2 3 4 5 6
cached, body_at only 3578 7355 11132 14909 18686
cached, no turn_at cut 3576 7353 11130 14907 18684

So: 2 tokens less reused per turn, in exchange for one less part per request. Cold read is unchanged
(578.5 / 570.4 tok/s on a 26242-token prompt, same as with both cuts). One checkpoint fewer per
conversation also takes pressure off --prompt-cache, since what was the "cost" of the previous patch
(+1 checkpoint per conversation) is now back to stock.

Two things to watch if this goes upstream.

  1. --prompt-cache-spread and the eviction path rank checkpoints by adjacency, so removing a cut changes
    what gets evicted first. Here it is one checkpoint fewer per conversation, which is the direction we want,
    but it is a behaviour change worth keeping in mind.
  2. STRATA_SLOT_CKPT_MOVE identifies "this request's own turn checkpoint" with best->ids.size() == turn_at
    (generate.cpp:15534). With the turn_at cut gone that test never matches, so the move optimization
    silently stops applying. It needs to accept body_at as well.

Net effect on my workload — appending to or editing the last message, which is what an IDE-style client does
on every turn — is 11.5 s → 0.44 s for the prompt read, with cold-read throughput and decode unchanged.

<!-- gh-comment-id:6418537753 --> @3chet commented on GitHub (Oct 26, 2026): ### Follow-up: once the body-end cut exists, the `turn_at` cut is redundant — dropping it halves the tail read With `body_at` (= `turn_at - k`) saved as its own checkpoint, keeping the `turn_at` cut splits the tail into three parts instead of two, and the part in between carries **only the `k` tokens the client moves** (`<|im_end|>` and `\n` in this template). Those two tokens pay a full fixed overhead — stage sync, copies, buffers — measured at **341 ms** on this box. The `body_at` checkpoint already covers everything before them. One small change on top of the patch in my previous comment: ```cpp std::vector<int64_t> cuts = {reread_to, root_at, message_at, turn_at, n - 1}; if (body_at > 0) { cuts.push_back(body_at); // the body end replaces turn_at: the tokens between them are the ones the client moves cuts.erase(std::remove(cuts.begin(), cuts.end(), turn_at), cuts.end()); std::sort(cuts.begin(), cuts.end()); } ``` Same probe, same binary, `--prefill auto:8192`, `STRATA_CKPT_BODY_AT=2`; the only variable is the two lines above: | | tail-appended, 12747 tokens | long append, 13652 tokens | |---|---|---| | `body_at` only | 12 read in **784 / 723 / 791 ms**, 4 checkpoints | 117 read in 3278 / 2754 ms | | `body_at`, `turn_at` cut dropped | 12 read in **443 ms**, 3 checkpoints | 117 read in **2683 ms** | ``` prompt 12747 tokens = 12735 reused + 12 read in 443 ms (27.1 tok/s), 8 generated in 180 ms, 3 checkpoints ``` Multi-turn appends still land on the same checkpoints, at the cost of re-reading exactly those `k` tokens: | turn | 2 | 3 | 4 | 5 | 6 | |---|---|---|---|---|---| | cached, `body_at` only | 3578 | 7355 | 11132 | 14909 | 18686 | | cached, no `turn_at` cut | 3576 | 7353 | 11130 | 14907 | 18684 | So: **2 tokens less reused per turn, in exchange for one less part per request.** Cold read is unchanged (578.5 / 570.4 tok/s on a 26242-token prompt, same as with both cuts). One checkpoint fewer per conversation also takes pressure off `--prompt-cache`, since what was the "cost" of the previous patch (+1 checkpoint per conversation) is now back to stock. **Two things to watch if this goes upstream.** 1. `--prompt-cache-spread` and the eviction path rank checkpoints by adjacency, so removing a cut changes what gets evicted first. Here it is one checkpoint fewer per conversation, which is the direction we want, but it is a behaviour change worth keeping in mind. 2. `STRATA_SLOT_CKPT_MOVE` identifies "this request's own turn checkpoint" with `best->ids.size() == turn_at` (`generate.cpp:15534`). With the `turn_at` cut gone that test never matches, so the move optimization silently stops applying. It needs to accept `body_at` as well. Net effect on my workload — appending to or editing the last message, which is what an IDE-style client does on every turn — is **11.5 s → 0.44 s for the prompt read**, with cold-read throughput and decode unchanged.
Author
Owner

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

Closing this issue because it still did not follow the format after 5 days. That is housekeeping, not a rejection.

To bring it back: fix the title (area prefix) and the missing parts, then comment /reopen. A check runs and reopens it, or tells you what is still missing. See CONTRIBUTING.md.

<!-- gh-comment-id:6553366962 --> @github-actions[bot] commented on GitHub (Nov 1, 2026): Closing this issue because it still did not follow the format after 5 days. That is housekeeping, not a rejection. To bring it back: fix the title (area prefix) and the missing parts, then comment `/reopen`. A check runs and reopens it, or tells you what is still missing. See [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#1849
No description provided.