Skip to content

fix: correct inverted scroll direction mapping in Anthropic agent loop#1281

Open
Ricardo-M-L wants to merge 1 commit intotrycua:mainfrom
Ricardo-M-L:fix/anthropic-scroll-direction-mapping
Open

fix: correct inverted scroll direction mapping in Anthropic agent loop#1281
Ricardo-M-L wants to merge 1 commit intotrycua:mainfrom
Ricardo-M-L:fix/anthropic-scroll-direction-mapping

Conversation

@Ricardo-M-L
Copy link
Copy Markdown

@Ricardo-M-L Ricardo-M-L commented Apr 8, 2026

Summary

  • Fix inverted scroll direction mapping in _convert_responses_items_to_completion_messages (libs/python/agent/agent/loops/anthropic.py)
  • All 4 scroll directions were mapped to their opposite: scroll_x > 0 → "left" (should be "right"), scroll_x < 0 → "right" (should be "left"), scroll_y > 0 → "up" (should be "down"), scroll_y < 0 → "down" (should be "up")
  • The reverse conversion in _convert_completion_to_responses_items was already correct, making the two functions inconsistent — a round-trip conversion would invert the scroll direction

Details

In _convert_completion_to_responses_items, the mapping is:

  • "right"scroll_x = +amount
  • "left"scroll_x = -amount
  • "down"scroll_y = +amount
  • "up"scroll_y = -amount

But _convert_responses_items_to_completion_messages had the inverse:

  • scroll_x > 0"left" (should be "right")
  • scroll_x < 0"right" (should be "left")
  • scroll_y > 0"up" (should be "down")
  • scroll_y < 0"down" (should be "up")

This fix aligns the forward conversion with the reverse, so round-trip consistency is maintained.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed scroll direction handling where directional mappings were inverted, ensuring scrolling in all directions now works correctly.

In `_convert_responses_items_to_completion_messages`, the scroll direction
mapping was completely inverted for all 4 directions:
- scroll_x > 0 mapped to "left" instead of "right"
- scroll_x < 0 mapped to "right" instead of "left"
- scroll_y > 0 mapped to "up" instead of "down"
- scroll_y < 0 mapped to "down" instead of "up"

The reverse conversion in `_convert_completion_to_responses_items` was
correct, making the forward and reverse mappings inconsistent — a
round-trip would invert the scroll direction.
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 8, 2026

@Ricardo-M-L 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 Apr 8, 2026

📝 Walkthrough

Walkthrough

A scroll direction mapping bug fix in the anthropic loop handler. The X and Y axis scroll directions are inverted in the response conversion function to correct directional behavior.

Changes

Cohort / File(s) Summary
Scroll Direction Mapping Fix
libs/python/agent/agent/loops/anthropic.py
Inverted scroll direction mappings in _convert_responses_items_to_completion_messages: scroll_x > 0 now maps to "right" instead of "left", and scroll_y > 0 now maps to "down" instead of "up". Scroll amount computation logic remains unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Scroll up, scroll down, left to right,
Directions fixed, now they're right!
A flip of maps, a tiny change,
The rabbit fixed the scrolling range!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main change: correcting inverted scroll direction mapping in the Anthropic agent loop.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

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

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
libs/python/agent/agent/loops/anthropic.py (1)

1289-1298: ⚠️ Potential issue | 🔴 Critical

Remaining inverted scroll mapping in tool_calls path.

The reverse conversion in the tool_calls handling branch (lines 1289-1298) still has the inverted mapping. This contradicts the fix applied at lines 484-495 and the correct implementation at lines 855-872.

Current (incorrect):

  • "left"scroll_x = +amount
  • "right"scroll_x = -amount
  • "up"scroll_y = +amount
  • "down"scroll_y = -amount

This will cause scroll actions returned via the tool_calls format to scroll in the opposite direction.

🐛 Proposed fix to align with the correct convention
                            scroll_x = (
                                amount
-                               if direction == "left"
-                               else -amount if direction == "right" else 0
+                               if direction == "right"
+                               else -amount if direction == "left" else 0
                            )
                            scroll_y = (
                                amount
-                               if direction == "up"
-                               else -amount if direction == "down" else 0
+                               if direction == "down"
+                               else -amount if direction == "up" else 0
                            )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libs/python/agent/agent/loops/anthropic.py` around lines 1289 - 1298, The
scroll direction mapping in the tool_calls handling branch is inverted: update
the logic that sets scroll_x and scroll_y (the variables computed from direction
and amount) so it matches the correct convention used elsewhere (e.g., the
earlier fixes): "left" should produce scroll_x = -amount and "right" -> +amount;
"up" should produce scroll_y = -amount and "down" -> +amount; keep the default 0
for other directions. Locate the code that assigns scroll_x and scroll_y in the
tool_calls branch (using variables named scroll_x, scroll_y, direction, amount)
and flip the sign logic accordingly to match the implementation used at the
other locations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@libs/python/agent/agent/loops/anthropic.py`:
- Around line 1289-1298: The scroll direction mapping in the tool_calls handling
branch is inverted: update the logic that sets scroll_x and scroll_y (the
variables computed from direction and amount) so it matches the correct
convention used elsewhere (e.g., the earlier fixes): "left" should produce
scroll_x = -amount and "right" -> +amount; "up" should produce scroll_y =
-amount and "down" -> +amount; keep the default 0 for other directions. Locate
the code that assigns scroll_x and scroll_y in the tool_calls branch (using
variables named scroll_x, scroll_y, direction, amount) and flip the sign logic
accordingly to match the implementation used at the other locations.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 14277254-cd2b-4165-9399-5e97d9a3e511

📥 Commits

Reviewing files that changed from the base of the PR and between 1e62756 and 233b92b.

📒 Files selected for processing (1)
  • libs/python/agent/agent/loops/anthropic.py

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