[GH-ISSUE #1620] serve: a cancelled request loses the conversation cache entry it restored (take() without a park), so the next request re-reads the prompt #651

Closed
opened 2026-11-04 01:44:48 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @taxah92 on GitHub (Oct 8, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1620

Summary

A request restored from the conversation cache removes its entry from the cache (ConversationCache::take(), include/strata/core/conversation_cache.hpp:251-256), and the entry is put back only when the conversation is parked at the end of a completed turn (put(), line 323). A request that is cancelled (client disconnect, idle timeout, an explicit stop) never parks, so the conversation loses its slot; the next request for it matches only the root checkpoint and re-reads everything after it.

Companion report: #1619 — with one request turn, a queued request receives no bytes at all, which is what makes clients with a stream idle timeout abort in the first place.

Environment

  • Strata v0.1.41 (the same was visible on 0.1.40.3), source build sm_70, Tesla V100 SXM2 16 GB, Ubuntu 26.04
  • Qwen3.8-Flash-Next IQ3_S, 1M context (YaRN), --kv k8v4 --kv-resident 32768, --spec 3, --conversation-cache-mib 24576 --conversation-cache-slots 3 --prompt-cache 16 --prompt-cache-every 8192
  • Three concurrent conversations (one parent session and two subagents), one request turn

What we see

Engine log, consecutive lines of one sequence:

conversation cache: restored 141020 tokens (live) in 218.4 ms; parked=3 bytes=13708493512
prompt 141160 tokens = 141020 reused + 0 of 140 read ... 0 generated          <- cancelled
conversation cache: restored 105295 tokens (live) in 164.4 ms; parked=2 bytes=9559936460
prompt 105674 tokens = 105295 reused + 374 of 379 read ... 0 generated        <- cancelled
prompt 141160 tokens = 12166 reused + 91392 of 128994 read ... 0 generated    <- only the root matched
prompt 105674 tokens = 12166 reused + 13056 of 93508 read ... 0 generated     <- only the root matched
prompt 141160 tokens = 12166 reused + 128994 read in 96446 ms, 585 generated  <- 96 s re-read

parked=2 shows the entry was taken and not returned. The 12 166-token prefix is what looks like the system prompt plus the tool definitions (the root checkpoint), so 93-129k tokens were re-read for each conversation. Totals from one day of logs: 28 events where only the root matched, ~740k tokens re-read ≈ 9-10 minutes of prefill, plus the same again for the aborted attempts.

Suggested fix

Keep the taken snapshot alive until the turn ends, or re-insert it when the request is cancelled before it parks. The image already exists — it is take()n and dropped. Parking what a cancelled turn has (its state is valid up to the point it stopped) would preserve the slot as well. At the very least, keep the entry instead of removing it: best() matches prefixes, so a stale live image still shortens the next read.

Related: #175 (explicit strata_cache_slot) — this is the same "returning to the original chat rereads its large prompt" complaint, but on the cancel path rather than the interleaved-request path.

Originally created by @taxah92 on GitHub (Oct 8, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1620 ## Summary A request restored from the conversation cache removes its entry from the cache (`ConversationCache::take()`, `include/strata/core/conversation_cache.hpp:251-256`), and the entry is put back only when the conversation is parked at the end of a **completed** turn (`put()`, line 323). A request that is cancelled (client disconnect, idle timeout, an explicit stop) never parks, so the conversation loses its slot; the next request for it matches only the root checkpoint and re-reads everything after it. Companion report: #1619 — with one request turn, a queued request receives no bytes at all, which is what makes clients with a stream idle timeout abort in the first place. ## Environment - Strata v0.1.41 (the same was visible on 0.1.40.3), source build sm_70, Tesla V100 SXM2 16 GB, Ubuntu 26.04 - Qwen3.8-Flash-Next IQ3_S, 1M context (YaRN), `--kv k8v4 --kv-resident 32768`, `--spec 3`, `--conversation-cache-mib 24576 --conversation-cache-slots 3 --prompt-cache 16 --prompt-cache-every 8192` - Three concurrent conversations (one parent session and two subagents), one request turn ## What we see Engine log, consecutive lines of one sequence: ``` conversation cache: restored 141020 tokens (live) in 218.4 ms; parked=3 bytes=13708493512 prompt 141160 tokens = 141020 reused + 0 of 140 read ... 0 generated <- cancelled conversation cache: restored 105295 tokens (live) in 164.4 ms; parked=2 bytes=9559936460 prompt 105674 tokens = 105295 reused + 374 of 379 read ... 0 generated <- cancelled prompt 141160 tokens = 12166 reused + 91392 of 128994 read ... 0 generated <- only the root matched prompt 105674 tokens = 12166 reused + 13056 of 93508 read ... 0 generated <- only the root matched prompt 141160 tokens = 12166 reused + 128994 read in 96446 ms, 585 generated <- 96 s re-read ``` `parked=2` shows the entry was taken and not returned. The 12 166-token prefix is what looks like the system prompt plus the tool definitions (the root checkpoint), so 93-129k tokens were re-read for each conversation. Totals from one day of logs: 28 events where only the root matched, ~740k tokens re-read ≈ 9-10 minutes of prefill, plus the same again for the aborted attempts. ## Suggested fix Keep the taken snapshot alive until the turn ends, or re-insert it when the request is cancelled before it parks. The image already exists — it is `take()`n and dropped. Parking what a cancelled turn has (its state is valid up to the point it stopped) would preserve the slot as well. At the very least, keep the entry instead of removing it: `best()` matches prefixes, so a stale live image still shortens the next read. Related: #175 (explicit `strata_cache_slot`) — this is the same "returning to the original chat rereads its large prompt" complaint, but on the cancel path rather than the interleaved-request path.
Author
Owner

@Niko1221 commented on GitHub (Oct 10, 2026):

Fixed in v0.1.42. A request cancelled before it has read past the conversation it restored (or between two verify windows of a short read) now leaves that conversation as the live one, so the next request continues from it or parks it on the switch, instead of the entry being lost. A cancel in the middle of a batched or pipelined prompt chunk still leaves the session between two chunks (nothing safe to keep there); the checkpoints are kept as before. Test: tools/cancel_park_test.py (restore, cancel, ask again): the follow-up reuses 1834 of 1851 prompt tokens, 0.1.41 reuses 1523. Thank you for the precise trace.

<!-- gh-comment-id:6099638262 --> @Niko1221 commented on GitHub (Oct 10, 2026): Fixed in v0.1.42. A request cancelled before it has read past the conversation it restored (or between two verify windows of a short read) now leaves that conversation as the live one, so the next request continues from it or parks it on the switch, instead of the entry being lost. A cancel in the middle of a batched or pipelined prompt chunk still leaves the session between two chunks (nothing safe to keep there); the checkpoints are kept as before. Test: tools/cancel_park_test.py (restore, cancel, ask again): the follow-up reuses 1834 of 1851 prompt tokens, 0.1.41 reuses 1523. Thank you for the precise trace.
Author
Owner

@Niko1221 commented on GitHub (Oct 13, 2026):

Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.

If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.

<!-- gh-comment-id:6156159425 --> @Niko1221 commented on GitHub (Oct 13, 2026): Thanks for the report. To keep the tracker current we are closing issues older than three days: [0.1.44](https://github.com/Niko1221/Strata/releases/tag/v0.1.44) is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1. If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.
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#651
No description provided.