mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1164] [CLOSED] conversation cache: a shared prefix is copied out of a parked conversation instead of taking it over, so the parked one keeps its history #3280
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#3280
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/1164
Author: @BlueKingMuch
Created: 10/6/2026
Status: ❌ Closed
Base:
main← Head:cache-borrow📝 Commits (4)
ed63fa8conversation cache: a conversation parked again keeps at most an eighth of each K/V buffer in reserve (was up to 16 MiB per buffer, 0.4-0.5 GB per conversation)2a30c04serve: a new conversation that starts with a checkpoint of a parked one borrows it, the parked conversation stays (sibling subagents no longer cost each other their history)94b5906Merge v0.1.40.3 into cache-borrowcf7f3e8conversation cache: a match that reaches a pin=N prefix is taken instead of borrowed📊 Changes
9 files changed (+403 additions, -25 deletions)
View changed files
📝
docs/DETAILS.md(+13 -4)📝
include/strata/core/conversation_buffer.hpp(+11 -5)📝
include/strata/core/conversation_cache.hpp(+70 -11)📝
include/strata/core/conversation_snapshot.hpp(+15 -0)📝
src/core/conversation_cache_test.cpp(+147 -0)📝
src/core/conversation_snapshot.cpp(+16 -2)📝
src/core/conversation_snapshot_test.cpp(+31 -0)📝
src/core/conversation_state.cpp(+27 -0)📝
src/program/generate.cpp(+73 -3)📄 Description
Builds on #1163 (the first commit); this PR is the second.
An agent harness that runs subagents sends several conversations that start with the same system prompt and tool list. The conversation cache checkpoints that prefix, and when a new conversation finds it only inside a parked one (because another conversation is in the session at that moment), it moves that whole parked conversation into the session and overwrites it after the checkpoint. The parked conversation is gone, and its next turn reads its history again.
With this, the new conversation borrows: only the K/V up to the checkpoint and the checkpoint itself come over (
conversation_snapshot_restore_prefix), and the parked conversation stays where it is. A match on a parked conversation's live state or its newest checkpoint is that conversation going on, and it is moved into the session as before (ConversationCache::borrows). While the outgoing conversation is parked, the one borrowed from is pinned, so parking cannot evict it; if the outgoing conversation fits only in its room, it is moved in as before and the outgoing one keeps its place. The engine log says "borrowed".#1090 (prefix snapshots on disk) changes the same decision: a saved prefix wins over a parked conversation that matches no further, so that conversation is not taken out. With this PR it is not taken out either, and nothing is read from disk.
Measured
Same setup as #1163, also on 0.1.40.1 against v0.1.40.1 (a layer split never borrows - its stages restore whole images only - a borrow clears a batch slot as a source, as a taken conversation does, and without
--mtpit takes no draft K/V, as parking saves none): RTX 4080 SUPER 32 GB, Ryzen 7 5800X3D, 96 GB, Windows 11, IQ3_S, 262K context,--conversation-cache-mib 2816 --conversation-cache-slots 3, a fixed expert placement (--adapt-every 1000000 --expert-cache 8031), greedy, 64-token answers. A main agent P (30,000 tokens) and two subagents S1 and S2 with the same system prompt (15,000 each) take turns for two rounds, every return +2,300 tokens: P1 S1 P2 S2 S1b S2b P3 S1c S2c P4. Prompt tokens read, time to first token:With both, every return resumes its conversation (2.8 to 3.0 s). The second eviction is S1 at P4, by 5 MB: three conversations of 0.8 to 1.1 GiB and the one being switched in fill 2816 MiB.
Why it builds on #1163: borrowing keeps one more conversation in the cache, and with the reserve unbounded that pushed the main agent out - this PR alone on v0.1.40.1, same run: P3 read 34,728 tokens again (12.1 s instead of 2.9 s), all ten requests 54.5 s instead of 42.9 s.
The answers: with the fixed placement all ten equal #1163 alone (S2 borrowed gives the same tokens as S2 moved in the old way), and the main agent's four answers equal a run without subagents.
Tests:
conversation_cache_test(which matches borrow and which do not, pinning against slot and byte eviction and the drop of superseded copies, the refusal when the outgoing conversation fits only in the donor's room) andconversation_file_teston Windows;conversation_snapshot_test(on the GPU: the borrowed prefix and its checkpoint give the same bytes as restoring the whole conversation and rewinding to the checkpoint, and the parked image stays unchanged) on Windows with CUDA. The same run without--mtpborrows the same way.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.