Repository navigation
perf(core): ingest an appended session tail instead of the whole file - #21
Merged
Merged
Conversation
Ingest session A, then session B, append one message to A, and re-ingest A. The pre-existing search_document ids of A must survive and exactly one row must be added. Today the whole session is deleted and re-inserted, so this fails.
An append re-parsed the whole session file, deleted every row, and inserted them again. Each pause in a running agent's writes cost work in proportion to the whole session, most of it in search_document inserts and their FTS trigger. Each ingest now stores the parser's checkpoint in ingest_state.resume_json (migration 0014). The append path runs when the file grew, its earlier bytes still hash to the last ingest's full_hash, and that ingest ended on a line boundary. The adapter then parses only the new lines from the checkpoint, and ingest inserts only their rows. Lines that refer back resolve against archived rows. A tool result updates its earlier call, and parents and file events find earlier messages and calls. Every other change takes the whole-file path as before. That includes a line that resolves a reference an earlier line left open, and a Codex session_meta line.
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.
Why
A running agent made Lore burn up to a full core. Each append re-parsed the whole session file, deleted every row, and inserted them again, so every pause in the agent's writes cost work in proportion to the whole session. Now an append parses only the new lines and inserts only their rows.
What changed
ParseCheckpoint. A whole-file parse starts from the empty checkpoint. An append starts from the checkpoint the last ingest stored in the newingest_state.resume_jsoncolumn (migration 0014).ingest_filetakes the append path when the earlier bytes still hash to the lastfull_hashand that ingest ended on a line boundary. Lines that refer back to earlier rows resolve against the archive. A tool result updates its earlier call, and parents and file events find earlier messages and calls.stat. An append between the two used to drop the checkpoint.Scope
session_meta.Tradeoffs
Blast Radius
Every ingest path runs through the refactored parsers and row insertion. Whole-file output is unchanged. All existing lore-core tests pass, and new tests compare every append step against a fresh ingest of the same file.
Verification
cargo test -p lore-core --test persist an_append_keeps_existing_search_rows_and_adds_only_the_new_onefails on the test commit (ids[6, 7, 8, 9]against[1, 2, 3, 4]) and passes on head.cargo test -p lore-core --test incremental_ingestgrows Claude Code and Codex sessions line by line, in chunks, and through half-written lines. After every step it compares all session rows with a fresh ingest, ignoring ids and timestamps. The secret case asserts the redacted search text and the finding.