cua icon indicating copy to clipboard operation
cua copied to clipboard

cua-driver(macos): process stays alive + drains CPU after task completes (likely screencapture/recording leak)

Open f-trycua opened this issue 5 months ago • 1 comments

Symptom

cua-driver process (likely launched via cua-driver mcp from the hermes-agent computer-use wrapper) stays alive after the agent's task has completed and drains CPU on macOS — observed by a contributor as making the fans spin up on a MacBook Air just from idle background activity. Killing the lingering cua-driver PID returns the machine to baseline.

Anecdotal but reportedly reproducible by repeated computer-use turns, then waiting after the turn ends. Suspicion points at the screen recording / per-window screencapture path — that's where a long-lived capture session would keep CPU non-trivial — but not yet pinned down to a specific tool.

Expected

When the MCP stdio session ends (parent closes stdin or terminates), cua-driver should:

  1. Tear down any open recording / screencapture / overlay surfaces (cursor overlay, PiP preview, ScreenCaptureKit / ImageCapture handles).
  2. Exit cleanly within a couple of seconds.

Right now it appears one (or both) is failing: either the process doesn't notice the parent has gone away, or it notices but the recording subsystem keeps an event loop hot and refuses to drop refs.

Reproduction notes

  • Platform: macOS (MacBook Air — Apple Silicon, fanless model implied since fans aren't mentioned — likely CPU thermals + power impact rather than literal fan noise).
  • Trigger: ordinary computer-use sessions through the hermes-agent wrapper. No explicit recording action — the contributor said "i guess, screencapture of certain apps", suggesting get_window_state / capture(mode='som'|'vision') triggered the path.
  • Aftermath: agent task finishes, agent process exits, cua-driver still in ps, sustained CPU.

A clean repro would be ideal — repeated capture calls in a hermes session then exit and watch ps -p $(pgrep cua-driver) + top -pid <pid> for ~30s.

What to look at first

  • crates/cua-driver/src/main.rs (or wherever stdio reads block) — does the read loop notice EOF on stdin and cascade a shutdown to all sessions / tool workers?
  • crates/cursor-overlay/ and crates/pip-preview/ — these hold their own event loops on macOS (CoreAnimation / dispatch queues). If a recording session ends without the parent explicitly tearing the overlay down, the overlay loop can keep the process alive.
  • Any ScreenCaptureKit / CGDisplayStream / AVCaptureSession handles touched by capture_mode='vision' or the screencast variants — those hold strong refs through their own queues and need explicit .stopCapture() / drop.
  • Per-session GC — #1777 hints at a TTL reaper for config state; the same plumbing might need to GC capture handles when a session goes idle.

Workaround

End-users can pkill -f cua-driver after a hermes session ends. Not great as a long-term answer.

References

  • Related: #1777 (session-identity / TTL reaper work)
  • Reporter: internal community contributor; will tag here separately if they want to attach a sample profile.

f-trycua avatar Jun 23 '26 22:06 f-trycua

Additional data point: macOS 14.8.3, Apple Silicon, 16 GB RAM, official signed Cua Driver 0.23.2, using Hermes' CuaDriverBackend.

In an isolated embedded daemon with overlays disabled and standard permission mode, we captured a small test window three times in vision mode, then stopped the MCP backend. The daemon reported zero lifecycle sessions before observation. No recording commands were issued by the diagnostic.

During the following six idle minutes:

  • Physical footprint grew from 17.5 to 125.9 MiB (+108.4 MiB), measured with vmmap.
  • CPU averaged 10.96% of one core, calculated from process CPU-time deltas rather than lifetime ps percentages.
  • No further screenshot or action calls were made. The three screenshots had been verified as fresh.

A subsequent sample still showed the cua-sck-window-capture worker waiting in SyncCompletion. This does not establish the allocation root cause. Explicitly stopping the isolated test endpoint removed its process and socket; unrelated active helpers were left untouched.

Is there an existing fix or preferred diagnostic path for screenshot-triggered idle growth after session end? The recording-lifetime fix discussed in #1764 seems distinct, and 0.24.0's shutdown cleanup does not by itself establish idle-growth prevention. We'd prefer to follow the upstream solution rather than add a local workaround.

DmytroVolodymyrson avatar Sep 09 '26 00:09 DmytroVolodymyrson