Skip to content

fix(agent): handle zero coordinates in predict_click#1495

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

fix(agent): handle zero coordinates in predict_click#1495
xronocode wants to merge 1 commit into
trycua:mainfrom
xronocode:fix/predict-click-zero-coordinates

Conversation

@xronocode
Copy link
Copy Markdown

@xronocode xronocode commented May 13, 2026

Summary

Small fix for #1400predict_click silently returned None when either x or y was 0, since the existing truthiness check treated 0 as falsy.

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

Changes

  • libs/python/agent/cua_agent/loops/anthropic.py — one-line fix at the coordinate validation check
  • libs/python/agent/tests/test_predict_click.py — 5 regression tests covering (0, y), (x, 0), (0, 0), normal coordinates, and no-click response

Testing

All 29 tests pass (24 existing + 5 new):

  • test_predict_click_x_zero — click at (0, 300) returns (0, 300), not None
  • test_predict_click_y_zero — click at (500, 0) returns (500, 0), not None
  • test_predict_click_both_zero — click at (0, 0) returns (0, 0), not None
  • test_predict_click_normal_coordinates — click at (512, 384) works as before
  • test_predict_click_no_click_action — text-only response returns None

Happy to adjust anything — thanks for the great project!

Summary by CodeRabbit

  • Bug Fixes

    • Fixed click coordinate extraction to correctly handle zero values (e.g., clicks at position (0, 0) or with x=0/y=0).
  • Tests

    • Added regression tests to ensure click coordinate handling works correctly for zero and non-zero coordinate values.

Review Change Stack

The truthiness check on action.get('x') and action.get('y') falsely
rejected x=0 or y=0 since 0 is falsy in Python. Changed to explicit
is not None check so that valid zero coordinates are accepted.

Closes trycua#1400
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 13, 2026

@xronocode 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 13, 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: 02b58dd5-eb0c-490e-91cd-fb53b6c44169

📥 Commits

Reviewing files that changed from the base of the PR and between 041916d and 81ed5ff.

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

📝 Walkthrough

Walkthrough

This PR fixes a coordinate validation bug in predict_click where zero-valued x or y coordinates were incorrectly rejected. The fix replaces truthiness checks with explicit is not None comparisons. Comprehensive regression tests verify the corrected behavior for zero and non-zero coordinates.

Changes

Zero-coordinate validation fix and tests

Layer / File(s) Summary
Zero-coordinate validation fix
libs/python/agent/cua_agent/loops/anthropic.py
Updated the coordinate-validity check in predict_click from truthiness tests to explicit is not None checks so that zero values in x or y are accepted as valid.
Regression test suite for zero-coordinate handling
libs/python/agent/tests/test_predict_click.py
Added test module with a minimal PNG constant, two mock-response builder helpers, and a TestAnthropicPredictClickZeroCoordinates test class that validates predict_click correctly returns (0, y), (x, 0), (0, 0), normal tuples, and None for missing click actions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐰 A hop, a skip, a zero in sight,
Now (x, y) of (0, 0) is right!
No truthiness tricks to make them fall,
Explicit is not None handles them all. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main fix: handling zero coordinates in the predict_click function.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

@xronocode xronocode marked this pull request as ready for review May 13, 2026 07:35
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.

1 participant