Skip to content

fix(tools): keep cua-driver MCP session task-local#28556

Closed
nazirulhafiy wants to merge 2 commits into
NousResearch:mainfrom
nazirulhafiy:fix/computer-use-cua-session
Closed

fix(tools): keep cua-driver MCP session task-local#28556
nazirulhafiy wants to merge 2 commits into
NousResearch:mainfrom
nazirulhafiy:fix/computer-use-cua-session

Conversation

@nazirulhafiy

Copy link
Copy Markdown
Contributor

Summary

  • keep the cua-driver MCP stdio session lifecycle inside one long-lived asyncio worker task
  • route all cua-driver tool calls through that worker so capture/action calls share the same MCP session and AX cache
  • avoid poisoning the cached computer_use backend when startup fails
  • give get_window_state more time for heavy native app AX trees

Motivation

The previous bridge entered the MCP stdio/ClientSession contexts in one task, then closed them from another. AnyIO cancel scopes used by the MCP stdio transport must be exited by the same task that entered them, which can produce shutdown errors and broken/stale session state. It also makes it easier for element-index actions to lose the cua-driver AX cache created during capture.

Test plan

  • python -m pytest tests/tools/test_computer_use.py -q -o 'addopts=' — 49 passed
  • python -m ruff check tools/computer_use/cua_backend.py tools/computer_use/tool.py tests/tools/test_computer_use.py — passed
  • python -m py_compile tools/computer_use/cua_backend.py tools/computer_use/tool.py tests/tools/test_computer_use.py — passed
  • manual macOS smoke test: started CuaDriverBackend, called list_apps(), captured Safari AX state successfully (188 elements)

Notes

A full python -m pytest tests/ -q -o 'addopts=' run was attempted locally but failed broadly outside this change area after 7k+ passes; I did not treat that as validation for this PR because the failures were not isolated to computer_use. Targeted computer_use tests and lint pass.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tools Tool registry, model_tools, toolsets labels May 19, 2026
@nazirulhafiy nazirulhafiy force-pushed the fix/computer-use-cua-session branch from d63956b to e526b47 Compare May 19, 2026 07:31
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 type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants