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

perf(agent-manager): enrich only candidate PIDs ("node" in processNames enriches every Node process)

Open codeaholicguy opened this issue 2 months ago • 0 comments

Problem

AgentManager.listAgents builds one shared process snapshot from the union of all adapters' processNames. The Gemini, Kiro and Pi adapters declare "node", so every Node.js process on the machine matches: editor helpers, dev servers, other CLIs.

captureProcessSnapshot then enriches all matched PIDs with lsof -a -d cwd -p <pids> and ps -o lstart= -p <pids> on every refresh, before any adapter's canHandle filters them out. On a typical developer machine, dozens of unrelated Node processes get enriched every 3 s (49 on a test machine), and the cost grows with unrelated software.

Proposed approach

Use two-phase capture in packages/agent-manager/src/utils/process.ts and AgentManager.listAgents:

  1. Run ps -axo pid=,ppid=,tty=,command= once, as today.
  2. Keep only processes that at least one adapter's canHandle accepts. canHandle is already on the AgentAdapter interface and needs only the command and executable.
  3. Run lsof and ps lstart for that filtered PID set only.

Optionally, cache start times per PID, since they never change for a live PID; this lets ps lstart skip PIDs it has already seen.

Acceptance criteria

  • [ ] Given a snapshot with 50 unrelated node processes and 2 real agents, lsof/ps lstart receive only the PIDs that pass some adapter's canHandle (unit test with an injected exec).
  • [ ] Start times are fetched once per (pid) while the process is alive, not on every refresh.
  • [ ] Detection results are unchanged for existing Gemini, Kiro and Pi tests, including wrapper-process handling.
  • [ ] With no candidate agent processes, a refresh spawns only the base ps (no lsof/ps lstart).

codeaholicguy avatar Sep 28 '26 08:09 codeaholicguy