Skip to content

fix(agent): use is not None check in predict_click for zero coordinates#1515

Open
zhoufengen wants to merge 1 commit into
trycua:mainfrom
zhoufengen:fix/predict-click-zero-coordinates
Open

fix(agent): use is not None check in predict_click for zero coordinates#1515
zhoufengen wants to merge 1 commit into
trycua:mainfrom
zhoufengen:fix/predict-click-zero-coordinates

Conversation

@zhoufengen
Copy link
Copy Markdown

@zhoufengen zhoufengen commented May 14, 2026

Summary

AnthropicHostedToolsConfig.predict_click uses a Python truthiness check to validate click coordinates:

if action.get("x") and action.get("y"):

This silently returns None when either coordinate is 0 (falsy in Python). Valid edge-of-screen clicks at x=0 or y=0 are incorrectly discarded.

Changes

Replace the truthiness check with an explicit None check in libs/python/agent/cua_agent/loops/anthropic.py:

# Before (buggy)
if action.get("x") and action.get("y"):

# After (fixed)
if action.get("x") is not None and action.get("y") is not None:

This matches the pattern already used in the OpenAI loop (openai.py:401).

Testing

Added libs/python/agent/tests/test_predict_click_zero_coords.py with 6 tests:

  • Confirm the old truthiness check drops x=0, y=0, and (0, 0) (regression proof)
  • Confirm the fix returns correct coordinates for all three cases
  • Non-zero coordinates still work
  • Returns None when no computer_call in response
  • Source file contains the is not None check (not the old buggy pattern)

Run with:

pytest libs/python/agent/tests/test_predict_click_zero_coords.py -v

tests pass

Related Issues

Fixes #1400

Summary by CodeRabbit

  • Bug Fixes

    • Fixed click coordinate detection to properly handle zero-value coordinates (0, 0) that were previously treated as invalid.
  • Tests

    • Added regression tests to verify zero-coordinate handling and prevent future regressions.

Review Change Stack

In AnthropicHostedToolsConfig.predict_click, the coordinate check used
Python truthiness (`if action.get("x") and action.get("y")`), which
silently returns None when either coordinate is 0. Valid edge-of-screen
clicks at x=0 or y=0 were incorrectly discarded.

Replace with explicit None checks, matching the pattern already used in
the OpenAI loop (openai.py:401):

  if action.get("x") is not None and action.get("y") is not None

Fixes trycua#1400

Generated with [AWS Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 14, 2026

@zhoufengen is attempting to deploy a commit to the Cua Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 05741331-e8c6-488c-829f-33189534c960

📥 Commits

Reviewing files that changed from the base of the PR and between c173173 and 72feb25.

📒 Files selected for processing (2)
  • libs/python/agent/cua_agent/loops/anthropic.py
  • libs/python/agent/tests/test_predict_click_zero_coords.py

📝 Walkthrough

Walkthrough

This PR fixes a coordinate validation bug in predict_click where zero values were incorrectly treated as invalid, preventing clicks on screen edges. The fix replaces falsy checks with explicit None validation. A comprehensive test suite verifies the fix works for zero coordinates, preserves non-zero behavior, and confirms the implementation is correct.

Changes

Coordinate Validation Fix

Layer / File(s) Summary
Coordinate validation fix
libs/python/agent/cua_agent/loops/anthropic.py
predict_click guard changed from truthiness checks (if x and y) to explicit is not None checks, allowing coordinates of 0 to be valid results.
Regression test suite
libs/python/agent/tests/test_predict_click_zero_coords.py
Test module with _extract_click_coords_old and _extract_click_coords_fixed helpers demonstrating buggy vs. corrected logic. Regression tests assert old behavior dropped zero coordinates while fixed behavior preserves them. Positive tests confirm non-zero coordinates and non-computer_call items work correctly. Source verification test reads anthropic.py and asserts the is not None check is present and the old truthiness pattern is absent.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A click at the edge, once lost to the void,
Where zeros were falsy, and logic destroyed—
Now (0, y) stands tall, no longer denied,
With tests to ensure it won't slip and hide! 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing predict_click to handle zero coordinates by using explicit None checks instead of truthiness checks.
Linked Issues check ✅ Passed The PR fully addresses issue #1400 by implementing the exact fix proposed: replacing truthiness checks with explicit None checks in predict_click, and adding comprehensive regression tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the zero-coordinate bug in predict_click and adding related regression tests; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: predict_click returns None for zero coordinates (x=0 or y=0)

1 participant