Repository navigation
perf(ai-vault): deduplicate session scan batches incrementally - #20255
Conversation
|
Warning Review limit reachedNext included review available in 7 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
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.
✅ No new issues found.
Reviewed changes
- Incremental session dedup (
codex-session-root-dedup.ts) — addsCodexSessionCollection, which admits each parsed row once and tracks every retained occurrence of the winning row per alias key, replacing the per-batch whole-array re-dedup. The standalonededupeCodexSessionsBySessionIdis unchanged. - Local scanner (
session-scanner.ts) —parseSessionCandidatesaccumulates into the collection andcanStopParsingSessionsreads it; the array is materialized once at return. - Remote scanner (
remote-session-scanner.ts) — same change forparseRemoteSessionCandidates/canStopParsingRemoteSessions. - Tests —
codex-session-collection.test.tschecks parity against the batch deduplicator across ties, invalid dates, canonical roots, WSL namespaces and execution hosts;session-scanner-dedup-batches.test.tsverifies native and remote scans do not re-derive retained aliases per batch and that cross-batch remote replacements do not consume the unique-session budget. - Benchmark —
config/scripts/session-dedup-batches-benchmark.mjscompares baseline vs incremental and runs a 40,000-batch differential.
Verification I ran locally: all 880 src/main/ai-vault tests pass, node config/scripts/session-dedup-batches-benchmark.mjs --verify-only reports 40,000 differential batches, and oxlint is clean on the six changed files. The collection selects the same champion as the batch function (identical left-to-right comparison against the current winner), and its index-keyed Map preserves survivor insertion order, so the returned set, order and object identities are preserved.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Reduced per-row occurrence metadata in
CodexSessionCollection—bestByKeyentries now storeindices: number | number[], so an ordinary unique winner keeps a single numeric index and an array is allocated only once the identical winning object repeats. Both delete paths branch on the sametypeofguard, so winner selection, insertion order, duplicate-object retention, host/WSL isolation and scan budgets are unchanged. The classes' previous one-element-array allocation per surviving row goes away. - Added an ordering regression test —
codex-session-collection.test.tsnow exercises a batch sequence that alternates single and repeated winning occurrences, asserting parity (set, order, identity) against the unchanged batch deduplicator after every batch; the test can fail if the numeric/array collapse mishandled ordering.
I re-ran codex-session-collection.test.ts (7 pass) and session-scanner-dedup-batches.test.ts (3 pass) against 7fd3aae; both green. The scanners' call sites (size, values(), Array.from(sessions.values(), …)) are unchanged in behavior and covered by the existing suite.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Summary
Local and SSH session scanners currently deduplicate the entire accumulated result after every batch of eight parsed files. Use a scan-local collection to admit each parsed row once, reusing the existing alias-key and canonical-root comparison functions. The standalone batch deduplicator remains unchanged.
An insertion-ordered map preserves surviving row order; replacements delete prior winning occurrences instead of moving another row into their position. Identical-object duplicates, distinct tied objects, invalid dates, canonical root/time/path preferences, native/WSL namespaces, execution-host isolation, unique-session parse budgets, cancellation and remote event-loop yields retain their existing behavior. Parsed sessions and title refreshes are replaced/cloned, not mutated after admission.
No new persisted cache, wire fields, execution ownership, agent status, workspace assumptions, or provider-specific behavior. Independent performance improvement 9; tracks #20206.
Measurement
The benchmark bundles the unchanged production batch deduplicator and the new collection, exercising the scanners' eight-row accumulation policy. Eight counterbalanced pairs, Node v26.6.0/macOS arm64, after all local tests and typechecks finished. Median milliseconds:
Synthetic deduplication CPU only: no disk/network, parser, final sorting or app-wide latency claim. Eight-row Claude batches change from 0.132 to 0.181 microseconds; ordinary 100+ row workloads improve. The collection retains O(surviving rows) scan-local indexing metadata, releases losing session objects, and becomes unreachable when the scan returns its array. Forced-GC retained heap growth while holding the index was about 221 KiB for 1,000 unique rows and 2.70 MiB for 10,000; this is not a peak-RSS measurement.
Verification
pnpm tc:nodeand changed-code quality gate pass.ORCA_BACKGROUND_LAUNCH=1; no app windows launched. Actual OS validation is macOS; SSH tests use an in-memory provider, with Windows/WSL paths covered by unit/differential tests.Visual Proof
N/A — session contents, ordering and UI behavior are unchanged.
Independent review follow-up
Commit
7fd3aae222178e993d3598e7d406bb5e9984bd81reduces the scan-local index's memory cost. A unique winning session stores one numeric occurrence index; an array is allocated only when the identical winning object occurs repeatedly. Winner selection, insertion order, duplicate-object handling, host/WSL isolation, cancellation and scan budgets are unchanged.Eight-pair forced-GC measurements with the same pre-created input rows held constant, comparing the original PR head with the applied fix:
That removes approximately 56 bytes per ordinary unique row (22–26% in these fixtures). This is retained collection overhead, not peak RSS; the necessary O(surviving rows) temporary index remains a real trade-off.
Fresh verification: 608 tests across 88 AI Vault files; an additional alternating single/repeated-winner regression; 40,000 unchanged-batch-oracle cases; another 40,000 original-PR-vs-fix batches; Node typecheck, changed-code gate and commit hooks all pass. All checks use
ORCA_BACKGROUND_LAUNCH=1; no app/native windows launched.The dependent #20301 branch also includes this mitigation. Merge this PR first, then retarget/revalidate #20301 against main. No PR has been merged by this review.