fix: correct inverted scroll direction mapping in Anthropic agent loop#1281
fix: correct inverted scroll direction mapping in Anthropic agent loop#1281Ricardo-M-L wants to merge 1 commit intotrycua:mainfrom
Conversation
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.
|
@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. |
📝 WalkthroughWalkthroughA 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 | 🔴 CriticalRemaining inverted scroll mapping in tool_calls path.
The reverse conversion in the
tool_callshandling 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 = -amountThis will cause scroll actions returned via the
tool_callsformat 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
📒 Files selected for processing (1)
libs/python/agent/agent/loops/anthropic.py
Summary
_convert_responses_items_to_completion_messages(libs/python/agent/agent/loops/anthropic.py)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")_convert_completion_to_responses_itemswas already correct, making the two functions inconsistent — a round-trip conversion would invert the scroll directionDetails
In
_convert_completion_to_responses_items, the mapping is:"right"→scroll_x = +amount"left"→scroll_x = -amount"down"→scroll_y = +amount"up"→scroll_y = -amountBut
_convert_responses_items_to_completion_messageshad 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