Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(agent, cli): Gemini bugfixes, add fallback if pty isn't available (#1123)

ddupont2036aa136b65
diff --git a/libs/python/agent/agent/loops/gemini.py b/libs/python/agent/agent/loops/gemini.py
index 86221d779a..3385b796c8 100644
--- a/libs/python/agent/agent/loops/gemini.py
+++ b/libs/python/agent/agent/loops/gemini.py
@@ -643,7 +643,7 @@ def _map_gemini_fc_to_computer_call(
action = {"type": "playwright_exec", "command": "visit_url", "params": {"url": url}}
else:
return None
- elif name == "open_web_browser":
+ elif name in ("open_web_browser", "open_browser"):
# Open browser with blank page or google
action = {
"type": "playwright_exec",
@@ -837,7 +837,16 @@ class GeminiComputerUseConfig(AsyncAgentConfig):
# Debug: print raw function calls from response
try:
- for p in response.candidates[0].content.parts:
+ _dbg_candidates = getattr(response, "candidates", None) or []
+ _dbg_parts = (
+ getattr(
+ getattr(_dbg_candidates[0] if _dbg_candidates else None, "content", None),
+ "parts",
+ None,
+ )
+ or []
+ )
+ for p in _dbg_parts:
if hasattr(p, "function_call") and p.function_call:
print(
f"[DEBUG] Raw function_call from model: name={p.function_call.name}, args={dict(p.function_call.args or {})}"
@@ -876,11 +885,16 @@ class GeminiComputerUseConfig(AsyncAgentConfig):
# Parse output into internal items
output_items: List[Dict[str, Any]] = []
- candidate = response.candidates[0]
+ candidates = getattr(response, "candidates", None) or []
+ if not candidates:
+ return {"output": output_items, "usage": usage}
+
+ candidate = candidates[0]
# Text parts from the model (assistant message)
text_parts: List[str] = []
function_calls: List[Dict[str, Any]] = []
- for p in candidate.content.parts:
+ parts = getattr(getattr(candidate, "content", None), "parts", None) or []
+ for p in parts:
# Check for thinking/reasoning content first
if getattr(p, "thought", False) and getattr(p, "text", None):
output_items.append(make_reasoning_item(p.text))
diff --git a/libs/python/cua-cli/cua_cli/commands/do.py b/libs/python/cua-cli/cua_cli/commands/do.py
index d7697cc699..894240a27d 100644
--- a/libs/python/cua-cli/cua_cli/commands/do.py
+++ b/libs/python/cua-cli/cua_cli/commands/do.py
@@ -83,6 +83,10 @@ def _fail(msg: str) -> int:
return 1
+class _PtyUnavailable(Exception):
+ """Raised when the remote PTY endpoint is unreachable; triggers run_command fallback."""
+
+
# ── provider / connection helpers ─────────────────────────────────────────────
@@ -1172,8 +1176,7 @@ def _cmd_shell_noninteractive(command: str | None, args: argparse.Namespace) ->
await _print_context(state["provider"], state.get("name", ""), state)
return _fail(f"exit {rc_code}: {stderr or stdout}")
_maybe_record_turn(args, state, "shell", {"command": command})
- preview = (stdout[:80] + "…") if len(stdout) > 80 else stdout
- rc = _ok(preview if preview else "done")
+ rc = _ok(stdout if stdout else "done")
await _print_context(state["provider"], state.get("name", ""), state)
return rc
@@ -1312,8 +1315,10 @@ async def _shell_remote_pty(
) as resp:
resp.raise_for_status()
data = await resp.json()
+ except aiohttp.ClientResponseError as e:
+ raise _PtyUnavailable(f"{e.status} {e.message} ({e.request_info.real_url})") from e
except Exception as e:
- return _fail(f"Failed to create PTY session: {e}")
+ raise _PtyUnavailable(str(e)) from e
pid: int = data["pid"]
@@ -1457,7 +1462,13 @@ def _cmd_shell(args: argparse.Namespace) -> int:
from cua_cli.utils.async_utils import run_async
- return run_async(_shell_remote_pty(provider, name, command, cols=cols, rows=rows))
+ try:
+ return run_async(_shell_remote_pty(provider, name, command, cols=cols, rows=rows))
+ except _PtyUnavailable as e:
+ if not command:
+ return _fail(f"PTY unavailable: {e}")
+ print(f"⚠️ PTY unavailable ({e}), falling back to run_command", file=sys.stderr)
+ return _cmd_shell_noninteractive(command, args)
def _cmd_open(args: argparse.Namespace) -> int: