mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #1347] serve: a full conversation cache drops the snapshot at the physical-RAM gate instead of evicting to pass it (270k tokens re-read, 96 s, 32 times) #546
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#546
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?
Originally created by @alanthinker on GitHub (Oct 7, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1347
The physical-RAM admission gate for parking a conversation is final: when it fails, the snapshot is thrown away even though the cache is holding parked conversations whose RAM it could take back. A long prompt then reads its whole context again.
Environment
--max-context 524288,--kv int8,--kv-resident 32768loaded 46.84 GiBaftercudaHostRegister ... ok, so 46.84 GiB is pinned and not reclaimable--conversation-cache-mib 25600 --conversation-cache-slots 25 --conversation-cache-min-free-mib 6144(the defaults in the deploy script)What happens
An agent harness keeps several long conversations. Every time one of them parks, the physical-RAM gate refuses, and the next request re-reads the whole prompt.
From one session's log (before the fix), 95 rejections:
32 of them were a full re-read of a ~270k-token context at ~2800 tok/s, i.e. ~96 s each.
Why it fails
make_room()only balances the cache's own budget (--conversation-cache-miband the slots). The second gate then asks the host for real free RAM:Measured on this machine:
additionalis about 4.73 GiBMemAvailableSo it fails by ~2.1 GiB — while the cache at that moment held 18.94 GiB in 12 parked conversations (
parked=12 bytes=20341561640), i.e. more than four times what the snapshot needed. Evicting one or two of them would have admitted it.The asymmetry is that
make_room()frees RAM by budget, and the gate then decides on RAM, but nothing connects the two: the gate's verdict is final andmake_room()is never asked again.Proposed fix
Evict least-recently-active parked conversations until the gate passes, bounded by the slot count. Each
ConversationBufferis a list of 16 MiB segments and each segment is its own allocation, far above glibc's mmap threshold, so an evicted entry is back with the kernel by the time the next check reads/proc/meminfo— no waiting is needed between the eviction and the re-check.The floor-only re-check after the capture is left alone: by then the snapshot is already built and evicting cannot make room for it.
Implementation (2 files, ~20 lines), on top of
82f46a8:include/strata/core/conversation_cache.hpp— factormake_room()'s loop body intoevict_oldest(), addslots()as the loop boundsrc/program/generate.cpp— retry the gate after each eviction; the failure line now reports how many were evicted and how many are still parked, and a new line reports the evictions that made the snapshot fitNo data-structure or interface change: the
private:section is byte-identical,make_room()keeps its signature and its behaviour (its three inlined statements became the body ofevict_oldest()), and both new methods are additions.conversation_cache_testpasses 4,197 checks including 6 new ones;conversation_memory_test(23) andserve/test_monitor(10) pass unchanged.Commit:
github.com/alanthinker/Strata@c62b540Workaround, for anyone hitting this now
Either lower
--conversation-cache-min-free-mibor lower--conversation-cache-mibbelow what the cache actually holds. Both are a trade: too little floor and the host goes short, too small a budget and the parked conversations evict each other instead. Neither removes the failure, it only moves the threshold — which is what the fix above is for.Related
@Niko1221 commented on GitHub (Oct 8, 2026):
Thanks @alanthinker. The fix is in 0.1.41 with your authorship kept on the commit. One change: a parked conversation that holds a pinned shared prefix is not evicted by the RAM gate (
evict_oldest()returns false when only such entries are left), because the pinned prefix is what later queries come back to. The failure line reports how many were evicted and how many are still parked, as you proposed;conversation_cache_testpasses with 4,208 checks, including new ones for the pinned case.