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

perf(agent-manager): Copilot lock discovery scans every session directory on each refresh

Open codeaholicguy opened this issue 2 months ago • 0 comments

Problem

CopilotSessionLocator.discoverActiveLocks (packages/agent-manager/src/providers/copilot/CopilotSessionLocator.ts) runs a readdir on every session directory ever created on every refresh, looking for inuse.<pid>.lock files. The cost grows with total Copilot history.

For each active lock, CopilotSessionParser.readSessionDir then reads the full events.jsonl (readEventEntries) and parses every line.

Proposed approach

  • Limit the lock search to session directories whose mtime is at or after the earliest live Copilot process start time (with slack). Creating a lock file updates the directory's mtime.
  • Remember the lock → directory mapping per (pid, startTime) and re-validate it with a single stat instead of rescanning.
  • Parse events.jsonl summaries through the incremental summary utility (#256).

Acceptance criteria

  • [ ] With 1,000 historical session directory fixtures and 1 live process, a refresh runs readdir on only directories modified since that process started (the test asserts the calls).
  • [ ] A known live lock is re-validated with O(1) filesystem calls per refresh.
  • [ ] An unchanged events.jsonl reads 0 bytes on the second refresh; after appending K bytes, ≤ K + 64 KiB.
  • [ ] Existing Copilot detection tests pass with identical results.

Depends on #256.

codeaholicguy avatar Sep 28 '26 08:09 codeaholicguy