Skip to content

fix(computer_use): reconnect cua-driver stdio session between turns#30133

Open
cjinzy wants to merge 1 commit into
NousResearch:mainfrom
cjinzy:fix-cua-stdio-reconnect
Open

fix(computer_use): reconnect cua-driver stdio session between turns#30133
cjinzy wants to merge 1 commit into
NousResearch:mainfrom
cjinzy:fix-cua-stdio-reconnect

Conversation

@cjinzy

@cjinzy cjinzy commented May 22, 2026

Copy link
Copy Markdown

Problem: cua-driver stdio MCP subprocess exits after each tool call sequence. _CuaDriverSession cached the dead session, so 2nd+ capture() failed with empty exceptions (fixes #24170).

Fix: call_tool() now:

  1. Serializes under _lock - no other thread observes torn-down session mid-flight
  2. Catches narrow transport exceptions (ConnectionError, OSError, EOFError, BrokenPipeError, etc.) instead of bare Exception
  3. Hard-resets internal state before reconnect - marks _started=False, nulls _session/_exit_stack immediately
  4. Retries exactly once with a fresh stdio spawn

Also adds --no-daemon-relaunch to _CUA_DRIVER_ARGS to keep the driver in-process (matching terminal TCC context).

Reviewed by: Codex CLI -- flagged thread-safety, broad exception handling, and resource cleanup; all addressed in v2 of this patch.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tools Tool registry, model_tools, toolsets tool/browser Browser automation (CDP, Playwright) labels May 22, 2026
cua-driver's stdio MCP subprocess exits after each tool call sequence
(initialize → calls → shutdown). _CuaDriverSession cached the session
object, so the second capture() call tried to write to a dead pipe,
resulting in empty exceptions and "capture failed".

This adds a single retry in _CuaDriverSession.call_tool(): on any
transport error, tear down the session and re-spawn a fresh stdio
connection, then retry the same tool call once.

Also adds --no-daemon-relaunch to _CUA_DRIVER_ARGS so the stdio
process stays in-process (matching the terminal's TCC context)
rather than relaunching via open -a CuaDriver.

Fixes NousResearch#24170 (capture fails on 2nd+ call).
@cjinzy cjinzy force-pushed the fix-cua-stdio-reconnect branch from 28aa5fe to 0c663e4 Compare May 22, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists tool/browser Browser automation (CDP, Playwright) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] computer_use toolset: 5 bugs found during hands-on testing (macOS 26.4.1, cua-driver v0.1.6)

2 participants