Skip to content

perf(native-chat): coalesce concurrent transcript reads - #8157

Closed
nwparker wants to merge 1 commit into
stablyai:mainfrom
nwparker:nwparker/perf-19
Closed

nwparker wants to merge 1 commit into
stablyai:mainfrom
nwparker:nwparker/perf-19

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Description

Coalesce concurrent cache misses for the same native-chat transcript snapshot. The cache now keys in-flight work by agent, resolved transcript path, mtime, byte size, and cache generation, so simultaneous desktop panes and paired web/mobile clients share one parse while changed files and different worktrees remain isolated.

This also adds:

  • a deterministic regression test proving eight simultaneous callers issue one underlying read;
  • concurrent cross-worktree coverage proving identical session IDs and mtimes do not collide;
  • an opt-in production-boundary benchmark.

Performance evidence

Command:

ORCA_NATIVE_CHAT_PERF_BENCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/native-chat/transcript-read-cache-inflight-cost.bench.test.ts --reporter=verbose

The isolated benchmark sends 8 simultaneous readNativeChatTranscriptCached calls through the real resolver/stat/cache/file-stream/Claude-decoder boundary for one uncached 16 MiB JSONL transcript (5 rounds, median):

Version Median
Before 359.81 ms
After 47.65 ms
Improvement 86.8% faster / 7.55x

The before-state regression test independently confirmed 8 underlying parses; after the fix it confirms exactly 1. This is an isolated concurrent cache-miss benchmark, not end-to-end UI latency.

ELI5

If eight Orca views asked for the same large chat at once, Orca used to photocopy and read the whole book eight separate times. Now the first request reads it and the other seven wait for that same copy, so the work happens once.

End-user trade-offs / regressions

  • No RPC, IPC, persisted-state, route, message-windowing, SSH, filesystem-routing, or provider contract changes.
  • Different agents, files, mtimes, sizes, and post-clear cache generations do not share work.
  • Concurrent callers now share the same settled error/result for that one snapshot. The in-flight entry clears on settle (or the existing 30-second safety timeout), so a later request retries normally.
  • Completed-read LRU and byte-budget behavior is unchanged.

Validation

  • Full suite: 2,562 test files passed; 26,714 tests passed; 4 files / 34 tests skipped.
  • Native-chat focused suite: 34/34 passed across cache, parser, watcher, desktop IPC, and runtime RPC/mobile windowing.
  • Full node/CLI/web typecheck passed.
  • Targeted oxlint, oxfmt --check, reliability gates, and max-lines ratchet passed.
  • Aggregate pnpm lint reaches a pre-existing ja.json interpolation mismatch for components.native-chat.composer.uploadingAttachments; this PR does not touch localization files.

@coderabbitai

coderabbitai Bot commented Jul 10, 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: 525ecb53-7573-438d-a3ba-1778defcef0b

📥 Commits

Reviewing files that changed from the base of the PR and between 96d1fa1 and 17a919d.

📒 Files selected for processing (3)
  • src/main/native-chat/transcript-read-cache-inflight-cost.bench.test.ts
  • src/main/native-chat/transcript-read-cache.test.ts
  • src/main/native-chat/transcript-read-cache.ts

📝 Walkthrough

Walkthrough

Native chat transcript cache misses now deduplicate concurrent reads for the same resolved file snapshot using an in-flight promise mechanism. Cache generation tracking prevents results from invalidated reads from being stored after cache resets. Tests cover shared object results for concurrent identical reads and separate reads for distinct files, while a benchmark measures concurrent miss cost.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing the template’s required Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes sections. Rewrite the PR description to follow the repository template and fill each required section, including screenshots, testing checkboxes, review report, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: coalescing concurrent native-chat transcript reads.
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.

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.

@nwparker

Copy link
Copy Markdown
Contributor Author

Superseded: main already coalesces concurrent transcript reads in transcript-read-cache.ts, and readNativeChatTranscriptCached has no production callers.

@nwparker nwparker closed this Oct 14, 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