[PR #5399] Serve: parked conversations spill to a disk tier instead of being dropped #5415

Open
opened 2026-11-07 16:35:02 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5399
Author: @nrtdadmin
Created: 11/6/2026
Status: 🔄 Open

Base: main ← Head: f-0210-conv-disk-cache


📝 Commits (2)

  • d272ca9 Serve: parked conversations spill to a disk tier instead of being dropped. The parked cache only had RAM: once the --conversation-cache-mib budget or the slot count filled, evict_oldest dropped the oldest conversation and its next request re-read the whole prompt. With --conversation-cache-file-mib > 0 (--conversation-cache-file-dir, default /conv-cache) eviction now writes the heavy parts (K/V pages, running state, checkpoint copies) to /.conv and keeps a RAM shell (ids, images, pinned) so best() still finds it; a returning conversation is read whole back from disk and the file goes. A shell still holds its slot - the count bounds RAM and disk entries together - and leaves for good when it is the oldest and a slot is needed or the disk budget ran out; borrows() refuses a spilled entry, the restore is all-or-nothing, so a half-borrowed K/V never reaches the graph. Enabling the tier wipes the folder: a spill file belongs to the engine that wrote it and a restart starts the cache empty. The serve web monitor gets a "Their storage (disk)" row under "Their memory (RAM)" (server.py counts the folder next to the INFO line, app.js renders usage and spills). Test: conversation_cache_disk_test round-trips a 751 MiB synthetic image (100k tokens, 5 K/V pages, 3 checkpoints, 2 stage images, a buffer crossing the 16 MiB segment edge), byte-identical, refuses a truncated file without crashing, and survives an empty image; live check on a 4-GPU --serve box.
  • f027b79 Serve: budget pressure spills RAM entries before it kills a shell. The eviction loop took the oldest entry whatever it was: with a spilled shell at the head (the common shape once the tier starts working) a conversation returning after the first spill erased its file and left the loop still short of RAM, so every park killed the shell the previous park had just written - the folder held at most one file however much pressure the RAM budget was under, which is the opposite of why the tier exists. The loop body now spills the oldest entry still holding K/V and frees a shell only when nothing else can free RAM (or a slot is needed for a new park, as before). Test: on the 4-GPU box with the RAM cache dialed to 2 GiB and cold conversations arriving one at a time, spilled files now pile up in the folder and a returning conversation reads its K/V back whole and removes the file; before the fix the folder stayed at one file under the same pressure.

📊 Changes

8 files changed (+437 additions, -3 deletions)

View changed files

📝 CMakeLists.txt (+7 -1)
📝 include/strata/core/conversation_cache.hpp (+106 -1)
📝 serve/server.py (+34 -0)
📝 serve/web/app.js (+6 -0)
📝 serve/web/index.html (+2 -0)
➕ src/core/conversation_cache_disk.cpp (+150 -0)
➕ src/core/conversation_cache_disk_test.cpp (+105 -0)
📝 src/program/generate.cpp (+27 -1)

📄 Description

Why

The parked-conversation cache only had RAM: once --conversation-cache-mib or the slot count filled, evict_oldest() dropped the oldest conversation, and its next request re-read the entire prompt. On our 4x V100 serving box (long multi-hundred-KB prompts) that re-read is the expensive part, and the eviction happened exactly when memory was under pressure.

What

With --conversation-cache-file-mib > 0 (new, plus --conversation-cache-file-dir, default <pack>/conv-cache), eviction now spills: the heavy parts (K/V pages, running state, checkpoint copies) go to <dir>/<serial>.conv and a small RAM shell (ids, images, pinned) stays so best() matching still finds the conversation. A returning conversation is read whole back from disk and the file goes.

  • A shell still holds one of slots - the slot count bounds RAM and disk entries together; when a slot is needed and the oldest entry is already on disk it leaves for good (its file goes), same when the disk budget is exhausted.
  • borrows() refuses a spilled entry - the restore is all-or-nothing, a half-borrowed K/V never reaches the graph.
  • Reads run through the existing conversation_snapshot_validate gate; a half-written file (crash between write and rename - the write is tmp + rename) is refused, not trusted.
  • Enabling the tier wipes the folder: a spill file belongs to the engine that wrote it and a restart starts the cache empty, so leftovers would never be read.
  • 0 (the default) is upstream behavior, byte-for-byte: eviction drops.
  • The serve web monitor gets a "Their storage (disk)" row under "Their memory (RAM)" showing usage/spilled count (server.py counts the folder named in the engine INFO line; app.js renders it; the row hides when the tier is off).

Test

  • New conversation_cache_disk_test (registered in the STRATA_BUILD_TESTS block): round-trips a 751 MiB synthetic parked image - 100k tokens, 5 K/V pages, 3 checkpoints, 2 stage images, a buffer crossing the 16 MiB segment edge - byte-identical read-back, refuses a truncated file without crashing, and survives an empty image.
  • Also ran under ASan+UBSan standalone: no OOB, no UB.
  • Live on the owner's 4-GPU (Volta sm_70, CUDA 12) --serve box for a day: normal serving, monitor row renders, spills restore correctly.

Built and tested by the owner's ops agent (hence the ops@wlwxai.local commit author). Happy to re-run anything on request.


🔄 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/5399 **Author:** [@nrtdadmin](https://github.com/nrtdadmin) **Created:** 11/6/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `f-0210-conv-disk-cache` --- ### 📝 Commits (2) - [`d272ca9`](https://github.com/Niko1221/Strata/commit/d272ca9f4d6da410dc18ba33990a1a1003daab99) Serve: parked conversations spill to a disk tier instead of being dropped. The parked cache only had RAM: once the --conversation-cache-mib budget or the slot count filled, evict_oldest dropped the oldest conversation and its next request re-read the whole prompt. With --conversation-cache-file-mib > 0 (--conversation-cache-file-dir, default <pack>/conv-cache) eviction now writes the heavy parts (K/V pages, running state, checkpoint copies) to <dir>/<serial>.conv and keeps a RAM shell (ids, images, pinned) so best() still finds it; a returning conversation is read whole back from disk and the file goes. A shell still holds its slot - the count bounds RAM and disk entries together - and leaves for good when it is the oldest and a slot is needed or the disk budget ran out; borrows() refuses a spilled entry, the restore is all-or-nothing, so a half-borrowed K/V never reaches the graph. Enabling the tier wipes the folder: a spill file belongs to the engine that wrote it and a restart starts the cache empty. The serve web monitor gets a "Their storage (disk)" row under "Their memory (RAM)" (server.py counts the folder next to the INFO line, app.js renders usage and spills). Test: conversation_cache_disk_test round-trips a 751 MiB synthetic image (100k tokens, 5 K/V pages, 3 checkpoints, 2 stage images, a buffer crossing the 16 MiB segment edge), byte-identical, refuses a truncated file without crashing, and survives an empty image; live check on a 4-GPU --serve box. - [`f027b79`](https://github.com/Niko1221/Strata/commit/f027b79f9cd58f42fa22811ca9aef9e8a1af160c) Serve: budget pressure spills RAM entries before it kills a shell. The eviction loop took the oldest entry whatever it was: with a spilled shell at the head (the common shape once the tier starts working) a conversation returning after the first spill erased its file and left the loop still short of RAM, so every park killed the shell the previous park had just written - the folder held at most one file however much pressure the RAM budget was under, which is the opposite of why the tier exists. The loop body now spills the oldest entry still holding K/V and frees a shell only when nothing else can free RAM (or a slot is needed for a new park, as before). Test: on the 4-GPU box with the RAM cache dialed to 2 GiB and cold conversations arriving one at a time, spilled files now pile up in the folder and a returning conversation reads its K/V back whole and removes the file; before the fix the folder stayed at one file under the same pressure. ### 📊 Changes **8 files changed** (+437 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+7 -1) 📝 `include/strata/core/conversation_cache.hpp` (+106 -1) 📝 `serve/server.py` (+34 -0) 📝 `serve/web/app.js` (+6 -0) 📝 `serve/web/index.html` (+2 -0) ➕ `src/core/conversation_cache_disk.cpp` (+150 -0) ➕ `src/core/conversation_cache_disk_test.cpp` (+105 -0) 📝 `src/program/generate.cpp` (+27 -1) </details> ### 📄 Description ## Why The parked-conversation cache only had RAM: once `--conversation-cache-mib` or the slot count filled, `evict_oldest()` **dropped** the oldest conversation, and its next request re-read the entire prompt. On our 4x V100 serving box (long multi-hundred-KB prompts) that re-read is the expensive part, and the eviction happened exactly when memory was under pressure. ## What With `--conversation-cache-file-mib > 0` (new, plus `--conversation-cache-file-dir`, default `<pack>/conv-cache`), eviction now **spills**: the heavy parts (K/V pages, running state, checkpoint copies) go to `<dir>/<serial>.conv` and a small RAM shell (ids, images, pinned) stays so `best()` matching still finds the conversation. A returning conversation is read whole back from disk and the file goes. - A shell still holds one of `slots` - the slot count bounds RAM and disk entries together; when a slot is needed and the oldest entry is already on disk it leaves for good (its file goes), same when the disk budget is exhausted. - `borrows()` refuses a spilled entry - the restore is all-or-nothing, a half-borrowed K/V never reaches the graph. - Reads run through the existing `conversation_snapshot_validate` gate; a half-written file (crash between write and rename - the write is `tmp` + rename) is refused, not trusted. - Enabling the tier wipes the folder: a spill file belongs to the engine that wrote it and a restart starts the cache empty, so leftovers would never be read. - `0` (the default) is upstream behavior, byte-for-byte: eviction drops. - The serve web monitor gets a "Their storage (disk)" row under "Their memory (RAM)" showing usage/spilled count (`server.py` counts the folder named in the engine INFO line; `app.js` renders it; the row hides when the tier is off). ## Test - New `conversation_cache_disk_test` (registered in the `STRATA_BUILD_TESTS` block): round-trips a 751 MiB synthetic parked image - 100k tokens, 5 K/V pages, 3 checkpoints, 2 stage images, a buffer crossing the 16 MiB segment edge - byte-identical read-back, refuses a truncated file without crashing, and survives an empty image. - Also ran under ASan+UBSan standalone: no OOB, no UB. - Live on the owner's 4-GPU (Volta sm_70, CUDA 12) `--serve` box for a day: normal serving, monitor row renders, spills restore correctly. *Built and tested by the owner's ops agent (hence the `ops@wlwxai.local` commit author). Happy to re-run anything on request.* --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#5415
No description provided.