refactor: append-only transcript persistence + fsync batching#13
Closed
yanmxa wants to merge 1 commit into
Closed
Conversation
The session save path previously rewrote the entire JSONL on every Save
via FileStore.Replace, producing O(file_size) writes per turn even though
each turn only adds one or two messages. This commit switches the path
to per-event append:
Store.Save now calls Start (idempotent) + AppendMessage per node
(deduped via an in-memory persistedIDs cache, populated lazily by
scanning the file once) + a single PatchState.
FileStore.Replace, recordsForTranscript, TranscriptFromSnapshot,
ReplaceCommand, and messageExistsLocked are removed — the rewrite
path no longer exists.
Bundled in this commit: fsync is now gated by a `sync` parameter on
appendRecord, batched at turn boundaries:
- sync=true: session.started, message.appended, session.compacted,
inference.responded (the turn-flush point).
- sync=false: state.patched, inference.requested, system.section.*,
tools.* — buffered in the page cache, flushed when the matching
inference.responded lands.
A typical turn now does one fsync instead of five. On crash, the
in-flight turn's telemetry may be lost, but messages and state from
prior turns are durable.
Also exports StateOpsFor + PatchTag/Mode/Worktree helpers so the new
Save path can express the projected state as a single patch list.
1 task
Member
Author
|
Closing — the file-level split produced commits that don't compile standalone. Reopening as a proper hunk-aware re-split. See follow-ups. |
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.
PR 1 of 5 — foundation.
Replaces full-file rewrite (
FileStore.Replace) with per-event append.Store.Savenow callsStart+AppendMessageper node + onePatchState. Old rewrite path deleted.AppendMessagededuped via in-memorypersistedIDscache, populated lazily by scanning the file once. After that, O(1) dedup instead of O(N) per call.appendRecordgains asyncparameter:sync=true:message.appended,session.compacted,session.started,inference.responded(turn flush).sync=false: telemetry — buffered in page cache, ride along on next turn flush.Behavior preserved: existing tests including resume/fork/JSONL integrity continue to pass.
Test
go test ./internal/session/... ./tests/integration/session/... ./tests/integration/cli/...passesTestFileStoreAppendMessageIsIdempotentreplaces the deletedTestFileStoreReplace🤖 Generated with Claude Code