[PR #1480] [CLOSED] serve: --conversation-cache-disk-only - the conversation cache on disk, with no RAM budget (depends on #1271, #1269) #3480

Closed
opened 2026-11-07 14:41:46 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1480
Author: @routhjim
Created: 10/8/2026
Status: ❌ Closed

Base: main ← Head: disk-only-cache


📝 Commits (10+)

  • 34e2409 serve: keep evicted conversations on disk across restarts
  • d258f18 serve: restore a session file without holding its K/V in RAM
  • 0d846c1 Merge remote-tracking branch 'upstream/main' into conversation-spill-disk
  • 1904b8a serve: recompute the RAM conversation match after a failed disk attempt: make_room may have evicted the entry the stale index named
  • 1a9e8b9 Merge remote-tracking branch 'upstream/main' into conversation-spill-disk
  • 3a5daf6 Merge branch 'pr-1269' into disk-only-cache
  • dd146f4 serve: --conversation-cache-disk-only - the conversation cache on disk, no RAM budget
  • b189048 conversation_spill_test: disk-only checks; docs: --conversation-cache-disk-only, measured on Strix Halo
  • ff30368 docs: --conversation-cache-disk-only restores measured from a cold page cache
  • 2987ac4 serve: disk-only cache keeps each conversation's root as a persistent prefix entry

📊 Changes

17 files changed (+2221 additions, -93 deletions)

View changed files

📝 CMakeLists.txt (+4 -1)
📝 docs/DETAILS.md (+78 -4)
📝 include/strata/core/conversation_cache.hpp (+131 -15)
📝 include/strata/core/conversation_file.hpp (+28 -0)
📝 include/strata/core/conversation_snapshot.hpp (+30 -0)
➕ include/strata/core/conversation_spill.hpp (+114 -0)
📝 serve/server.py (+55 -2)
📝 serve/test_monitor.py (+44 -0)
📝 serve/web/app.js (+28 -1)
📝 serve/web/index.html (+4 -0)
📝 src/core/conversation_file.cpp (+227 -32)
📝 src/core/conversation_file_test.cpp (+122 -0)
📝 src/core/conversation_snapshot.cpp (+79 -14)
➕ src/core/conversation_spill.cpp (+392 -0)
➕ src/core/conversation_spill_test.cpp (+331 -0)
📝 src/core/conversation_state.cpp (+17 -2)
📝 src/program/generate.cpp (+537 -22)

📄 Description

Stacked on #1271 (spill directory) and #1269 (streaming restore). The branch is #1271 (at 4af468f, which brings in v0.1.41) with #1269 (at d258f18) merged in. Only the last eight commits are new:

  • dd146f4: the mode;
  • b189048: tests and docs;
  • ff30368: the cold-page-cache numbers in the docs;
  • 2987ac4, a040357, 9eac670: persistent prefix entries (below), with tests and docs.
  • 83ad1c5, 155dd84: from @ed-hch's CUDA test: a refused disk read keeps its file, and the monitor card shows the disk tier.

I will rebase once those two land, or fold this into #1271 if its author prefers.

#1271 keeps the conversations the RAM cache evicts on disk. A conversation reaches disk only through a RAM eviction (make_room), so the RAM budget still decides what is kept. On a machine where the expert cache takes nearly all memory (Strix Halo: 72 GiB of experts in 128 GB), the conversation cache needs that budget most and can afford it least.

--conversation-cache-disk-only, with --conversation-cache-spill-dir, keeps the conversation cache on disk only:

  • When a request switches to another conversation, the outgoing one is written to the directory the way a session SAVE writes it. The running state and the deepest checkpoint are copied; the K/V streams from its pools into the file (conversation_snapshot_sources + the streaming session_file_write). No host image is made.
  • When a conversation comes back, it is read the way #1269's RESTORE reads it. The read pass checks the whole file before anything on the GPU changes; a bad file is dropped, and the prompt is read as usual. Then the apply pass writes the pools 16 MiB at a time, with RESTORE's fail-stop after the first block.
  • --conversation-cache-mib is not used. --conversation-cache-disk-mib is the only limit, so no conversation is refused for its size. A read or save still checks free RAM for its transient buffers (one checkpoint's running state and two 16 MiB blocks) against --conversation-cache-min-free-mib. When that refuses, the file is kept for a later turn.
  • v0.1.41's RAM-admission eviction (#1347) is on the RAM parking path; disk-only mode never reaches it.
  • The new file is written before this conversation's older copies are dropped. drop_superseded gains a keep path, because its rule alone would drop the new copy too. A failed write loses nothing.
  • The agent's next turn of the live conversation writes nothing. It resumes at the newest turn checkpoint, and the outgoing tail is only the reply the client sends again.
  • A clean shutdown saves the live conversation, flushed. Switch saves skip the flushes: a file torn by a crash fails the payload hash when it is read and is dropped.
  • Single GPU, without --batch or --peer-device; otherwise the flag says so and is off.

Where it helps. A coding agent run as several sessions on one local engine: Claude Code through an Anthropic-compatible proxy, or a manager such as Happier that starts sessions from a phone. Each session is a long conversation (20-120K tokens), and they alternate. With one GPU and no RAM to spare, every switch read the whole conversation again. One real Claude Code session of 121K tokens took 181 s to read and 2.0 s to restore from disk. A new session started from a 13K-token preamble that is the same every time, and read all of it.

Prefix entries. When a conversation is saved, its shared opening is also saved on its own as strata-conv-prefix-N, once per distinct opening. The opening is the deepest "strata_prefix" checkpoint on the live path when the request pinned one. Otherwise it is the root by the engine's rule: the first turn boundary at least --prompt-cache-root tokens in. A new conversation that opens the same way resumes from it.

  • Prefix entries are never removed as superseded. The disk budget evicts every ordinary conversation before one of them. A restart keeps them as prefixes, and has_prefix dedupes them.
  • The sidecar format is unchanged; the kind is in the file name.
  • In disk-only mode a request that resumes at a pinned prefix is another conversation, so the one it leaves is saved. The RAM cache's skip ("N queries cost one prefix") would drop it.

Measured with real Claude Code sessions. The client marks "strata_prefix" after Claude Code's leading <system-reminder> blocks, so the system prompt, tools and reminders form the shared part.

first turn of a new session prompt read reused
without prefix entries 15.7 s 4,350 tokens
with them 4.7 s 13,434 of 15,924
with them, after an engine restart 5.1 s 13,434 (the 420 MiB entry restored in 326 ms)

The rest of each first turn is the user's own message and a per-session block, so it has to be read.

Why this matters beyond the budget. With #1271 as it is, a conversation larger than the free RAM budget is neither parked nor spilled:

skip parking (snapshot 1292 MiB exceeds available budget)

If its disk copy was restored a turn earlier, that copy was already removed as superseded, so the conversation is gone, and its next turn reads 15,954 tokens from the start (18.9 s, in the run below). The long conversations are the ones that gain the most from a disk tier. Disk-only mode never asks the RAM budget.

Measured on a Ryzen AI Max+ 395 (Radeon 8060S, gfx1151, 128 GB, Linux 7.2, ROCm 7.14.1, the iGPU alone).

  • Build: per docs/STRIX_HALO.md.
  • Model and flags: Qwen3.8-Flash-Next with K-quant experts, --mmap-experts --expert-cache auto --spec 4 --mtp mtp/rt --lookup-chain 3 --kv int8 --max-context 65536. Spill directory on the internal NVMe.
  • Workload: three agent-style conversations taking turns (A1 B1 C1 A2 ...). Each is a 9-12K-token first prompt, then turns that each add ~1.1K tokens of source text. Greedy, 64 output tokens. 3 rounds, an engine restart, then 2 more rounds.
  • Reuse and prompt time come from the /metrics totals around each request.
prompt read, later turns (12) turns resumed
no conversation cache 11.4-22.3 s, nothing reused 0 of 12
#1271, --conversation-cache-mib 2048 --conversation-cache-slots 1 2.4-3.0 s, 88-94% reused 11 of 12 (the one above lost)
this PR, --conversation-cache-disk-only 2.3-3.6 s, 88-94% reused 12 of 12
  • A switch wrote 360-443 MiB in 181-196 ms. A return read it back in 291-351 ms, of which the read pass was ~150 ms.
  • Cold disk: the same run again, with every spill file pushed out of the page cache before each request (fsync, then posix_fadvise(DONTNEED); fincore showed 0 bytes resident each time). Restores took 275-361 ms (read pass 128-162 ms), and all 12 later turns resumed with the same 88-94% reuse.
  • The files are smaller than #1271's parked images (1.0-1.4 GB) because only the deepest checkpoint is saved, as SAVE already does. Three conversations took 1.3 GB on disk.
  • Process memory (RssAnon, sampled every 0.1 s) peaked 0.6 GiB above a run without the cache during a switch, and ended 0.15 GiB above it. No conversation stays in RAM.
  • Greedy replies matched the run without the cache for 13 of 15 turns. The other two (the first turn after the restart, and the turn after it) are identical to #1271's replies for the same turns: a restore and a full read of the prompt round differently.

Tests. conversation_spill_test: 32 new checks, 73 pass. test_monitor: 2 new tests, 12 pass.

  • A streamed spill writes byte for byte the file the image spill writes, matches and reads back with the same K/V.
  • It refuses a host K/V image or an empty conversation.
  • A failing source leaves no file and no index entry.
  • drop_superseded spares the keep copy, while the rule alone would drop it.
  • Prefix entries: named as prefixes, kept by drop_superseded, evicted last, deduped, and still prefixes after a reopen.

The engine paths were run end to end as above.

Not tested:

  • CUDA (no NVIDIA card here) and Windows;
  • --kv-grow: the restore calls kvg_ensure as the RAM restore does, but I did not run it with elastic K/V.

Measured with the help of Claude (Anthropic).

🤖 Generated with Claude Code

https://claude.ai/code/session_013XBY17SSRKGmDXc2YFsrmp


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1480 **Author:** [@routhjim](https://github.com/routhjim) **Created:** 10/8/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `disk-only-cache` --- ### 📝 Commits (10+) - [`34e2409`](https://github.com/Niko1221/Strata/commit/34e24094a2214eaa14cde6a08cebc36f62926c18) serve: keep evicted conversations on disk across restarts - [`d258f18`](https://github.com/Niko1221/Strata/commit/d258f18920daf7c85a1c5fe407bf907d1fb9639a) serve: restore a session file without holding its K/V in RAM - [`0d846c1`](https://github.com/Niko1221/Strata/commit/0d846c168fa6f400d409574507c5bcd32b6771ee) Merge remote-tracking branch 'upstream/main' into conversation-spill-disk - [`1904b8a`](https://github.com/Niko1221/Strata/commit/1904b8abf542bc3c8177d8d18a22aea5da3d49c2) serve: recompute the RAM conversation match after a failed disk attempt: make_room may have evicted the entry the stale index named - [`1a9e8b9`](https://github.com/Niko1221/Strata/commit/1a9e8b95a185cfa3939bb3fdf1d5487411dd229f) Merge remote-tracking branch 'upstream/main' into conversation-spill-disk - [`3a5daf6`](https://github.com/Niko1221/Strata/commit/3a5daf640d68576876767e5926ed25e9b9e5629b) Merge branch 'pr-1269' into disk-only-cache - [`dd146f4`](https://github.com/Niko1221/Strata/commit/dd146f495534f950847ba8dfff93d9ec9d9712d2) serve: --conversation-cache-disk-only - the conversation cache on disk, no RAM budget - [`b189048`](https://github.com/Niko1221/Strata/commit/b18904801395080df9a5c42190dd5f227200b974) conversation_spill_test: disk-only checks; docs: --conversation-cache-disk-only, measured on Strix Halo - [`ff30368`](https://github.com/Niko1221/Strata/commit/ff30368e4f7ecf0e315d1b2fd7e05cc9bdbf5a75) docs: --conversation-cache-disk-only restores measured from a cold page cache - [`2987ac4`](https://github.com/Niko1221/Strata/commit/2987ac4307543db2b674c6d438ad9377281d5bc8) serve: disk-only cache keeps each conversation's root as a persistent prefix entry ### 📊 Changes **17 files changed** (+2221 additions, -93 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+4 -1) 📝 `docs/DETAILS.md` (+78 -4) 📝 `include/strata/core/conversation_cache.hpp` (+131 -15) 📝 `include/strata/core/conversation_file.hpp` (+28 -0) 📝 `include/strata/core/conversation_snapshot.hpp` (+30 -0) ➕ `include/strata/core/conversation_spill.hpp` (+114 -0) 📝 `serve/server.py` (+55 -2) 📝 `serve/test_monitor.py` (+44 -0) 📝 `serve/web/app.js` (+28 -1) 📝 `serve/web/index.html` (+4 -0) 📝 `src/core/conversation_file.cpp` (+227 -32) 📝 `src/core/conversation_file_test.cpp` (+122 -0) 📝 `src/core/conversation_snapshot.cpp` (+79 -14) ➕ `src/core/conversation_spill.cpp` (+392 -0) ➕ `src/core/conversation_spill_test.cpp` (+331 -0) 📝 `src/core/conversation_state.cpp` (+17 -2) 📝 `src/program/generate.cpp` (+537 -22) </details> ### 📄 Description **Stacked on #1271 (spill directory) and #1269 (streaming restore).** The branch is #1271 (at 4af468f, which brings in v0.1.41) with #1269 (at d258f18) merged in. Only the last eight commits are new: - dd146f4: the mode; - b189048: tests and docs; - ff30368: the cold-page-cache numbers in the docs; - 2987ac4, a040357, 9eac670: persistent prefix entries (below), with tests and docs. - 83ad1c5, 155dd84: from @ed-hch's CUDA test: a refused disk read keeps its file, and the monitor card shows the disk tier. I will rebase once those two land, or fold this into #1271 if its author prefers. #1271 keeps the conversations the RAM cache evicts on disk. A conversation reaches disk only through a RAM eviction (`make_room`), so the RAM budget still decides what is kept. On a machine where the expert cache takes nearly all memory (Strix Halo: 72 GiB of experts in 128 GB), the conversation cache needs that budget most and can afford it least. `--conversation-cache-disk-only`, with `--conversation-cache-spill-dir`, keeps the conversation cache on disk only: - When a request switches to another conversation, the outgoing one is written to the directory the way a session SAVE writes it. The running state and the deepest checkpoint are copied; the K/V streams from its pools into the file (`conversation_snapshot_sources` + the streaming `session_file_write`). No host image is made. - When a conversation comes back, it is read the way #1269's RESTORE reads it. The read pass checks the whole file before anything on the GPU changes; a bad file is dropped, and the prompt is read as usual. Then the apply pass writes the pools 16 MiB at a time, with RESTORE's fail-stop after the first block. - `--conversation-cache-mib` is not used. `--conversation-cache-disk-mib` is the only limit, so no conversation is refused for its size. A read or save still checks free RAM for its transient buffers (one checkpoint's running state and two 16 MiB blocks) against `--conversation-cache-min-free-mib`. When that refuses, the file is kept for a later turn. - v0.1.41's RAM-admission eviction (#1347) is on the RAM parking path; disk-only mode never reaches it. - The new file is written before this conversation's older copies are dropped. `drop_superseded` gains a `keep` path, because its rule alone would drop the new copy too. A failed write loses nothing. - The agent's next turn of the live conversation writes nothing. It resumes at the newest turn checkpoint, and the outgoing tail is only the reply the client sends again. - A clean shutdown saves the live conversation, flushed. Switch saves skip the flushes: a file torn by a crash fails the payload hash when it is read and is dropped. - Single GPU, without `--batch` or `--peer-device`; otherwise the flag says so and is off. **Where it helps.** A coding agent run as several sessions on one local engine: Claude Code through an Anthropic-compatible proxy, or a manager such as Happier that starts sessions from a phone. Each session is a long conversation (20-120K tokens), and they alternate. With one GPU and no RAM to spare, every switch read the whole conversation again. One real Claude Code session of 121K tokens took 181 s to read and 2.0 s to restore from disk. A new session started from a 13K-token preamble that is the same every time, and read all of it. **Prefix entries.** When a conversation is saved, its shared opening is also saved on its own as `strata-conv-prefix-N`, once per distinct opening. The opening is the deepest `"strata_prefix"` checkpoint on the live path when the request pinned one. Otherwise it is the root by the engine's rule: the first turn boundary at least `--prompt-cache-root` tokens in. A new conversation that opens the same way resumes from it. - Prefix entries are never removed as superseded. The disk budget evicts every ordinary conversation before one of them. A restart keeps them as prefixes, and `has_prefix` dedupes them. - The sidecar format is unchanged; the kind is in the file name. - In disk-only mode a request that resumes at a pinned prefix is another conversation, so the one it leaves is saved. The RAM cache's skip ("N queries cost one prefix") would drop it. Measured with real Claude Code sessions. The client marks `"strata_prefix"` after Claude Code's leading `<system-reminder>` blocks, so the system prompt, tools and reminders form the shared part. | first turn of a new session | prompt read | reused | |---|---:|---:| | without prefix entries | 15.7 s | 4,350 tokens | | with them | **4.7 s** | **13,434 of 15,924** | | with them, after an engine restart | **5.1 s** | **13,434** (the 420 MiB entry restored in 326 ms) | The rest of each first turn is the user's own message and a per-session block, so it has to be read. **Why this matters beyond the budget.** With #1271 as it is, a conversation larger than the free RAM budget is neither parked nor spilled: ``` skip parking (snapshot 1292 MiB exceeds available budget) ``` If its disk copy was restored a turn earlier, that copy was already removed as superseded, so the conversation is gone, and its next turn reads 15,954 tokens from the start (18.9 s, in the run below). The long conversations are the ones that gain the most from a disk tier. Disk-only mode never asks the RAM budget. **Measured** on a Ryzen AI Max+ 395 (Radeon 8060S, gfx1151, 128 GB, Linux 7.2, ROCm 7.14.1, the iGPU alone). - Build: per `docs/STRIX_HALO.md`. - Model and flags: Qwen3.8-Flash-Next with K-quant experts, `--mmap-experts --expert-cache auto --spec 4 --mtp mtp/rt --lookup-chain 3 --kv int8 --max-context 65536`. Spill directory on the internal NVMe. - Workload: three agent-style conversations taking turns (A1 B1 C1 A2 ...). Each is a 9-12K-token first prompt, then turns that each add ~1.1K tokens of source text. Greedy, 64 output tokens. 3 rounds, an engine restart, then 2 more rounds. - Reuse and prompt time come from the `/metrics` totals around each request. | | prompt read, later turns (12) | turns resumed | |---|---:|---:| | no conversation cache | 11.4-22.3 s, nothing reused | 0 of 12 | | #1271, `--conversation-cache-mib 2048 --conversation-cache-slots 1` | 2.4-3.0 s, 88-94% reused | 11 of 12 (the one above lost) | | **this PR, `--conversation-cache-disk-only`** | **2.3-3.6 s, 88-94% reused** | **12 of 12** | - A switch wrote 360-443 MiB in 181-196 ms. A return read it back in 291-351 ms, of which the read pass was ~150 ms. - Cold disk: the same run again, with every spill file pushed out of the page cache before each request (`fsync`, then `posix_fadvise(DONTNEED)`; `fincore` showed 0 bytes resident each time). Restores took 275-361 ms (read pass 128-162 ms), and all 12 later turns resumed with the same 88-94% reuse. - The files are smaller than #1271's parked images (1.0-1.4 GB) because only the deepest checkpoint is saved, as SAVE already does. Three conversations took 1.3 GB on disk. - Process memory (`RssAnon`, sampled every 0.1 s) peaked 0.6 GiB above a run without the cache during a switch, and ended 0.15 GiB above it. No conversation stays in RAM. - Greedy replies matched the run without the cache for 13 of 15 turns. The other two (the first turn after the restart, and the turn after it) are identical to #1271's replies for the same turns: a restore and a full read of the prompt round differently. **Tests.** `conversation_spill_test`: 32 new checks, 73 pass. `test_monitor`: 2 new tests, 12 pass. - A streamed spill writes byte for byte the file the image spill writes, matches and reads back with the same K/V. - It refuses a host K/V image or an empty conversation. - A failing source leaves no file and no index entry. - `drop_superseded` spares the `keep` copy, while the rule alone would drop it. - Prefix entries: named as prefixes, kept by `drop_superseded`, evicted last, deduped, and still prefixes after a reopen. The engine paths were run end to end as above. **Not tested:** - CUDA (no NVIDIA card here) and Windows; - `--kv-grow`: the restore calls `kvg_ensure` as the RAM restore does, but I did not run it with elastic K/V. Measured with the help of Claude (Anthropic). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_013XBY17SSRKGmDXc2YFsrmp --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:41:46 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3480
No description provided.