ai-devkit icon indicating copy to clipboard operation
ai-devkit copied to clipboard

perf(agent-manager): Gemini discovery reads every chat file in full on each refresh

Open codeaholicguy opened this issue 2 months ago • 0 comments

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 and readFileSyncs every chat file in full (readCandidateSession).
  • It keeps all of their contents in contentCache at 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 projectHash and sessionId from 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; contentCache is 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.

codeaholicguy avatar Sep 28 '26 08:09 codeaholicguy