mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1503] [CLOSED] [Engine] conversation cache: never park one conversation with another's retained K/V #3495
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#3495
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?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1503
Author: @sanastasiou
Created: 10/8/2026
Status: ❌ Closed
Base:
main← Head:fix/retained-kv-leak📝 Commits (1)
cef12c8conversation cache: never park one conversation with another's retained K/V📊 Changes
4 files changed (+77 additions, -8 deletions)
View changed files
📝
include/strata/core/conversation_cache.hpp(+24 -4)📝
src/core/conversation_cache_test.cpp(+35 -0)📝
src/program/generate.cpp(+9 -2)📝
sycl/src/program/generate.cpp(+9 -2)📄 Description
Problem and result
With
--batchand conversation parking, one conversation can be parked with another conversation's K/V in its snapshot. Restoring it later serves the other conversation's content.A restore keeps the restored K/V (
ConversationCache::retain) so the next park of the main session copies only what changed. The reuse tracked a token count (unchanged_tokens), not whose tokens.copy_from_slot(a batch slot giving its conversation back to the main session) replaces the main session's K/V but did not drop the retained image. The next park then reused the earlier conversation's K/V for the new one's prefix.Seen in production on a 2-GPU layer split,
--batch 2,--conversation-cache-mib 24576, 4 Claude Code clients:Before: Q's reply named a file path that existed only in P's context, and Q answered from P's history from then on. In five 4-conversation runs, 29 parks reused a retained image after a slot had replaced the main session.
After: a park reuses retained K/V only for the prefix the live conversation shares with the conversation it came from; otherwise it copies in full.
Related discussion
none (focused bug fix)
Approach
retain()records the ids of the conversation the K/V belongs to.take_reuse_for(live). It reuses only the prefix thatliveshares with those ids. With no shared prefix, or no recorded ids, nothing is reused.copy_from_slotdrops the retained image before it replaces the main session's K/V.sycl/src/program/generate.cpp.Compatibility: the reuse only ever skipped a copy. Cutting it costs at most one full copy of the parked conversation's K/V; the output is otherwise identical. No flag, no default change.
Validation
Passed:
maine88ee39d(0.2.0-beta + 12 commits; the branch merges cleanly), Ubuntu 24.04, gcc 13.3:cmake -G Ninja -S . -B b -DSTRATA_BUILD_CONVERSATION_TESTS=ON -DSTRATA_ENABLE_CUDA=OFF && cmake --build b && (cd b && ctest -R "conversation|session_save")→ 5/5 tests passed;
conversation_cache_test: 4778 checks passed. The new cases: another conversation never gets the retained K/V; a diverging conversation reuses only the shared prefix; a rewrite's limit still holds on every stage; an image of unknown identity is never reused. The first case fails if the ids comparison is removed (checked by mutation on the original revision).3d1fb480) with this change (plus four unrelated local patches), Linux,CMAKE_CUDA_ARCHITECTURES=86,-DSTRATA_ENABLE_CUDA=ON: builds. It boots and serves Qwen3.8-Flash-Next IQ3_S on 2x RTX 3090 (24 GB each), layer split,--batch 2, conversation cache on, Debian 13, 256 GB RAM.Failed:
none observed
Not run:
generate.cppedit line for line but is not compiled.Limits
The guard only cuts reuse; it does not add any. A conversation restored, handed to a slot and given back re-copies its full K/V on its next park.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.