Repository navigation
Save the session incrementally instead of rewriting it every turn - #9
Merged
Merged
Conversation
Every end-of-turn save re-serialized and rewrote the whole session file (34 MB on a long session even after #8). Now: - session.json is a full snapshot tagged with a generation id; each later save appends only the changed tail (first changed block onward) to .nexus/session.log. - Each block's saved JSON is cached until the block or one of its items changes (items carry a version, so a change that needs no redaction is still seen). Finding the changed tail is a reference compare. - The log is folded into a fresh snapshot once it outgrows half the snapshot, when most of the snapshot is dead (after /clear), on the first save of a process, or when another Nexus in the folder rewrote the snapshot. Age-based caps are re-applied only on those rewrites, so a block aging out of the recent window is not re-appended every turn. - One loader (boot auto-resume and /resume) replays the log; lines from another generation are skipped and a torn last line ends the replay. Old single-file session.json still loads unchanged. - session.log gets the same owner-only permissions as session.json. On a copy of the long session: per-turn save 140 ms -> 15-20 ms, writing ~8 KB instead of 34 MB; load (snapshot + log) ~200 ms. The first save of a process still writes a full snapshot (~1.1 s on that session). Verified live: resume, two Ollama turns (both went to the log, snapshot untouched), /restart restored both turns. test/session-save.test.js now drives the real save/load code (deltas, edits to older blocks, ephemeral blocks, torn/foreign log lines, compaction, aging, foreign rewrite, legacy files).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Save the session incrementally instead of rewriting it every turn
Every end-of-turn save re-serialized and rewrote the whole session file
(34 MB on a long session even after #8). Now:
save appends only the changed tail (first changed block onward) to
.nexus/session.log.
changes (items carry a version, so a change that needs no redaction is
still seen). Finding the changed tail is a reference compare.
snapshot, when most of the snapshot is dead (after /clear), on the
first save of a process, or when another Nexus in the folder rewrote the
snapshot. Age-based caps are re-applied only on those rewrites, so a
block aging out of the recent window is not re-appended every turn.
another generation are skipped and a torn last line ends the replay.
Old single-file session.json still loads unchanged.
On a copy of the long session: per-turn save 140 ms -> 15-20 ms, writing
~8 KB instead of 34 MB; load (snapshot + log) ~200 ms. The first save of
a process still writes a full snapshot (~1.1 s on that session).
Verified live: resume, two Ollama turns (both went to the log, snapshot
untouched), /restart restored both turns. test/session-save.test.js now
drives the real save/load code (deltas, edits to older blocks, ephemeral
blocks, torn/foreign log lines, compaction, aging, foreign rewrite,
legacy files).