ai-devkit
ai-devkit copied to clipboard
perf(agent-manager): Antigravity adapter runs synchronous ps/lsof on every refresh instead of using the shared snapshot
Problem
AntigravityCliAdapter.detectAgents (packages/agent-manager/src/adapters/AntigravityCliAdapter.ts) doesn't declare processNames. So AgentManager.listAgents calls it without the shared process snapshot, and it runs its own synchronous process discovery:
const processes = enrichProcesses(listAgentProcesses("agy"));
That means execFileSync of ps -axo ..., lsof -a -d cwd ... and ps -o lstart ... on every refresh. It duplicates the shared async snapshot and blocks the event loop. The ps call runs even when no agy process exists.
This regression shipped in [email protected] / [email protected], from the adapter introduced in #133.
Evidence
- CPU profile of
ai-devkit agent consoleover 180 s:spawnSyncaccounted for 10.1 s of main-thread time, all underAntigravityCliAdapter.detectAgents.- Breakdown:
listAgentProcesses7.9 s,batchGetProcessCwds1.7 s,batchGetProcessStartTimes0.5 s.
- About 160 ms of event-loop blocking per refresh, plus 3 extra subprocesses per refresh (6 in total instead of 3).
Proposed approach
- Declare
readonly processNames = ["agy"] as const. - Accept
context?: AgentDetectionContextand filtercontext.processes, followingClaudeCodeAdapter.detectAgents. - Fall back to
captureProcessSnapshot(async) only when no context is given.
Acceptance criteria
- [ ]
AntigravityCliAdapterdeclaresprocessNamesand usescontext.processeswhen provided. - [ ] The Antigravity detection path makes no
execFileSync/spawnSynccalls; a test assertschild_processsync APIs aren't called. - [ ] With an injected snapshot containing no
agyprocess,detectAgentsspawns no subprocess. - [ ] A full
listAgents()refresh spawns exactly one set of shared snapshot subprocesses (ps+lsof+ps lstart), not two. - [ ] Existing Antigravity detection and conversation tests pass unchanged.
- [ ] Optional guard: a lint rule or test fails if any adapter imports the sync helpers
listAgentProcessesorenrichProcessesfromutils/process.