mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #309] [CLOSED] serve: keep retained K/V through the cache capacity gate #2565
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#2565
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/309
Author: @chimpera
Created: 9/30/2026
Status: ❌ Closed
Base:
main← Head:pr-keep-retained-kv-0.1.30📝 Commits (1)
c84968bserve: keep retained K/V through the cache capacity gate📊 Changes
1 file changed (+6 additions, -5 deletions)
View changed files
📝
src/program/generate.cpp(+6 -5)📄 Description
Follow-up from running the conversation cache (#189) in production and post-morteming a long real-world session. Nothing here is a correctness bug — the cache stayed consistent throughout — it's an efficiency cliff the capacity gate creates once the cache is full.
What.
park_currentdiscards the retained K/V whenevercan_fitfails and falls back to a full snapshot capture:This removes the gate. Capacity stays
make_room's decision — it runs immediately after — andput()'s accounting still bounds the budget.Where it bites. The workload is a serving box with one long-lived conversation re-parked every round trip (an agent tool loop) while short-lived conversations come and go and keep the cache full. Once
bytes()is at budget, the gate fires on EVERY park of the long conversation: the restore before each park had retained its K/V correctly, and the park throws it away. The entry still parks — as a whole-snapshot capture (hundreds of ms at ~100K tokens; the incremental path exists for exactly this shape and never engages), and the cycle repeats every round trip.Why the fallback doesn't protect the thing it claims. The comment says growth must not evict useful conversations, but
make_roomenforces that policy itself, with the priority your tests pin (conversation_cache_test.cpp:80-82):So a park carrying its own retained K/V is not a fresh arrival competing for capacity: the parked image replaces memory the cache already counts through
reuse_, and under real pressuremake_roomdrops the reuse before evicting anyone. Once the cache is full, the gate changes only WHAT gets captured, and both of its terms are covered downstream anyway:make_roomalso evicts whileentries_.size() >= slots_, so with slots full exactly one LRU eviction happens whether the reuse was kept or dropped;fresh_estimateis LARGER than the with-reuse estimate, somake_roomevicts the same entries or MORE.Net effect of the gate at a full cache: identical-or-worse eviction, plus a whole-snapshot recapture instead of the growth. If we're misreading the intent behind the pre-check we'd genuinely like to know — but as far as we can trace, nothing it protects survives its removal.
One subtlety reviewers should check. The with-reuse estimate passed to
make_roommust stay UNCAPPED.ConversationBuffer::bytes()counts segment capacities, andput()charges the completed image's true size on the same basis — capping the estimate at the fresh figure would under-evict and overfill the budget. (We found this the hard way with a capped variant: a small-budget run parked an imagemake_roomhad not made room for.)Tests. None needed:
can_fitstays as a non-mutating query with its existing coverage (the unit tests at conversation_cache_test.cpp:76-82 still pass unchanged). On top of the unit suites we ran the repo's own conversation_cache_parity harness on this exact change (single GPU, STRATA_STATE_HASH): reuse at spec 1 byte-exact and spec 4, the pressure scenario at a fit-individually-not-together budget, and the exchange scenario — the last on both the patched and unpatched build at the same budget, identical PASS. A serve-loop-level regression test for "a full cache keeps the incremental re-park" would need the two-conversation harness; happy to add one if you want it in-tree.Measured on our serving deployment (2-GPU split, int8 K/V, ~300 KB/token parked): a ~160K-token conversation with the cache at budget re-parks in growth-only time instead of a 400-900 ms full capture per tool round trip; restores are unaffected (56 ms for a 64K-token checkpoint).
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.