Skip to content

perf(parser): incremental parse of append-grown session files#749

Merged
iamtoruk merged 1 commit into
mainfrom
perf/incremental-append-parse
Jul 18, 2026
Merged

perf(parser): incremental parse of append-grown session files#749
iamtoruk merged 1 commit into
mainfrom
perf/incremental-append-parse

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

CLI half of the desktop-slowness fix: the session cache computed an incremental resume offset for append-grown files (reconcileFileaction: 'appended'), but the parser ignored it and re-parsed from byte 0 — so machines with live agents constantly appending to session JSONL paid a full re-parse of those files on every warm run.

  • The Claude JSONL scan now parses only the bytes past the cached offset and merges with the cached turns: continuation turns merge into the last cached turn, boundary re-emits (same msg.id, or the re-read torn line) collapse to the last occurrence keeping the first timestamp (mergeBoundaryCalls, mirroring dedupeStreamingMessageIds), scan-wide dedup keys are re-seeded so cross-file dedup is unchanged.
  • Defensive guard in reconcileFile: never resume past current EOF (truncate-then-regrow falls back to a full re-parse).
  • No parse-version bump: output is unchanged (only cost), cache shape untouched — a bump would force the very cold re-parse this avoids.

Verified: new integration suite proves the incremental result deep-equals a cold full re-parse (incl. torn-line, inode-change, and offset-beyond-EOF cases) and that the offset path actually activates; full root suite 2178 passed. Real-data check on a 21MB live session file: incremental output byte-identical to cold parse; append-between-runs costs ~0ms extra vs a measurable re-parse penalty before.

@iamtoruk
iamtoruk merged commit 916119d into main Jul 18, 2026
3 checks passed
@iamtoruk
iamtoruk deleted the perf/incremental-append-parse branch July 18, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant