Skip to content

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

Description

@codeaholicguy

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions