Repository navigation
perf(ai-vault): count recent sessions for scan cutoffs - #20301
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Shared scan cutoff helper — new
src/main/ai-vault/session-scan-cutoff.tsreplaces the per-candidate sort with an O(n) count (newerCount >= limit), which is exactly the Nth-largest> nextCandidatecondition. - Native + remote wiring —
session-scanner.tsandremote-session-scanner.tsdrop their duplicate private cutoff functions and import the shared one, preserving thesessions.size < limit/ undefined-mtime early return. - Fallback fidelity — non-integer /
<= 0/NaN/Infinitylimits and anyNaNtimestamp route back to the exact legacy sort, so equal mtimes still never stop the scan and unusual limits keep their original semantics. - Differential tests —
session-scan-cutoff.test.tscross-checks the new function against a sort-based reference across invalid dates, extended years, negative limits and lowered-alias replacements;session-scanner-cutoff.test.tsasserts zero numeric sorts across a real native and remote scan. I confirmed the scanner test genuinely fails against the baseline implementation (64 numeric sorts), so it is not a tautology. - Benchmark script —
config/scripts/session-scan-cutoff-benchmark.mjsruns 40k randomized differential cutoff calls and reports counterbalanced CPU timings.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
nwparker
changed the base branch from
OrcaWin/codex-perf-09-11-session-dedup-batches
to
main
September 13, 2026 01:18
nwparker
force-pushed
the
OrcaWin/codex-perf-09-11-session-scan-cutoff
branch
from
September 13, 2026 01:24
1239f08 to
674376b
Compare
Contributor
|
Warning Review limit reachedNext included review available in 36 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Replace repeated timestamp sorting in the native and remote AI Vault scan cutoff with an equivalent count: the Nth-largest timestamp is strictly newer than the next candidate mtime exactly when at least N timestamps are strictly newer.
Stacked on #20255. The base branch is
OrcaWin/codex-perf-09-11-session-dedup-batches, so this PR contains only the cutoff improvement. Merge after that PR; retarget to main if needed. This is a separate improvement, not a combined performance PR.The identical native/remote cutoff implementations now share
session-scan-cutoff.ts. Every call examines the current collection, so alias replacements that lower a winning timestamp remain correct without new cached state. Equal mtimes still do not stop the scan. Unlimited/insufficient-session scans still return before visiting rows.Preserves the exact original sort for NaN timestamps and unusual numeric limits. Parses timestamps once and reuses the same temporary numeric array for that fallback. No change to discovery bounds, batch sizes, cancellation/yields, scope backfill, returned sessions/order, SSH execution ownership, or wire content. No git-worktree assumption.
Measured result
Actual baseline private cutoff selected from the base source using the TypeScript AST; actual current cutoff, timestamp parser and session collection bundled with esbuild. Node 26.6.0 / macOS arm64, eight counterbalanced pairs. Median CPU time:
The scanner already permits up to
2 * limitcandidates and checks the cutoff after every post-limit candidate. The cumulative workload uses that existing policy. These are synthetic cutoff/admission timings, excluding discovery, file/network reads, parsing and final sorting—not an app-wide latency claim. Nearly ordered timestamps benefit much less than shuffled ones.Malformed-input disclosure: 1,000 timestamps with an invalid first timestamp: 0.128 -> 0.126 ms; invalid last timestamp: 0.119 -> 0.126 ms. The initial allocation-free prototype reparsed earlier timestamps on that fallback and regressed to 0.228 ms; that prototype was replaced before publication. Numeric-array allocation/retention remains the same as the baseline.
Verification
pnpm tc:node, changed-code quality gate againstfdda0e835b, and formatting pass.ORCA_BACKGROUND_LAUNCH=1; no app windows launched.Reproduce:
Tracking: #20206. Does not close the broader performance audit.
Independent review follow-up
This branch now includes #20255's occurrence-index memory mitigation via forward update
1239f0830432479b80ec2334b475f54154d74c36; history was not rewritten. The diff against the updated #20255 branch remains the same six cutoff files.Fresh verification of the combined dedup + cutoff branch: 616 tests across 90 AI Vault files, 40,000 cutoff differential cases, Node typecheck, and changed-code quality gate against the updated base all pass. No app windows launched.
Merge order remains mandatory: merge #20255 first, then retarget/revalidate this PR against main. This review did not merge either PR. The memory mitigation is tested here already, but it does not remove that operational dependency.