mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5211] [Other] Serve: session_autosave, the conversation cache's L2 on disk #5346
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#5346
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/5211
Author: @Flo5k5
Created: 11/4/2026
Status: 🔄 Open
Base:
main← Head:session-autosave📝 Commits (1)
3a64710Serve: session_autosave, the conversation cache's L2 on disk📊 Changes
3 files changed (+318 additions, -0 deletions)
View changed files
📝
serve/server.py(+83 -0)➕
serve/session_persist.py(+85 -0)➕
serve/test_session_persist.py(+150 -0)📄 Description
Problem and result
A resumed conversation re-reads its whole prompt. On our M5 Pro 64 GB with Gyro-M (TQ2_0, expert-cache 24576), taking a 34K-token conversation back costs ~41 s of prompt reading before the first token. The conversation cache (#596) parks finished conversations in RAM and reuses them when the next prompt shares their tokens, but RAM evictions drop exactly the conversations a long session still needs, and nothing survives a server restart.
/slots/0?action=save|restorealready moves one whole session to or from disk by hand; the engine parks conversations by itself.With this change (opt-in), each finished turn's conversation is saved to
slot_save_pathautomatically, and a later prompt that begins with a saved conversation restores it before the request: the engine reads only the tokens past it - the resumed 34K conversation reads its new turn, not its history.Related discussion
Context on our setup and the 64 GB fit: #5176 (the issue where the host-side improvements this belongs to were outlined). Maintainer's agreement on scope: not yet - this is a draft to settle the open questions below before anything is finalized.
Approach
The engine's two existing halves are joined with no engine change:
auto-<digest>.bininslot_save_pathand records(len, digest, file, bytes)inindex.json(LRU, capped by"session_persist_max_gb", default 8).The key is the digest of the PROMPT's tokens, not prompt + reply: a chat template renders message by message, so turn n's whole prompt is a prefix of turn n+1's, whatever the reply was. Matching takes the incoming prompt's digest at each recorded length (one sha256 per candidate); the engine's own prefix match absorbs a smaller divergence at the tail (verified on the stock chat template: turn 1's 249 prompt tokens are an exact prefix of turn 2's 299).
Skips: a restore of a conversation the engine already holds (its own prefix match reads nothing then); a save when the live conversation's size is not this turn's prompt plus its reply (another request came in between the turn and the save). A refused or failed save/restore never breaks the request - the prompt is then read in full, as without the option. Off unless
--session-autosave/"session_autosave": true(needsslot_save_pathand an engine with session files).Validation
Passed:
python -m unittest serve.test_session_persist -v- revision3a647107, Python 3.15 on macOS, mock engine (no GPU): 5 tests OK. The turn is saved under its prompt's digest; a prompt continuing the live conversation restores nothing; a returning prompt restores its saved conversation (and only it) after another conversation became the live one; an unrelated prompt restores nothing; the index LRU-trims to its cap and reloads without the dropped file.python -m unittest serve.test_slots- same revision: 30 tests OK (the manual API unchanged).python -m unittest serve.test_server- same revision: 359 tests OK (the option is inert unless enabled).Failed:
Not run:
Limits
Draft on four open questions:
SAVEline is between requests). Between the turn's end and the save, another request may take the FIFO and leave a different conversation live - the size guard skips the save then, but the cleaner place would be inside the last turn's FIFO section. Where would you want it?slot_actionrefuses save/restore under--batch; this keeps the same rule implicitly (one slot). Right call for autosave too?SAVEDreports ~1.2 GB per 63K-token conversation on our model - the LRU cap keeps that sane. Is a delta format (snapshots of the same conversation chain) worth it upstream, or out of scope?The prefix matching assumes the chat template renders message by message (true of the stock template; a template that rewrites earlier turns would not match, and the request then reads its prompt in full - no failure, just no saving).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.