Skip to content

perf(ai-vault): extend incremental transcript parsing to all append-only JSONL agents (STA-1417) - #7593

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/sta-1417-incremental-parsers
Jul 6, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/sta-1417-incremental-parsers

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

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 ResumableSessionParseState interface (consumeLine/clone/touchFile/finalize) and convert every parser whose on-disk format is an append-only JSONL line-fold:

Agent Status Notes
Claude already incremental (#7525) adapted to the shared interface
Codex now incremental bespoke state: usage-delta totals, worker-session rejection persists across appends, title-source marker
Cursor now incremental the field-report workload
Copilot, Droid, OpenClaw, Pi, Gemini (.jsonl) now incremental share a generic accumulator-fold state
Grok, Rovo, Devin, Hermes, Gemini (.json) reuse-only whole-JSON docs rewritten in place — structurally non-incremental
Kimi reuse-only state.json + sibling wire file (multi-file)
OpenCode reuse-only SQLite rows / legacy doc + message dir

The exclusions are documented at the registry (createResumableParseState). All resume guards from #7525 apply unchanged: truncation (size < offset) and rewrite (non-\n byte 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_index reading → session-scanner-codex-title-index.ts; addCodexUsage → session-scanner-token-values.ts beside subtractCodexUsage.

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:

Scan Before (#7525 baseline) After
Cold ~1,660ms CPU ~1,560ms CPU (unchanged, expected)
Each rescan, all 24 files growing ~1,450ms CPU ~5–7ms CPU (~250×)

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-vault suite: 18 files / 99 tests pass; typecheck + oxlint clean.

Trade-offs

Same profile as #7525, now applied to more agents — no new classes of risk:

  • The append-only assumption now covers Codex/Cursor/Copilot/Droid/OpenClaw/Pi/Gemini-jsonl logs; all are event-log formats written by append. The rewrite guards make the worst case a stale vault row until restart, not corruption.
  • Cache memory per entry is unchanged (bounded accumulator + ≤5 capped previews + small per-agent extras); entry count cap (4096) unchanged.
  • Non-JSONL formats intentionally keep reuse-only caching; converting them is structurally impossible (in-place rewrites) rather than deferred work.

Closes STA-1417 (parented under STA-1278).

Made with Orca 🐋

Validation

  • Two independent Opus 4.8 adversarial review-code rounds: round 1 clean (2 nits, both addressed in 7a1b4f270 — 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.
  • 21 differential tests in session-scanner-parse-cache-agents.test.ts + full ai-vault suite green; typecheck + oxlint clean.
  • Known residual (cosmetic, from round 2): a file whose first parse sees only an unterminated partial line stores byteOffset 0, so its next scan re-reads from 0 while counting as incremental in the trace stats — telemetry inaccuracy only, output still deep-equals a cold parse.

…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]>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5f763aa4-0de6-453d-9a70-fb68eeb67dce

📥 Commits

Reviewing files that changed from the base of the PR and between 7a1b4f2 and 668b634.

📒 Files selected for processing (3)
  • src/main/ai-vault/session-scanner-codex-fixtures.ts
  • src/main/ai-vault/session-scanner-incremental-fixtures.ts
  • src/main/ai-vault/session-scanner-parse-cache-agents.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/ai-vault/session-scanner-parse-cache-agents.test.ts

📝 Walkthrough

Walkthrough

Changes

This PR adds a shared ResumableSessionParseState contract, refactors multiple session parsers to use resumable line consumers, and generalizes parse-cache resume handling across agents. Codex title lookup is moved into a separate cached module that reads session_index.jsonl. The PR also adds accumulator cloning, Codex token usage summation, incremental fixture generators, and tests for incremental cache behavior, truncation, and Codex-specific resume cases.

Compact metadata

  • Type: Refactor + feature
  • Scope: src/main/ai-vault/ session scanner modules
  • Estimated review effort: High

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,
Clones the state and keeps it there,
Titles rise from index streams,
Caches resume trailing dreams.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is substantive, but it misses the required template sections and the testing, AI review, security, and notes details. Rewrite it in the required template with Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes, including cross-platform review details.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: extending incremental transcript parsing to more append-only JSONL agents.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/main/ai-vault/session-scanner-secondary-parsers.ts (1)

68-136: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Solid refactor into resumable state; one minor duplication nit.

consumeCopilotRecordLine, createCopilotSessionResumeState, and the rewired parseCopilotSessionLines correctly follow the accumulatorFoldResumeState/ResumableSessionParseState contract used elsewhere (matches createResumableParseState's case 'copilot' wiring in session-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

📥 Commits

Reviewing files that changed from the base of the PR and between 47feae3 and e3ff3e5.

📒 Files selected for processing (13)
  • src/main/ai-vault/session-scanner-accumulator.ts
  • src/main/ai-vault/session-scanner-codex-parser.ts
  • src/main/ai-vault/session-scanner-codex-title-index.ts
  • src/main/ai-vault/session-scanner-droid-parser.ts
  • src/main/ai-vault/session-scanner-graph-parsers.ts
  • src/main/ai-vault/session-scanner-incremental-fixtures.ts
  • src/main/ai-vault/session-scanner-parse-cache-agents.test.ts
  • src/main/ai-vault/session-scanner-parse-cache.ts
  • src/main/ai-vault/session-scanner-primary-parsers.ts
  • src/main/ai-vault/session-scanner-secondary-parsers.ts
  • src/main/ai-vault/session-scanner-token-values.ts
  • src/main/ai-vault/session-scanner-types.ts
  • src/main/ai-vault/session-scanner-values.ts

@brennanb2025
brennanb2025 merged commit 16439fd into main Jul 6, 2026
1 check passed
Jinwoo-H added a commit that referenced this pull request Jul 6, 2026
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]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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