Repository navigation
perf(ai-vault): extend incremental transcript parsing to all append-only JSONL agents (STA-1417) - #7593
Conversation
…nly JSONL agents STA-1278/#7525 added per-file reuse for all agents but incremental append-parsing for Claude only. Agents whose transcripts are large, actively-written JSONL logs — a 2-day orchestrator driving ~20 Cursor agents was the field report (STA-1417) — still fully re-parsed every hot file on each forced ~5s rescan, because the (mtime,size) reuse gate never hits for files being written. Generalize the resume machinery behind a ResumableSessionParseState interface (consumeLine/clone/touchFile/finalize) and convert every parser whose format is an append-only JSONL line-fold: Codex, Cursor, Copilot, Droid, OpenClaw/Pi, and Gemini's JSONL variant, alongside the existing Claude support. Accumulator-only parsers share a generic fold-state helper; Codex gets a bespoke state carrying its usage-delta totals, worker-session rejection (persisted across appends), and a title-source marker so session_index titles that appear after a transcript was first cached still replace the raw first prompt at finalize time (index reads stay signature-cached). Whole-JSON formats (grok/rovo/devin/hermes/gemini-json), Kimi's state+wire pair, and OpenCode (SQLite / doc+message-dir) are structurally non-incremental and keep unchanged-file reuse, documented at the registry. Benchmark (24 hot 6MB codex+cursor transcripts, 10 records appended per file between scans): rescans drop from ~1,450ms CPU each to ~5-7ms (~250x). Differential tests assert cached/incremental output deep-equals a cold parse per agent, including trailing-unterminated-line, truncation-fallback, worker-rejection, and late-index-title cases. The codex session_index reading moved to session-scanner-codex-title-index.ts and addCodexUsage to session-scanner-token-values.ts to keep the parser under the max-lines budget. STA-1417 Co-authored-by: Orca <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughChangesThis PR adds a shared Compact metadata
Related issues: None referenced. Related PRs: None referenced. Suggested labels: refactor, ai-vault, incremental-parsing Suggested reviewers: None specified. Poem A parser walks each line with care, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
src/main/ai-vault/session-scanner-secondary-parsers.ts (1)
68-136: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSolid refactor into resumable state; one minor duplication nit.
consumeCopilotRecordLine,createCopilotSessionResumeState, and the rewiredparseCopilotSessionLinescorrectly follow theaccumulatorFoldResumeState/ResumableSessionParseStatecontract used elsewhere (matchescreateResumableParseState'scase 'copilot'wiring insession-scanner-parse-cache.ts).Minor:
extractString(data.transformedContent) ?? extractString(data.content)is computed twice (title derivation at Line 94 and preview text at Line 98). Hoisting into a local avoids the duplicate work/readability cost.♻️ Optional dedup
if (record.type === 'user.message' && data) { accumulator.messageCount++ - accumulator.title ??= normalizeTitleText( - extractString(data.transformedContent) ?? extractString(data.content) ?? '' - ) - addPreviewMessage(accumulator, { - role: 'user', - text: extractString(data.transformedContent) ?? extractString(data.content), - timestamp: record.timestamp - }) + const userText = extractString(data.transformedContent) ?? extractString(data.content) + accumulator.title ??= normalizeTitleText(userText ?? '') + addPreviewMessage(accumulator, { + role: 'user', + text: userText, + timestamp: record.timestamp + }) return }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: dbd3dd2c-3901-4080-839a-d0ff892cff65
📒 Files selected for processing (13)
src/main/ai-vault/session-scanner-accumulator.tssrc/main/ai-vault/session-scanner-codex-parser.tssrc/main/ai-vault/session-scanner-codex-title-index.tssrc/main/ai-vault/session-scanner-droid-parser.tssrc/main/ai-vault/session-scanner-graph-parsers.tssrc/main/ai-vault/session-scanner-incremental-fixtures.tssrc/main/ai-vault/session-scanner-parse-cache-agents.test.tssrc/main/ai-vault/session-scanner-parse-cache.tssrc/main/ai-vault/session-scanner-primary-parsers.tssrc/main/ai-vault/session-scanner-secondary-parsers.tssrc/main/ai-vault/session-scanner-token-values.tssrc/main/ai-vault/session-scanner-types.tssrc/main/ai-vault/session-scanner-values.ts
…trailing lines Co-authored-by: Orca <[email protected]>
…xtures for max-lines Co-authored-by: Orca <[email protected]>
Brings in 9 commits: deferred remote catalogs at startup (#7087), owner-aware pane title decision gating the Gemini GPU fallback (#7458), incremental transcript parsing for JSONL agents (#7593), gh rate-limit and git-status spawn-churn fixes (#7595), WSL Codex session bridging (#7477), jump-palette subscription gating (#7558), and the IDE font dropdown fix. Conflict resolutions (our structure, main's semantics): - pty-connection.ts onTitleChange: kept this branch's third parameter and stale-derived-title guard (staleWorkingTitleClear must never feed completion tracking), grafted main's resolvePaneTitleDecision so the display label, GPU policy, and observeTitle all ride the owner-aware decision (#7428/#7447). - App.tsx startup: kept this branch's publishTerminalViewAttributesAtAppStart (hidden-at-launch OSC 10/11 replies) ahead of main's restructured local-first startup; dropped this branch's early ui.get() overlap — main's #7087 now awaits ui.get at effectively the same point, making it redundant. Gates: typecheck clean; 4298 tests across src/main/ipc, src/main/daemon, terminal-pane, pane-manager. The delivery path (ipc/pty.ts, dispatcher, scheduler, snapshots) had no conflicts and no incoming changes. Co-authored-by: Orca <[email protected]>
…nly JSONL agents (STA-1417) (stablyai#7593) Co-authored-by: Orca <[email protected]>
Problem
#7525 (STA-1278) fixed the main-process CPU peg by adding per-file reuse for all agents plus incremental append-parsing for Claude transcripts only. Agents whose transcripts are large, actively-written JSONL logs still fully re-parse every hot file on each forced ~5s rescan — the
(mtime,size)reuse gate never hits for a file that's being written.Field evidence (STA-1417, from Discord): a 2-day Fable orchestrator driving ~20 Cursor agents through a large refactor — "perf with long running threads is still painful", and the orchestration can't be restarted to work around it. N concurrently-hot transcripts breaks #7525's "it's only one file" trade-off assumption: 20 growing Cursor/Codex files ≈ the original peg magnitude.
Fix
Generalize #7525's resume machinery behind a
ResumableSessionParseStateinterface (consumeLine/clone/touchFile/finalize) and convert every parser whose on-disk format is an append-only JSONL line-fold:The exclusions are documented at the registry (
createResumableParseState). All resume guards from #7525 apply unchanged: truncation (size < offset) and rewrite (non-\nbyte at the resume point) fall back to a full parse; a trailing unterminated line is shown but re-read once complete.Codex title subtlety preserved: Codex names threads lazily in
session_index.jsonl. The index lookup moved from session_meta-consume time to finalize time (it can't live inside a resumable sync fold), and runs on every finalize with the existing signature-cached index read — so a thread name that appears after the transcript was first cached still replaces the raw first-prompt title, exactly matching full-re-parse behavior. Covered by a dedicated test.Two mechanical moves to stay under the max-lines budget: codex
session_indexreading →session-scanner-codex-title-index.ts;addCodexUsage→session-scanner-token-values.tsbesidesubtractCodexUsage.Evidence
Benchmark modeling the field report — 24 hot 6MB transcripts (12 Codex rollouts + 12 Cursor agent-transcripts), 10 records appended to every file between scans:
Before-numbers scale linearly with transcript size (2-day sessions are far larger than 6MB); after-numbers stay flat.
Correctness: table-driven differential tests per converted agent assert cached, incremental, and truncation-fallback outputs deep-equal a cold parse of the same bytes, plus trailing-unterminated-line no-double-count, Codex worker-session rejection across appends, Codex late-index-title pickup, and a reuse-only regression test (grok). Full
src/main/ai-vaultsuite: 18 files / 99 tests pass; typecheck + oxlint clean.Trade-offs
Same profile as #7525, now applied to more agents — no new classes of risk:
Closes STA-1417 (parented under STA-1278).
Made with Orca 🐋
Validation
review-coderounds: round 1 clean (2 nits, both addressed in7a1b4f270— lazy factory gate so steady-state resumes never allocate throwaway state; per-agent mid-write truncated-trailing-line test); round 2 fully clean with a ship recommendation. Round 2 independently verified the append-only classification for all 7 converted formats (Orca never writes/truncates these transcripts), codex title precedence, clone/finalize aliasing discipline, and remote-path isolation.session-scanner-parse-cache-agents.test.ts+ full ai-vault suite green; typecheck + oxlint clean.incrementalin the trace stats — telemetry inaccuracy only, output still deep-equals a cold parse.