[PR #1529] [CLOSED] serve: the conversation disk tier writes in the background, keeps the root checkpoint, takes what RAM cannot hold (on #1480) #3510

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

📋 Pull Request Information

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

Base: main ← Head: conv-disk-tier


📝 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 (+2534 additions, -98 deletions)

View changed files

📝 CMakeLists.txt (+6 -1)
📝 docs/DETAILS.md (+107 -4)
📝 include/strata/core/conversation_cache.hpp (+138 -16)
📝 include/strata/core/conversation_file.hpp (+28 -0)
📝 include/strata/core/conversation_snapshot.hpp (+30 -0)
➕ include/strata/core/conversation_spill.hpp (+151 -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 (+470 -0)
➕ src/core/conversation_spill_test.cpp (+428 -0)
📝 src/core/conversation_state.cpp (+17 -2)
📝 src/program/generate.cpp (+600 -26)

📄 Description

Builds on #1480 by @routhjim, which stacks #1271 by @ANBAL534 and #1269 by @pspranger-throw. This branch sits on #1480's current head (8c0a5af, on v0.1.41) with their commits unchanged; mine are the three on top (d9beea0 and 86ec596 for the code, 42cb955 for the numbers in DETAILS.md). If #1480 lands first, this rebases down to those three.

I had a similar disk tier running locally for a while. When I compared it with yours, the session-file base and the streamed save and restore were better than mine, so I moved the parts of mine that still helped onto your branch instead of opening a competing PR.

What changes

  • Evictions are written in the background. When the RAM cache evicts a conversation, the image goes to a writer thread (spill_async). Before, it was written and flushed inside the request that caused the eviction. The writer thread only calls session_file_write, and the index is only touched on the main thread: wait() joins the write and indexes the file. This happens before a disk match, before a streamed save, and at shutdown, so a file is never matched before it is complete. A failed write removes its file.
  • A spilled file keeps two checkpoints. It keeps the deepest one, as SAVE does, and the shallowest one, the root of the chain. The root is usually the end of the system prompt, which is what a new chat or a subagent resumes from. The checkpoints in between only serve edits further back. Dropping them halves the file.
  • What RAM cannot hold goes to disk instead of being dropped. With the RAM cache on, a conversation that cannot be parked (it is over the budget, or the physical-RAM admission refuses it) is streamed to the directory the way --conversation-cache-disk-only writes it. A disk hit larger than the RAM budget is streamed back the way that mode reads it. This applies on one GPU, without --batch or --peer-device, like disk-only.
  • Fixes along the way.
    • put() called make_room without the spill callback. An image larger than its estimate could evict conversations that were then lost. They now go to the disk tier too, and so does an image put() refuses.
    • If the RAM admission refuses a park or a disk hit while a background write is still holding an evicted image, the request waits for that write and checks again.
    • A disk hit within the RAM budget used to be refused outright when make_room could not free the room or the physical-RAM admission said no, so the request fell back to a prefix or a full read. It is streamed back now. I hit this on my own box: a 166K-token conversation came back with only its 46K prefix and re-read 122K tokens (99 s).
    • The physical-RAM eviction loop from 940011d stays. Since an evicted image now goes to the writer thread and stays in RAM until it is written, the park waits for that write before it gives up.
  • --conversation-cache-disk-min-tokens N (default 0, off). Conversations shorter than N are not written.
  • Free-space floor. Every spill write keeps --session-min-free-mib free, as SAVE does.

With the defaults and the RAM cache off, behaviour is the same as #1480.

Measured

Measured after the rebase onto v0.1.41: #1480 at 8c0a5af against this branch at 86ec596, same machine, same flags.

Setup. RTX 2080 Ti 22 GB, i5-12490F, 62 GB RAM, Ubuntu, NVMe. Swift 1.5 IQ3_S, --kv int8 --kv-resident 32768 --spec 4 --mtp.

Workload. Three agent-style conversations take turns with --conversation-cache-slots 1. They share a system prompt; each first prompt is about 16K tokens, and each later turn adds about 2.2K. There are 3 rounds, an engine restart (SIGTERM), then 2 more rounds. Decoding is greedy with 24 output tokens. The table shows prompt-read time for the 12 later turns.

median range turns resumed shutdown
#1480, --conversation-cache-mib 4096 4.95 s 4.62-6.19 s 12 / 12 4.0 s
this PR, --conversation-cache-mib 4096 4.45 s 4.30-6.25 s 12 / 12 3.7 s
#1480, --conversation-cache-mib 256 14.24 s 10.69-22.59 s 0 / 12 3.1 s
this PR, --conversation-cache-mib 256 4.89 s 4.70-6.57 s 12 / 12 3.3 s
  • Background writes. A write took 0.32-0.56 s, and a request waited 0.4-10.4 ms for it. Only a shutdown waited longer (up to 0.46 s), for the write still in flight.
  • File size. Once a conversation had more than one checkpoint, a spilled file was 603-699 MiB, against 1149-1618 MiB with every checkpoint.
  • 256 MiB budget. Nothing fits in RAM there. On #1480 those conversations are dropped. Here a streamed save took 0.37-0.68 s and a streamed restore 0.59-0.97 s (read pass 0.27-0.50 s).
  • Shutdown. Every shutdown, including writing out the RAM cache, took under 5 s, so serve/server.py's 10 s wait before it kills the engine was never reached.

Tests. conversation_spill_test has 34 new checks of mine; on the rebased branch all 107 pass (93 before the rebase, also under ThreadSanitizer). The checks cover the background write, the index waiting for it, branching at the root, put() evicting through the callback, waiting in the destructor, and refusal on the free-space floor. The other conversation tests pass. Before the rebase it also built on Windows (CUDA 12.6, VS 2022) with the tests passing there; I've been running it on a 2080 Ti and a 3080 since.

Not included

  • Mirroring every turn to disk (#1331). A clean shutdown already writes the RAM cache out. A crash costs one prompt re-read, so I didn't think several times the IO was worth it.
  • No-MTP save and restore. That is #1492. The disk tier still needs the MTP drafter loaded, like SAVE/RESTORE.

The discussion in #1331 (@shahrokhzargarpour) and #1489 (@CC-David-CC) also helped shape this. Thanks to all of you. Happy to rebase or split it differently if that suits the stack better.

🤖 Generated with Claude Code


🔄 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/1529 **Author:** [@konijiwa110](https://github.com/konijiwa110) **Created:** 10/8/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `conv-disk-tier` --- ### 📝 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** (+2534 additions, -98 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+6 -1) 📝 `docs/DETAILS.md` (+107 -4) 📝 `include/strata/core/conversation_cache.hpp` (+138 -16) 📝 `include/strata/core/conversation_file.hpp` (+28 -0) 📝 `include/strata/core/conversation_snapshot.hpp` (+30 -0) ➕ `include/strata/core/conversation_spill.hpp` (+151 -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` (+470 -0) ➕ `src/core/conversation_spill_test.cpp` (+428 -0) 📝 `src/core/conversation_state.cpp` (+17 -2) 📝 `src/program/generate.cpp` (+600 -26) </details> ### 📄 Description Builds on #1480 by @routhjim, which stacks #1271 by @ANBAL534 and #1269 by @pspranger-throw. This branch sits on #1480's current head (8c0a5af, on v0.1.41) with their commits unchanged; mine are the three on top (d9beea0 and 86ec596 for the code, 42cb955 for the numbers in DETAILS.md). If #1480 lands first, this rebases down to those three. I had a similar disk tier running locally for a while. When I compared it with yours, the session-file base and the streamed save and restore were better than mine, so I moved the parts of mine that still helped onto your branch instead of opening a competing PR. ## What changes - **Evictions are written in the background.** When the RAM cache evicts a conversation, the image goes to a writer thread (`spill_async`). Before, it was written and flushed inside the request that caused the eviction. The writer thread only calls `session_file_write`, and the index is only touched on the main thread: `wait()` joins the write and indexes the file. This happens before a disk match, before a streamed save, and at shutdown, so a file is never matched before it is complete. A failed write removes its file. - **A spilled file keeps two checkpoints.** It keeps the deepest one, as SAVE does, and the shallowest one, the root of the chain. The root is usually the end of the system prompt, which is what a new chat or a subagent resumes from. The checkpoints in between only serve edits further back. Dropping them halves the file. - **What RAM cannot hold goes to disk instead of being dropped.** With the RAM cache on, a conversation that cannot be parked (it is over the budget, or the physical-RAM admission refuses it) is streamed to the directory the way `--conversation-cache-disk-only` writes it. A disk hit larger than the RAM budget is streamed back the way that mode reads it. This applies on one GPU, without `--batch` or `--peer-device`, like disk-only. - **Fixes along the way.** - `put()` called `make_room` without the spill callback. An image larger than its estimate could evict conversations that were then lost. They now go to the disk tier too, and so does an image `put()` refuses. - If the RAM admission refuses a park or a disk hit while a background write is still holding an evicted image, the request waits for that write and checks again. - A disk hit within the RAM budget used to be refused outright when `make_room` could not free the room or the physical-RAM admission said no, so the request fell back to a prefix or a full read. It is streamed back now. I hit this on my own box: a 166K-token conversation came back with only its 46K prefix and re-read 122K tokens (99 s). - The physical-RAM eviction loop from 940011d stays. Since an evicted image now goes to the writer thread and stays in RAM until it is written, the park waits for that write before it gives up. - **`--conversation-cache-disk-min-tokens N`** (default 0, off). Conversations shorter than N are not written. - **Free-space floor.** Every spill write keeps `--session-min-free-mib` free, as SAVE does. With the defaults and the RAM cache off, behaviour is the same as #1480. ## Measured Measured after the rebase onto v0.1.41: #1480 at 8c0a5af against this branch at 86ec596, same machine, same flags. **Setup.** RTX 2080 Ti 22 GB, i5-12490F, 62 GB RAM, Ubuntu, NVMe. Swift 1.5 IQ3_S, `--kv int8 --kv-resident 32768 --spec 4 --mtp`. **Workload.** Three agent-style conversations take turns with `--conversation-cache-slots 1`. They share a system prompt; each first prompt is about 16K tokens, and each later turn adds about 2.2K. There are 3 rounds, an engine restart (SIGTERM), then 2 more rounds. Decoding is greedy with 24 output tokens. The table shows prompt-read time for the 12 later turns. | | median | range | turns resumed | shutdown | |---|---:|---:|---:|---:| | #1480, `--conversation-cache-mib 4096` | 4.95 s | 4.62-6.19 s | 12 / 12 | 4.0 s | | this PR, `--conversation-cache-mib 4096` | 4.45 s | 4.30-6.25 s | 12 / 12 | 3.7 s | | #1480, `--conversation-cache-mib 256` | 14.24 s | 10.69-22.59 s | 0 / 12 | 3.1 s | | this PR, `--conversation-cache-mib 256` | 4.89 s | 4.70-6.57 s | 12 / 12 | 3.3 s | - **Background writes.** A write took 0.32-0.56 s, and a request waited 0.4-10.4 ms for it. Only a shutdown waited longer (up to 0.46 s), for the write still in flight. - **File size.** Once a conversation had more than one checkpoint, a spilled file was 603-699 MiB, against 1149-1618 MiB with every checkpoint. - **256 MiB budget.** Nothing fits in RAM there. On #1480 those conversations are dropped. Here a streamed save took 0.37-0.68 s and a streamed restore 0.59-0.97 s (read pass 0.27-0.50 s). - **Shutdown.** Every shutdown, including writing out the RAM cache, took under 5 s, so `serve/server.py`'s 10 s wait before it kills the engine was never reached. **Tests.** `conversation_spill_test` has 34 new checks of mine; on the rebased branch all 107 pass (93 before the rebase, also under ThreadSanitizer). The checks cover the background write, the index waiting for it, branching at the root, `put()` evicting through the callback, waiting in the destructor, and refusal on the free-space floor. The other conversation tests pass. Before the rebase it also built on Windows (CUDA 12.6, VS 2022) with the tests passing there; I've been running it on a 2080 Ti and a 3080 since. ## Not included - **Mirroring every turn to disk (#1331).** A clean shutdown already writes the RAM cache out. A crash costs one prompt re-read, so I didn't think several times the IO was worth it. - **No-MTP save and restore.** That is #1492. The disk tier still needs the MTP drafter loaded, like SAVE/RESTORE. The discussion in #1331 (@shahrokhzargarpour) and #1489 (@CC-David-CC) also helped shape this. Thanks to all of you. Happy to rebase or split it differently if that suits the stack better. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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:59 +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#3510
No description provided.