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

perf(agent-manager): Antigravity adapter runs synchronous ps/lsof on every refresh instead of using the shared snapshot

Open codeaholicguy opened this issue 2 months ago • 0 comments

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 console over 180 s:
    • spawnSync accounted for 10.1 s of main-thread time, all under AntigravityCliAdapter.detectAgents.
    • Breakdown: listAgentProcesses 7.9 s, batchGetProcessCwds 1.7 s, batchGetProcessStartTimes 0.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?: AgentDetectionContext and filter context.processes, following ClaudeCodeAdapter.detectAgents.
  • Fall back to captureProcessSnapshot (async) only when no context is given.

Acceptance criteria

  • [ ] AntigravityCliAdapter declares processNames and uses context.processes when provided.
  • [ ] The Antigravity detection path makes no execFileSync/spawnSync calls; a test asserts child_process sync APIs aren't called.
  • [ ] With an injected snapshot containing no agy process, detectAgents spawns 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 listAgentProcesses or enrichProcesses from utils/process.

codeaholicguy avatar Sep 28 '26 08:09 codeaholicguy