Skip to content

fix: await telemetry.shutdown in stop() and re-throw auth timeout error#1420

Open
Ricardo-M-L wants to merge 2 commits into
trycua:mainfrom
Ricardo-M-L:fix/anthropic-scroll-direction-mapping
Open

fix: await telemetry.shutdown in stop() and re-throw auth timeout error#1420
Ricardo-M-L wants to merge 2 commits into
trycua:mainfrom
Ricardo-M-L:fix/anthropic-scroll-direction-mapping

Conversation

@Ricardo-M-L
Copy link
Copy Markdown
Contributor

@Ricardo-M-L Ricardo-M-L commented May 1, 2026

Summary

Bug 1 - cloud.ts stop() missing telemetry shutdown:
stop() disconnected the interface but never called telemetry.shutdown(). When CloudComputer disconnects, PostHog events are never flushed. Fix: add await this.telemetry.shutdown(), matching AgentClient.disconnect().

Bug 2 - auth.ts timeout swallowed:
loginViaBrowser used finally instead of catch — timeout fires, error caught but not re-thrown. Callers got undefined instead of an error. Fix: change finally to catch, re-throw after stopping server.

Test plan

  • Verify telemetry events are flushed when stop() is called
  • Verify timeout error propagates to callers instead of returning undefined

Summary by CodeRabbit

  • Bug Fixes

    • Fixed scroll direction mapping for horizontal and vertical scrolling.
  • Improvements

    • Enhanced telemetry shutdown during cloud computer disconnection.
    • Improved error handling in browser-based authentication flow.

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.
cloud.ts stop(): call telemetry.shutdown() to flush PostHog events — matches
the pattern in AgentClient.disconnect.

auth.ts loginViaBrowser: re-throw the timeout error instead of silently
swallowing it, so callers receive a proper error instead of undefined.
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 1, 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 May 1, 2026

📝 Walkthrough

Walkthrough

These changes comprise three separate bug fixes: correcting inverted scroll direction mappings in the Python agent loop, ensuring telemetry shutdown completion during cloud computer disconnection, and refactoring error handling in browser-based authentication from finally to catch block logic.

Changes

Cohort / File(s) Summary
Scroll Direction Fix
libs/python/agent/agent/loops/anthropic.py
Inverted horizontal and vertical scroll direction mappings in tool-use conversion; positive/negative scroll_x now map to right/left, and positive/negative scroll_y map to down/up (previously reversed).
Telemetry Shutdown
libs/typescript/computer/src/computer/providers/cloud.ts
CloudComputer.stop() now explicitly awaits telemetry.shutdown() after interface disconnection to ensure telemetry terminates before marking uninitialized.
Auth Error Handling
libs/typescript/cua-cli/src/auth.ts
loginViaBrowser refactored from finally-block to catch-block error handling; server stops conditionally on error rather than unconditionally after successful authorization.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

release:pypi/agent

Poem

🐰 Scrolls spin right, directions align,
Telemetry bows before the sign,
Auth catches errors with graceful care,
Three tiny fixes floating in air!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 'fix: await telemetry.shutdown in stop() and re-throw auth timeout error' directly addresses two key bug fixes described in the PR objectives: telemetry shutdown in cloud.ts and error re-throwing in auth.ts. However, it omits the third significant change (scroll direction mapping fix in anthropic.py), which affects tool-use conversion logic.
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

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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)

484-498: ⚠️ Potential issue | 🔴 Critical

The forward conversion is inverted relative to the correct reverse conversion path and qmp.py convention.

According to qmp.py (line 280), positive scroll_y means "scroll up". However, the forward conversion at lines 484–498 maps:

  • scroll_y > 0direction = "down"
  • scroll_y < 0direction = "up"

This inverts the direction. When this flows through the tool_calls reverse conversion (lines 1289–1298), which correctly expects "up" → positive scroll_y, the result is backwards:

  • Input: scroll_y > 0 (scroll up) → mapped to "down" → reversed to negative scroll_y (scroll down)

The forward conversion should be:

  • scroll_y > 0direction = "up"
  • scroll_y < 0direction = "down"

Additionally, there is a pre-existing inconsistency: the content_item reverse conversion (lines 855–872) has the opposite mapping ("down" → positive scroll_y), which is also incorrect per qmp.py. Both reverse conversion paths should be aligned to match the qmp.py convention.

🤖 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 484 - 498, The
forward conversion block that sets direction/amount (the code that assigns
direction = "right"/"left"/"down"/"up" based on scroll_x/scroll_y and computes
amount) is inverted for scroll_y: change it so scroll_y > 0 sets direction =
"up" and scroll_y < 0 sets direction = "down" (amount stays absolute). Also
update both reverse conversion paths that interpret direction strings—the
"tool_calls" reverse conversion and the "content_item" reverse conversion—so
they both follow qmp.py's convention: "up" maps to positive scroll_y and "down"
maps to negative scroll_y. Ensure the direction string names ("up"/"down") are
used consistently between the forward conversion (direction variable) and both
reverse conversions.
🤖 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 484-498: The forward conversion block that sets direction/amount
(the code that assigns direction = "right"/"left"/"down"/"up" based on
scroll_x/scroll_y and computes amount) is inverted for scroll_y: change it so
scroll_y > 0 sets direction = "up" and scroll_y < 0 sets direction = "down"
(amount stays absolute). Also update both reverse conversion paths that
interpret direction strings—the "tool_calls" reverse conversion and the
"content_item" reverse conversion—so they both follow qmp.py's convention: "up"
maps to positive scroll_y and "down" maps to negative scroll_y. Ensure the
direction string names ("up"/"down") are used consistently between the forward
conversion (direction variable) and both reverse conversions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19c9adce-41eb-48ae-a0c9-0665be8f6f5a

📥 Commits

Reviewing files that changed from the base of the PR and between f432b6a and c8bd632.

📒 Files selected for processing (3)
  • libs/python/agent/agent/loops/anthropic.py
  • libs/typescript/computer/src/computer/providers/cloud.ts
  • libs/typescript/cua-cli/src/auth.ts

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