mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3565] [Engine] serve: auto sessions, an opt-in disk parking around a conversation switch #4691
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#4691
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/3565
Author: @drumblund
Created: 10/21/2026
Status: 🔄 Open
Base:
main← Head:serve-auto-sessions📝 Commits (1)
69e254eServe: auto sessions, an opt-in disk parking around a conversation switch📊 Changes
1 file changed (+169 additions, -0 deletions)
View changed files
📝
serve/server.py(+169 -0)📄 Description
Problem and result
The engine has held a saved conversation across restarts for a while:
--slot-save-pathplusPOST /slots/0?action=save|restorewrite and read a session file, andSAVE <path>/RESTORE <path>onthe engine's control stream does the work. What was missing is anything that calls it.
So a single-slot service had exactly one way to survive a conversation switch: the in-RAM cache, bounded by
--conversation-cache-mib. That bound is easy to hit — at 512K a 27k-token conversation parks 651 MB, so a24 GiB ceiling holds roughly thirty of them and then starts evicting. And a restart, or a conversation that
was evicted, pays a full re-read of a prompt that can be minutes of prefill.
After, with
"auto_sessions": true:saved 27,174 tokens (0.65 GB) in 223 ms,restored in 146 msThe restored answer matches the one given before the switch character for character.
Related discussion
none — no issue was opened for this. Off by default (
auto_sessionsis false unless the config saysotherwise), and every failure is logged and leaves the request alone.
Approach
The conversation is identified by its first user message.
conversation_key()takes the text of thefirst
role: usermessage and returnssha1(text)[:16], orNonewhen a request has no user text (atokenize-only call, say) so it stays out of the way. That is the same boundary the engine's prompt cache
sees, so the two agree on what "a different conversation" means.
_auto_session_turn()runs between requests, holding the service FIFO. When the incoming request's keydiffers from the held one: save the held conversation to
auto-<key>.bin(only if it reachedauto_sessions_min_tokens), then restore the incoming one ifauto-<key>.binexists. Same key → nothingbut a token count update. A save that fails does not skip the restore only in one case — a held conversation
with nothing durable, i.e. a cancelled request's provisional state, which the engine refuses as
invalidand which has no file worth protecting.
A failed step never fails the request. The whole body is wrapped:
print(f"[strata] auto sessions: {e}")and the request runs as it always did. In particular, if a save failed, the held conversation is still in
the engine and still parks in RAM — restoring over it would replace a full state with a weaker one.
A normal stop saves what the engine holds (
auto_session_shutdown_save()), but only when the service isidle: a running request's session is live and saving it would capture a partial state.
Pruning touches only its own files.
_auto_session_prune()keeps the newestauto_sessions_keepfilesand at most
auto_sessions_max_gbof them, and deletes only names matchingauto-*.bin— a file saved byhand through
/slots/0is never removed.Defaults, all overridable from the config:
auto_sessions_min_tokens16000,auto_sessions_keep12,auto_sessions_max_gb100.Validation
Passed:
Environment: macOS 26.5.2, M5 Max 128 GB, engine
0.1.44.1-metal, IQ3_S 79 GB, 512K context,--conversation-cache-mib 24576 --conversation-cache-slots 3,slot_save_pathset,auto_sessions_min_tokens20000.auto sessions: saved 27,174 tokens (0.65 GB) to auto-<key>.bin in 223 ms,auto sessions: restored 27,174 tokens from auto-<key>.bin in 146 ms, answer identical.(
cached=26,987of 26,992 prompt tokens).python3 -m py_compile serve/server.pyclean.auto_sessions_min_tokens: logged as skipped, requestunaffected.
Failed: none observed.
Not run:
serve/only and does not depend on the backend, but this machinehas no such hardware.
parallel/--batchsetups:/slots/0and this path are refused there by the pre-existing check, sincea session file could interleave with a request being admitted.
Limits
the same question, a re-rendered template) starts what looks like a new conversation and gets a new file;
one that keeps the text but changes everything after it reuses the old one. That matches what the prompt
cache does, but it is a guess.
--conversation-cache-mibpool is still the fast path; this is what coversa restart and a conversation the pool dropped. Both are worth having.
SAVEfails withinvalid checkpoint running-state payload— the server logs it and the request proceeds. On CUDA the pathalready works. This PR is independent of that one at the source level:
serve/server.pyonly.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.