ai-devkit
ai-devkit copied to clipboard
perf(agent-manager): Gemini discovery reads every chat file in full on each refresh
Problem
GeminiSessionLocator.discoverSessions (packages/agent-manager/src/providers/gemini/GeminiSessionLocator.ts) runs for Gemini processes not already cached in the registry.
- It walks every
~/.gemini/tmp/<id>/chats/directory andreadFileSyncs every chat file in full (readCandidateSession). - It keeps all of their contents in
contentCacheat once. - There is no date window, so every refresh costs O(total Gemini history) in both bytes read and peak memory.
Proposed approach
- Skip
chats/directories that can't belong to a live process, using the project-hash ↔ cwd mapping that is already computed (cwdHashMap), before reading any file. - Consider only files whose mtime is at or after the earliest candidate process start time (with some slack).
- Extract
projectHashandsessionIdfrom a bounded head read where the format allows; otherwise cache the parsed metadata keyed by path, inode, size and mtime. - Remove
contentCache; matched sessions are parsed once and cached by the same key.
Acceptance criteria
- [ ] With 500 historical chat fixtures across 20 projects and 1 unmatched live process, discovery opens only files from that process's project whose mtime falls in the window.
- [ ] No full contents of unrelated chat files are kept in memory;
contentCacheis removed or bounded. - [ ] After the first refresh, with unchanged files, a refresh reads 0 bytes of chat content.
- [ ] Existing Gemini detection tests pass with identical results.