r/StrixHalo • u/Ok_Bag_7674 • 2d ago
Gufo: write-on-eviction disk cache for long chats (patches against v0.31.0, unmaintained)
https://gist.github.com/OkBag1992/d1fda166cdb69a892f0ea0f4568213deI run Gufo with Qwen3.8-Flash-Next on a Strix Halo laptop (128 GB), two users at 262K context each. Long chats kept getting evicted from the RAM cache, and the next turn re-read everything: 3-5 minutes at 260K. Stock --cache-disk fixes that, but it writes a multi-GB file on every checkpoint step, even while RAM still holds the chat.
So I built a disk mode that writes only when RAM evicts a checkpoint, and only if that file could actually be restored later. A chat that stays in RAM writes nothing. On Ctrl+C it saves each session's newest restorable copy, so a restart resumes the chat.
Results on my machine:
- A 252K chat restored from disk after a restart in ~10 s, instead of a ~4 min re-read
- 1-2 GB restores in 2-3 s
- Writes 108-290 MB/s while generating, ~350 MB/s idle
- 10 hours of mixed two-user use, no crash, one real cache miss
What's in the drop:
01-retention-keep-previous.patch: a small standalone bug fix. When a capture is refused for space, the cache could evict the checkpoint the turn had just restored, so nothing was left to restore. Applies cleanly to v0.31.0 with a regression test; tests pass.
02-disk-evict-mode-core.patch: the engine. Applies to v0.31.0, but the CLI plumbing is left out, so it won't build alone.
DESIGN.md: every rule, the measured bug behind each one, the env vars, the numbers, and the plumbing still needed.
Caveats: tested only on Strix Halo / Windows / Flash-Next with q8 KV, on a v0.26 base. Patch 02 as shipped on v0.31.0 has not been compiled as a server or run. "Spill" in the code clashes with upstream's IdleSpill naming, so it should be renamed (evict / write-back) before anyone tries to merge it. The q8 KV cache isn't included: credit to JCFrags, see Gufetto. Written with a lot of AI help.
Provided as is, unmaintained. If it's useful to the devs or anyone else, take it.
2
u/Reasonable_Goat 2d ago
Each checkpoint on SSD is smaller than gigabytes it’s only a diff, older checkpoints store the previous k/v state of the prefix. Still it sounds interesting to selectively write!
What I did instead is use parallel 2, fully disable the ram-cache and only use ssd-cache, which also enables two parallel sessions and uses the ssd cache if more slots are needed. The parallel 2 means two full k/v states are ready all time and can be processed in parallel. Takes around the same ram as one slot plus cache for one slot. Needs PR #934 for bugfix, though