mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1937] [Engine] serve: parked conversations on the disk, optionally across restarts (--conversation-disk-dir, --conversation-disk-persist) #3765
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#3765
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?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1937
Author: @xrip
Created: 10/11/2026
Status: 🔄 Open
Base:
main← Head:pr/conversation-disk-tier📝 Commits (2)
65a79b5serve: parked conversations on the disk, optionally across restarts (--conversation-disk-dir, --conversation-disk-persist)c6b9997conversation disk: read a file back only when that is faster than reading the tokens it adds📊 Changes
10 files changed (+1304 additions, -31 deletions)
View changed files
📝
CMakeLists.txt(+9 -1)📝
docs/DETAILS.md(+53 -0)📝
include/strata/core/conversation_cache.hpp(+7 -0)➕
include/strata/core/conversation_disk.hpp(+153 -0)📝
metal/CMakeLists.txt(+1 -0)📝
serve/server.py(+4 -1)➕
src/core/conversation_disk.cpp(+575 -0)➕
src/core/conversation_disk_test.cpp(+335 -0)📝
src/program/generate.cpp(+166 -28)📝
sycl/CMakeLists.txt(+1 -1)📄 Description
Problem and result
A conversation the RAM conversation cache evicts (its slots or its byte budget full) is dropped, and a client that comes back to it reads the whole prompt again: an agent that switches between its main conversation and sub-agents too large for the budget together reads ~150K tokens again on every switch. Every restart of the engine (an update, a settings change, a reboot, a poweroff) also reads every conversation from token 0 again.
--conversation-disk-dir DIR: the evicted conversation goes toDIRand comes back from there when a request continues it. With--conversation-disk-persist on|exit-onlythe conversations outlive the engine: the same 165,558-token conversation came back after a restart in 8.4 s, with the same answer.Related discussion
The maintainer said in #1090 that one disk-persistence design will be chosen; this is one of them. It was closed in the 0.2.0-beta reset and is rebased here onto 0.2.1. #3404 (separate, in the conversation cache) drops stale parked copies of a conversation, which the disk tier would otherwise write out.
Approach
Off by default (opt-in options, help text and
docs/DETAILS.md):conversation_disk.hpp/.cpp: the tier. Each image (one per stage with--layer-split) is one session file, written and read with the session files' own code (size, header and hash checks, the free-space preflight). A background writer (nice 10 on Linux) means a switch never waits for the disk, and queued images can be read back from RAM. Every checkpoint is kept, as in RAM.--conversation-disk-mib N(default 32768): oldest out first.conversation_cache.hpp:set_on_evict, so an evicted conversation goes to the tier instead of being dropped. A park that does not fit the cache's byte budget is also sent to the disk.generate.cpp: options, wiring, the read back when the disk holds a longer prefix than the session / a batch slot / the RAM cache (it needs RAM for the whole image above--conversation-cache-min-free-mib, else the prompt is read again), and the request line says when it was reused from the disk.--conversation-disk-persist on|exit-only: the files are bound to the session files' identity (model, engine version, settings), with an index per conversation, so the next start takes them in. Files of another identity are removed at start. On QUIT the engine saves the current conversation and the parked ones; while persist is on it ignores SIGINT/SIGTERM/SIGHUP and ends through its stdin, so a poweroff's SIGTERM does not cut the save short. The server waits up to 300 s for QUIT (serve/server.py, 4 lines).exit-onlywrites nothing while running and saves only at QUIT.not read. Second commit.conversation_disk.cppis added to the CUDA/HIP, SYCL and Metal engine lists (all three compilegenerate.cpp).Compatibility: with no
--conversation-disk-dirnothing is written or read. One change stays in the parking path: before the RAM admission evicts a conversation, it calls glibc'smalloc_trim(0), so freed images count in MemAvailable. Output is unaffected.Validation
Passed:
90767252) as two commits:65a79b51(the tier) andc6b99976(the read check). CUDA build in Docker (nvidia/cuda:13.3.0-devel-ubuntu24.04, GCC 14,-DCMAKE_CUDA_ARCHITECTURES=75 -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=ON -DSTRATA_BUILD_CONVERSATION_TESTS=ON):strataand the tests build;conversation_disk_test69 checks,conversation_cache_test4,772,conversation_file_test201, all pass.python -m pytest -q serve/test_server.py serve/test_parallel.py serve/test_parallel_yield.py serve/test_request_accounting.py: 392 passed, 3 skipped, 444 subtests passed (Windows 11, Python 3.14).342185bd: that is 0.2.0-beta plus this disk tier, plus one diagnostic log line and fork-only serve/tool patches (the disk-tier code is otherwise this commit). Box: 2x CMP 50HX 20 GB (sm_75, layer split), 2x Xeon E5-2670 v2, 64 GB, NVMe ext4, Ubuntu 24.04.4, driver 610.43.03, Flash-Next IQ3_XXS;exit-only,--adapt-swaps 0, greedy, 48 tokens.on(my fork on 0.2.1 with both commits and #3404): a 304,364-token conversation came back from the disk in 47.6 s (5,465 MiB read in 44.1 s, then the restore) and a 286,199-token one in 41.7 s, where reading them takes ~140 s.not read: its 16384 more tokens read in ~9.4 s, its file (2018 MiB) in ~12.5 s. On the NVMe days the same case read whole files: four reads of 4-6 GB for 13,764-16,384 tokens (6,033 MiB in 11.4 s for 16,384 tokens).Failed: the same end-to-end check with adaptive expert swaps on (the live config) gave one restored conversation a different first token. Swaps make decode non-repeatable on this box even without a restore; with
--adapt-swaps 0the check passed (above).Not run:
Limits
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.