fix(tools): keep cua-driver MCP session task-local#28556
Closed
nazirulhafiy wants to merge 2 commits into
Closed
Conversation
d63956b to
e526b47
Compare
a7b1fe0 to
c9da4a3
Compare
19 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_window_statemore time for heavy native app AX treesMotivation
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 passedpython -m ruff check tools/computer_use/cua_backend.py tools/computer_use/tool.py tests/tools/test_computer_use.py— passedpython -m py_compile tools/computer_use/cua_backend.py tools/computer_use/tool.py tests/tools/test_computer_use.py— passedCuaDriverBackend, calledlist_apps(), captured Safari AX state successfully (188elements)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.