feat: Add cloud mode for PR review workflow#1966
Conversation
This adds a new 'cloud' mode to the PR review workflow that launches reviews in OpenHands Cloud instead of running locally in GitHub Actions. Changes: - Add MODE environment variable (sdk/cloud) to agent_script.py - Add run_cloud_mode() function that: - Calls OpenHands Cloud API to start a conversation - Posts a comment on the PR with the cloud conversation URL - Exits without monitoring (review continues asynchronously) - Add post_github_comment() helper function - Add _start_cloud_conversation() helper function - Update composite action.yml with new inputs: - mode (sdk/cloud) - openhands-cloud-api-key - openhands-cloud-api-url - Update workflow.yml example to support cloud mode - Update README.md with cloud mode documentation - Add tests for the new functionality Cloud mode benefits: - Faster CI completion (exits after starting the review) - Track review progress in OpenHands Cloud UI - Interact with the review conversation - Uses the LLM model configured in OpenHands Cloud account Co-authored-by: openhands <openhands@all-hands.dev>
- Extract shared setup code into _prepare_review_context() helper function to eliminate code duplication between run_cloud_mode() and run_sdk_mode() - Fix inconsistent GITHUB_TOKEN requirements: update action.yml to correctly document that GITHUB_TOKEN is required for both modes (used to post PR comments) - Remove redundant OPENHANDS_CLOUD_API_KEY validation in run_cloud_mode() (already validated in main()) - Extract comment body into CLOUD_REVIEW_COMMENT_TEMPLATE constant - Improve tests to actually test behavior by calling main() instead of just verifying list membership - Add test for _prepare_review_context() helper function
Move _prepare_review_context call to main() and pass the prompt to both run_sdk_mode and run_cloud_mode functions. This reduces code duplication and makes the flow clearer - context preparation happens once, then the mode-specific logic runs. - run_cloud_mode now takes (pr_info, prompt) instead of (pr_info, review_style) - run_sdk_mode now takes (prompt, skill_trigger) instead of (pr_info, review_style)
🧪 Cloud Mode Test Results (Bug Fix Verification)Status: ✅ Bug fix verified - Cloud mode working correctly Issue Found and FixedThe Fix Applied
Test Results
📍 Test Conversation URL: https://app.all-hands.dev/conversations/5be1faf2ef364d3f84df3055922867db This test was performed to verify the bug fix for PR #1966. |
The OpenHands Cloud API does not accept a 'secrets' field in the request payload (causes HTTP 422 'Extra inputs are not permitted' error). The Cloud API has 'additionalProperties: false' in its schema, which means it only accepts the documented fields: initial_user_msg, repository, git_provider, selected_branch, etc. Instead of passing secrets directly, OpenHands Cloud uses the user's connected GitHub account for repository access. Added an informational log message to explain this behavior when github_token is provided. Co-authored-by: openhands <openhands@all-hands.dev>
Rewrote cloud mode to use OpenHandsCloudWorkspace instead of directly calling the /api/conversations endpoint. This provides: - Proper sandbox provisioning via OpenHands Cloud API - LLM configuration sent to the cloud sandbox - GITHUB_TOKEN passed to sandbox for posting review comments - Same agent capabilities as SDK mode, but running in the cloud Changes: - agent_script.py: Rewrite run_cloud_mode() to use OpenHandsCloudWorkspace - agent_script.py: Remove _start_cloud_conversation() and CLOUD_REVIEW_COMMENT_TEMPLATE - agent_script.py: Cloud mode now requires LLM_API_KEY (sent to sandbox) - action.yml: Update to require LLM_API_KEY for both modes - action.yml: Add openhands-workspace to dependencies - README.md: Update documentation for new cloud mode architecture - tests: Update tests for new requirements See: https://docs.openhands.dev/sdk/guides/agent-server/cloud-workspace Co-authored-by: openhands <openhands@all-hands.dev>
🔧 Major Refactor: Cloud Mode Now Uses OpenHandsCloudWorkspaceI've refactored the cloud mode implementation to properly use What ChangedBefore:
After:
New Requirements for Cloud ModeCloud mode now requires both:
DocumentationSee the official guide: https://docs.openhands.dev/sdk/guides/agent-server/cloud-workspace Commits
|
- Revert agent_script.py to main version and add cloud mode support - Share core agent definition logic between SDK and cloud modes - Cloud mode uses OpenHandsCloudWorkspace with keep_alive=True - Cloud mode calls run(blocking=False) to start agent without waiting - Add CLOUD_MODE_INSTRUCTION to instruct agent to post review comment when done - Post PR comment with conversation URL for tracking progress - Update tests to match new implementation The only difference between modes is: - SDK mode: runs locally and waits for completion - Cloud mode: runs in cloud sandbox, exits immediately after starting Co-authored-by: openhands <openhands@all-hands.dev>
|
@OpenHands pls merge from main and resolve the conflicts |
|
I'm on it! xingyaoww can track my progress at all-hands.dev |
Resolved conflicts in: - .github/actions/pr-review/action.yml: Added both cloud mode inputs and lmnr-api-key - examples/03_github_workflows/02_pr_review/agent_script.py: Kept cloud mode logic and added Laminar trace handling - examples/03_github_workflows/02_pr_review/README.md: Combined cloud mode docs with observability section Co-authored-by: openhands <openhands@all-hands.dev>
|
Successfully merged Summary of Conflict ResolutionThree files had merge conflicts that were resolved: 1.
|
|
🤖 OpenHands PR Review Started The code review is running in OpenHands Cloud. 📍 Track progress: https://app.all-hands.dev/conversations/8cff5913-4ed8-48c9-9473-e00e443de03f The agent will post a review comment when the analysis is complete. |
✅ Cloud Mode Testing ResultsI tested the cloud mode feature using the Test Configuration
Results
Cloud ConversationThe PR review is running here: https://app.all-hands.dev/conversations/8cff5913-4ed8-48c9-9473-e00e443de03f Minor ObservationThere were some validation warnings about an SummaryThe cloud mode implementation works as expected:
Great work on this feature! 🎉 |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
🤖 OpenHands PR Review Started The code review is running in OpenHands Cloud. 📍 Track progress: https://app.all-hands.dev/conversations/578fcb531dd34ef3b87fe7fd55b29e46 The agent will post a review comment when the analysis is complete. |
Instead of using OpenHandsCloudWorkspace to create a sandbox and then creating a conversation on the agent-server inside it, this change uses the OpenHands Cloud /api/conversations endpoint directly. Benefits: - No LLM credentials needed - cloud uses user's configured LLM - Proper conversation URL that works in the OpenHands Cloud UI - Simpler implementation - just one API call Changes: - Add _start_cloud_conversation() to call Cloud API directly - Update validation to only require LLM_API_KEY for sdk mode - Include GITHUB_TOKEN in the prompt for cloud mode (API doesn't support passing secrets separately) - Update action.yml descriptions to reflect mode differences Tested: Successfully created conversation 578fcb531dd34ef3b87fe7fd55b29e46 Co-authored-by: openhands <openhands@all-hands.dev>
|
Looks like there are a few issues preventing this PR from being merged!
If you'd like me to help, just leave a comment, like Feel free to include any additional details that might help me get this PR into a better state. You can manage your notification settings |
|
@OpenHands pls fix #1966 (review) |
|
I'm on it! xingyaoww can track my progress at all-hands.dev |
- Fix documentation/code mismatch: Update README.md and action.yml to clarify that cloud mode requires both OPENHANDS_CLOUD_API_KEY and LLM_API_KEY (the LLM config is sent to the cloud sandbox) - Replace _make_http_request with requests library for simpler HTTP handling - Add error handling for cloud mode: Post failure comment if conversation.run() fails after posting 'review started' comment - Add openhands-workspace package to action.yml dependencies (required for OpenHandsCloudWorkspace) - Update tests to work with requests library Co-authored-by: openhands <openhands@all-hands.dev>
|
I've addressed the PR review feedback from #1966 (review). The changes have been pushed to the Summary of Changes1. Fixed Documentation/Code Mismatch (Critical Issue #1)
2. Replaced Over-Engineered HTTP Client (Critical Issue #2)
3. Added Error Handling for Cloud Mode (Improvement #6)
4. Fixed Missing Dependency
5. Updated Tests
Checklist
|
|
@OpenHands /codereview-roasted |
|
I'm on it! xingyaoww can track my progress at all-hands.dev |
Code Review Summary for PR #1966: "feat: Add cloud mode for PR review workflow"🔴 Taste Rating: Needs ImprovementI performed a Linus Torvalds-style "roasted" code review of this PR. Here are the key findings: Critical Issues (Must Fix)
Improvement Opportunities
Verdict❌ Needs rework before merging. The Key InsightThe cloud mode implementation tries to be both "fire-and-forget" and "wait for completion". Pick one design and commit to it. No code changes were made - this was a review-only task as requested by |
|
@OpenHands pls address #1966 (comment) keep_alive=True, we should exit the script once we've hit the .run()
We should fix the validation - we should only validate it on the SDK path |
…ional Address review feedback from PR #1966: 1. Cloud mode with keep_alive=True now exits immediately after starting the conversation by using run(blocking=False). This provides the intended 'faster CI completion' benefit where the workflow exits immediately while the review continues asynchronously in the cloud. 2. LLM_API_KEY is now optional for cloud mode - the cloud uses the user's configured LLM settings from their OpenHands Cloud account. SDK mode still requires LLM_API_KEY for local execution. Changes: - agent_script.py: Use run(blocking=False) for cloud mode, make LLM_API_KEY optional with graceful handling - action.yml: Update validation to only require llm-api-key for SDK mode, update description to clarify - tests: Update tests to reflect new behavior - README.md: Update documentation to reflect LLM_API_KEY is optional for cloud mode Co-authored-by: openhands <openhands@all-hands.dev>
|
@OpenHands /codereview-roasted |
|
I'm on it! xingyaoww can track my progress at all-hands.dev |
Code Review Summary for PR #1966: "feat: Add cloud mode for PR review workflow"Taste Rating: 🔴 Needs ImprovementI provided a Linus Torvalds-style "roasted" code review of this PR. No code changes were made - this was a review-only request. Critical Issues Identified:
Improvement Opportunities:
Key Insight:The fundamental issue is that "cloud mode" and "sdk mode" have different data requirements but share the same entry point with conditional logic scattered throughout. A cleaner design would have each mode as a separate, focused module with a thin dispatcher in Verdict: ❌ Needs reworkThe core functionality is sound, but the |
|
@OpenHands Read this PR and investigate all you need to answer me:
|
This comment was marked as outdated.
This comment was marked as outdated.
|
I only answered your questions (no code changes were made). Answers (restated)What cloud account is in use in this code added by this PR?
Key references: Does the code use more than one cloud account (bot vs user)?
Key references:
Clickable links to where any account/credential is usedOpenHands Cloud credential ( GitHub token (
Optional LLM credential (
Checklist against your request
|
|
@OpenHands please merge from main and resolve all conflict, KEEP existing logic from the main branch. We should refactor the agent script to have something that calls |
|
I'm on it! xingyaoww can track my progress at all-hands.dev |
- Merged latest changes from main branch - Refactored agent_script.py to call run_agent_review from separate mode files - Created sdk_mode.py for SDK implementation (local execution) - Created cloud_mode.py for cloud implementation using OpenHandsCloudWorkspace - Updated tests to reflect the new module structure - Kept all existing logic from main branch (GraphQL review context, format_prompt, etc.) Co-authored-by: openhands <openhands@all-hands.dev>
SummaryI've successfully merged from What was done:
Files changed:
The PR is now updated at: #1966 |
- Created utils/ folder with shared agent abstractions - utils/agent_util.py: Shared LLM, Agent, Conversation creation utilities - utils/sdk_mode.py: SDK implementation using shared utilities - utils/cloud_mode.py: Cloud implementation using OpenHandsCloudWorkspace - Updated agent_script.py to import from utils/ - Updated tests to import from new locations Co-authored-by: openhands <openhands@all-hands.dev>
|
[Automatic Post]: It has been a while since there was any activity on this PR. @xingyaoww, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
|
Too much conflict, gonna restart |
Summary
This PR adds a new 'cloud' mode to the PR review workflow that launches reviews in OpenHands Cloud instead of running locally in GitHub Actions. This is inspired by and builds upon PR #1927.
Changes
examples/03_github_workflows/02_pr_review/agent_script.py:MODEenvironment variable support (sdkorcloud)post_github_comment()helper function to post PR comments_start_cloud_conversation()helper function to call OpenHands Cloud APIrun_cloud_mode()function that creates a cloud conversation and posts a comment with the URLrun_sdk_mode()functionOPENHANDS_CLOUD_API_KEY(ignoresLLM_MODELandLLM_BASE_URL).github/actions/pr-review/action.yml:mode,openhands-cloud-api-key,openhands-cloud-api-urlexamples/03_github_workflows/02_pr_review/workflow.yml:modeinput with comment explaining both modesexamples/03_github_workflows/02_pr_review/README.md:tests/github_workflows/test_pr_review_agent.py(new):Cloud Mode Benefits
Usage
SDK Mode (default):
Cloud Mode:
Checklist
@xingyaoww can click here to continue refining the PR
Agent Server images for this PR
• GHCR package: http://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.12-nodejs22golang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:9143041-pythonRun
All tags pushed for this build
About Multi-Architecture Support
9143041-python) is a multi-arch manifest supporting both amd64 and arm649143041-python-amd64) are also available if needed