mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #2264] Conversation cache re-parks the same conversation every turn: 2251.9 GB of host copies at 4.7 % reuse, and the K/V retention that would make the write incremental can never apply #908
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#908
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 @Krypto-Whitehat on GitHub (Oct 13, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2264
Summary
Once a conversation has been parked, the engine parks it again on every following
request. Each turn writes the full snapshot to host RAM,
drop_superseded()deletes thecopy written one turn earlier, and the K/V retention that would reduce the write to the new
suffix never engages. Measured over 1,418 successful parks in one server log:
Every figure is counted over the same window of one server log (
strata-iq3_xxs.log, up toand including the park at line 80035; the server restarted right after, which is why the whole
log holds 19 more parks). The counters, so the numbers can be re-derived rather than taken on
trust:
The refusal classes are counted separately, because they say different things: 1,766 physical-RAM
admission in the window, 185 because the snapshot exceeded the cache budget, 6 and 3 after capture
for the RAM floor. The 1,989 refusals over the whole log are therefore not 325 - the 325 are the
subset that quotes measured free RAM.
Three consecutive snapshots in one turn differed by 6,152 bytes out of 2.4856 GB
(0.0002 %). A growth gate cuts the per-benchmark volume to 3.26 GB (-66.7 %) and removes the
superseded class entirely; the measurement is below and a cleaned-up version of the same
gate is in #2265.
Note the cost class: this is host-RAM churn plus PCIe/memcpy time, not SSD I/O.
--conversation-cache-mibis documented as a RAM budget ("RAM budget for parkedconversations"), and each
ConversationBufferis "a list of 16 MiB segments, each segment itsown allocation", so no filesystem is in the path. That makes it a plausible contributor to
swap pressure.
Environment
a0116b27(v0.1.43.1, currentorigin/main), nvcc 13.4.92, arch 120Config, identical in every arm:
Single long agentic conversation, 100k-185k tokens. No switching between conversations is
required - this reproduces with one conversation only.
Root cause
src/program/generate.cpp, the park decision (line 10445 ata0116b27):The trigger is
!from_live, notincoming. Parking does setincomingfor the nextrequest, but a probe compiled into the binary shows it is 0 on every turn and that
!from_liveis the sub-condition that fires:That measurement is the finding; what follows is my reading of it, offered as the likely
mechanism rather than as something I proved.
from_liveis set only wherelive_ok && starts_with(live, live_imgs)holds (line 10378), and the checkpoint loop right after itresets it:
So once the live state is gone - and a park leaves the session "in between" until the request
finishes - the next request arrives with
from_live=0and parks again. The park triggersthe next park. Which of the two paths above clears it is worth a maintainer's look; I only
know the condition holds every turn.
Two findings compound it:
The K/V retention can never apply. The documented rule is that the estimate is
"the snapshot's estimated size, less the K/V it already retains":
but in this path
retainedis ~1 MiB against a 3,113 MiB estimate, and the log confirmsit:
need 3112 MiBfor asnapshot_bytes=3264196896(3,113 MiB) snapshot, withreused_kv_bytes=0on every event.reusecomes fromconversations.take_reuse(), butreuse_is only ever filled byconversations.retain(...)inside the restore block(
generate.cpp:10542). In the same window the cache parks 1,418 times and restores 355, so onmost turns no restore happens,
retain()is never reached, andtake_reuse()correctly hasnothing to hand back. The empty credit is a consequence of the park/restore ratio, not of
the order of two statements inside the park path.
The memory guard refuses exactly when it would help. Parking needs host RAM to
serialise into, so under pressure it declines:
So the case parking exists for - RAM too tight - is the case where it cannot run, and the
case where it does run produces a snapshot that is discarded next turn.
One caveat on that 325: it is the subset of refusals that quotes measured free RAM. The
remaining 1,441 refusals in the same window print
telemetry unavailableinstead - the samerefusal, but with no measurement behind it, so for those the log does not record whether the
snapshot would have fitted. The 325 are what the log can prove; the refusal rate itself is
1,960 in this window.
Reproduction
Parked tokens: 100821 -> 100820 -> 100819. Size spread across the three: 6,152 bytes.
Reuse: 0, 0, 0.
The gate
A conversation that advanced by a few hundred tokens since its last park is not worth a 3 GB
copy that the next turn deletes: the stored entry still holds this conversation's prefix, and
a conversation only appends, so it stays usable for the reuse it was made for.
PR (linked below) turns that into
--conversation-cache-park-gain N, default 0 = park everyturn, the current behaviour, so nothing changes until it is asked for. What I measured on my
rig is the same gate as an env switch (
STRATA_PARK_RESUMED) with the threshold hard-coded at32,768 tokens; the pull request makes the threshold a flag and leaves the default off.
Measurement protocol
Single patched binary, switched by env only - no rebuild between arms. Same config, same
prompt (158,113 tokens), 5 generations of 256 tokens, medians from the server's own log line.
Park figures counted over the log line range of each arm.
The remaining 3.26 GB is the first park of the conversation, which is a real state change
and should stay.
The decode difference is -3.4 % and is not significant: it is inside the run-to-run spread
(92.2-124.1 tok/s in the same arm). The expert-cache hit rate is unchanged (91.5 % vs 91.3 %),
so keeping the K/V resident in VRAM does not cost cache hits here. I do not claim a decode
win; the claim is the removed copy volume and the eliminated superseded class.
Quality verification
Two tests, both on the gated build:
repetition.
"vierzehntausendneunhundert", Rostock, Axolotl,
y = 3x + 7), then four filler turns togrow the context, then all five queried again: 5/5 recalled correctly, no repetition,
K/V intact. This is the test that matters for a change on the snapshot path, because a
broken restore shows up as a lost early fact, not as nonsense in a single answer.
Suggested upstream fix
Rate-limit parking by growth. The gate in the linked pull request. A conversation that
advanced a few hundred tokens since its last park does not need a fresh 3 GB copy.
Do not spend a park on a conversation you are not going to restore. Counting the two line
types over the same window gives 1,418 successful parks against 355 restores - four parks
per restore. (Both numbers are counted from the log lines, not printed by the engine: its own
per-event lines carry the counters,
parked=%zuon the park line andrestored %lld tokenson the restore line.)This is why
reused_kv_bytesis always 0, and it is not an ordering problem:conversations.retain(...)(which fillsreuse_) sits inside the restoreblock at
generate.cpp:10542, guarded byincominghaving been successfully taken. Sincethe benchmark conversation is never restored,
retain()never runs,reuse_stays empty,and
take_reuse()correctly returns nothing - there is nothing to retain. Reorderingdrop_superseded()andtake_reuse()would change nothing:take_reuse()reads what aprevious restore retained, not what the cache still holds. The empty
retainedis asymptom of the park/restore ratio, not a sequencing defect.
Make the live-state invalidation explicit. Whatever marks the live state unusable after
a park should also record that this conversation was just parked, so the next turn does not
re-enter the same branch. A flag like "parked this conversation, it is the one being
continued" is cheap and directly breaks the loop.
Report both halves in the log. The park line prints
snapshot_bytesbut not the bytesthis call wrote, and the refusal line prints
needwithoutretained. With the currentoutput there is no way to tell that the documented K/V credit never applies.
Consider the default. The pull request ships the gate with default 0, which changes
nothing. The measurement above is for one rig; whether the gate should be on by default is
your call, and it is the only question the numbers there really open.
Impact
On a long single-conversation workload this is the largest steady-state cost I measured
outside the model itself: 2.25 TB of host copy traffic for a 4.7 % hit rate, 25.8 minutes of
copy time on the request path, and 1-2 s added to the front of many turns. It also churns
~3.3 GB of host allocations per turn inside a WSL VM whose budget is already tight (47 GB of
weights in a 54 GB cap), which is a plausible contributor to the swap pressure I hit separately
on this rig.
Not a reproduction of the earlier reports
Distinct from the conversation-cache parking admission note reported earlier from this rig.
That one is about the refusal path under a cgroup /
--memory-limit-mibcap, where parkingis declined. This is the accept path: parking succeeds, writes gigabytes, and the result is
superseded on the next turn without ever being reused.
Reporter
Krypto-Whitehat- RTX 5090 Laptop (24 GiB), Core Ultra 9 275HX, 64 GiB, WSL2 Ubuntu 24.04,engine built from source (nvcc 13.4.92, arch 120). Qwen3.8-Flash-Next IQ3_XXS, 262,144-token
context. All figures from one server log (
strata-iq3_xxs.log, 1,418 successful parks in thecounted window) plus two A/B arms on the same binary. Earlier report from this rig: #954
(fused/ring hang - still open:
the cause was traced to the 0.1.39 fused layout, the overflow behind it fixed in 0.1.40, and
the #958 backstop landed in 0.1.40.2), and the conversation-cache parking admission note.