ai-devkit
ai-devkit copied to clipboard
perf(agent-manager): Copilot lock discovery scans every session directory on each refresh
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 singlestatinstead of rescanning. - Parse
events.jsonlsummaries through the incremental summary utility (#256).
Acceptance criteria
- [ ] With 1,000 historical session directory fixtures and 1 live process, a refresh runs
readdiron 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.jsonlreads 0 bytes on the second refresh; after appending K bytes, ≤ K + 64 KiB. - [ ] Existing Copilot detection tests pass with identical results.
Depends on #256.