mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #661] Proposal: save and restore a conversation to disk (/slots/0?action=save|restore) #307
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#307
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?
Originally created by @maverde73 on GitHub (Oct 3, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/661
Proposal
Let the engine write the conversation it holds (what a parked conversation snapshot already holds) to one file and
read it back later, also after a restart of the same engine version with the same model and settings. This
implements llama-server-compatible save and restore requests and response fields for Strata's single slot, slot 0;
the feature is opt-in through
--slot-save-path DIR(or"slot_save_path"in the config):It is not complete
/slotssupport (no erase, no other slots) and the file format is Strata's own, not llama.cpp's.Underneath,
strata --servetakes two new stdin lines between requests:SAVE <path>andRESTORE <path>.Why
With a long conversation the first turn after a restart reads the whole prompt again: about 26 s at 63K tokens on
an RTX 4070 Ti. After the model is loaded, restoring the saved state took 0.97 s in the run below, and the next
32-token turn took 1.14 s. Engine startup itself still takes about 70-95 s. Useful for:
POST /unload, a scheduled restart) without losing the context.Files require the same engine version, model inputs and compatible settings: a file written by another engine
version is refused, not misread (same-version rebuilds are not identified by a build hash). It is the same idea as v0.1.36's
--expert-profile-save(#477),which keeps the learned expert profile across restarts; this keeps the conversation.
Measured
RTX 4070 Ti 12 GB, Ryzen 9 5900X, 64 GB RAM, NVMe (ext4), Linux, v0.1.38, IQ3_XXS with the setup's config, a
62,993-token prompt + 32 generated tokens (63,025 tokens held),
--max-context 65536:The turn after the restore produced the same 32 token IDs as the same next turn without a restart (this compares
two warm paths, not a claim of equality with one uninterrupted generation). A symbolic link, a second hard link, a
file with one flipped byte and a file restored by an engine with another RoPE base were refused, and the engine kept
serving after each refusal.
This saves conversation state, not all process-local execution history, so exact token replay across restarts is
not guaranteed: expert residency and CPU/GPU rounding can change later output. In the same 63K test the first
32-token continuation matched the process that stayed running; on the next continuation three restored processes
agreed with one another but differed from that process from the 28th token on. A refused corrupted restore in
between did not change the restored continuation. The cause of this divergence has not been isolated.
With the feature unused there was no measurable prefill, decode or peak-VRAM regression
in three alternating pairs at 3.4K, 29.6K and 63K, with identical output token IDs in all nine pairs.
Design (short)
conversation's length and the draft layer's K/V.
header hash), payload, payload hash, end marker. Written to a new, exclusively created temporary file, flushed,
renamed over the target and the folder flushed (POSIX). A failure before the rename keeps the old file; a failed
folder flush after it is reported as such (the new file is already in place).
validation (size, header, both fingerprints, a RAM preflight, geometry and layer range, every count against the
bytes left and the session's exact limits, the
payload hash, the snapshot validation) complete before any device write; a rejection keeps the active session. A
device-transfer failure after that point ends the engine, which the server restarts.
pack's own files, every expert file as the loader resolved it per layer and role, the MTP files); the config fingerprint covers the engine version, backend, KV settings, context,
the resolved RoPE configuration, a digest of the loaded control vectors and the arithmetic switches.
Limits
--layer-splitand with--peer-device.--prompt-cache> 0; the separate RAM parked-conversation cache need not be on.Origin, the server's own ora trusted one, also when an API key is set.
Tested on
CreateFileWwithCREATE_NEW, no-follow open,FlushFileBuffers,MoveFileExW). Its CPU file-I/O unit test passed as a 32-bit Windows executable built with zig 0.16 (clang,x86-windows-gnu) under Wine 10.0; this is not a Windows engine or GPU validation. Not built with MSVC, not run onreal Windows, Unicode model paths and large files not tested there.
hip_compatmaps. Not builtor run with
STRATA_ENABLE_HIP=ON.If you are on Windows or AMD and would like to try it, a run of the unit test and one save/restore of a long chat
would help a lot. I have a branch ready on top of v0.1.38 and will open a PR shortly; two robustness items are still being finished
there (the RAM preflight of a save runs before its first copy, and progress lines cover small saves and the
flush phases).
@maverde73 commented on GitHub (Oct 4, 2026):
The implementation is now up as #668 (on top of v0.1.38, the two robustness items above included, with tests and the 63K measurements). Happy to adjust it to how you prefer it.
@Niko1221 commented on GitHub (Oct 7, 2026):
Shipped in 0.1.40: session files save and restore a conversation to disk (SAVE and RESTORE between requests, with the checks added in review). Closing; please open a new issue for anything that is missing from the llama-server /slots behaviour you wanted.
@maverde73 commented on GitHub (Oct 7, 2026):
Thanks for reviewing and shipping it, and for the robustness checks added in review. Our proxy (mnemonic-proxy) uses session files for autosave and restore; our measurements so far are on the 0.1.38 + #668 build, and I'll re-run them on 0.1.40. Nothing missing on our side for now; if we need
eraseor more slots later, I'll open a new issue.@dandandelion commented on GitHub (Oct 12, 2026):
This question might be noobie but how do you properly use this? Does new sessions in harnesses/chat UIs automatically saves/reuses matching session caches saved?
@maverde73 commented on GitHub (Oct 12, 2026):
Not a noob question. No, it isn't automatic. Session files are an API, and nothing calls it on its own:
Start Strata with --slot-save-path DIR (or "slot_save_path" in the config).
Something has to call save and restore explicitly:
bash
curl -X POST "http://127.0.0.1:8080/slots/0?action=save" -H "Content-Type: application/json" -d '{"filename": "chat1.bin"}'
curl -X POST "http://127.0.0.1:8080/slots/0?action=restore" -H "Content-Type: application/json" -d '{"filename": "chat1.bin"}'
After a restore, keep sending the same messages as before. The client always sends the full history. When it matches the restored conversation, Strata reuses the state and only reads the new part.
Typical harnesses and chat UIs (Cline, Pi, Open WebUI...) don't call /slots, so they won't save or reuse anything on their own. You also have to keep track yourself of which file belongs to which conversation. Files are tied to the same engine version, model and settings. Nothing deletes them, and they're about 1.2 GB per 63K tokens. Details: docs/DETAILS.md, section "Session files (disk)".
Disclosure: I wrote the feature and the tool below. If you want it automatic, mnemonic-proxy sits between your harness and Strata. It saves the conversation to disk and, when you come back to it, restores the matching file before forwarding the request. That covers a restart, or another chat having used the engine in between. Your harness doesn't need to know anything about it. It's free and MIT-licensed. You don't need it if you only ever have one chat and never restart the engine: Strata already keeps the live conversation in memory.