Skip to content

Conversation

hamiltop
Copy link
Member

  • This change is worth documenting at https://docs.all-hands.dev/
  • Include this change in the Release Notes. If checked, you must provide an end-user friendly description for your change below

End-user friendly description of the problem this fixes or functionality that this introduces.


Give a summary of what the PR does, explaining any non-trivial design decisions.


Link of any specific issues this addresses.

@hamiltop hamiltop changed the base branch from main to release/stable-with-patches April 26, 2025 01:03
@hamiltop hamiltop force-pushed the feat/code-reviewer-impl branch from 215a05e to dc48f12 Compare April 26, 2025 01:33
@hamiltop hamiltop force-pushed the feat/code-reviewer-impl branch from 72f0416 to 225c940 Compare April 26, 2025 02:01
@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

Modify RetryMixin to set temperature to 2.0 (instead of 1.0)
when retrying an LLM call after an LLMNoResponseError if the
original temperature was 0.
@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

Update the message sent by `handle_awaiting_input` to explicitly
instruct the agent to use the `finish` tool with the JSON review
comments, rather than just sending "FINISH". This aims to prevent
the agent from misinterpreting the message as user input and looping.
@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

Based on agent feedback that calculating line numbers from the diff
alone is unreliable, remove instructions telling the agent to do so.
Reinforce the requirement to determine and verify line numbers using
`cat` and `grep -n` on the checked-out files in /workspace.
@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

Strengthen the prompt instructions to state that line numbers MUST
be determined *exclusively* by reading the file content in /workspace
using `cat` and `grep -n`.

Explicitly forbid using the `git diff` output for determining line
numbers.

Update the example `line_number_justification` to remove reference
to the diff hunk.
@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

1 similar comment
@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

Copy link

@phineas-remind101-sandbox phineas-remind101-sandbox bot left a comment

Choose a reason for hiding this comment

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

OpenHands AI Code Review:

General Feedback:

  • The test suite has been updated effectively to cover the new asynchronous methods (test_get_pr_diff_success_async, test_post_review_async, etc.) using pytest.mark.asyncio, unittest.mock.AsyncMock, and patching httpx.AsyncClient. Tests cover success cases, edge cases (like no comments), and error handling scenarios.
  • New tests added for the GitLab interface's async functions (test_gitlab_get_pr_diff_success, test_gitlab_post_review_success). These tests correctly use pytest.mark.asyncio and mock httpx.AsyncClient to simulate API interactions, including fetching MR details and posting discussions (comments). The tests accurately reflect the GitLab API specifics, like expecting a 201 status for comment creation and handling positional comments.
  • This new workflow automates PR reviews using OpenHands. It's well-structured with clear inputs, secrets, triggers, and permissions. The logic for determining the authentication token (App/PAT/Default) and selecting the OpenHands installation source (release branch vs experimental) based on triggers is robust. Environment variables are correctly set up for the review_pr script. Adding steps to dump Docker logs on failure and check the review result enhances debuggability. Consider explicitly defining the permissions needed for the docker commands if they require more than the default.

Line-Specific Feedback: (see comments below)

logger.error(f'Error fetching diff for PR #{pr_number}: {e}')
raise # Re-raise other exceptions

async def post_review(self, pr_number: int, comments: list[ReviewComment]) -> None:

Choose a reason for hiding this comment

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

The post_review function is now asynchronous, using httpx.AsyncClient for making API calls. It intelligently bundles line-specific comments and general feedback into a single review submission, which is efficient. Error handling with try...except blocks and logging for HTTPStatusError and other exceptions are good additions.

thread_ids,
)

async def get_pr_diff(self, pr_number: int) -> str:

Choose a reason for hiding this comment

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

Successfully converted get_pr_diff to an async function using httpx.AsyncClient. The specific 'Accept': 'application/vnd.github.v3.diff' header is correctly used. Error handling and logging for potential HTTPStatusError have been added, ensuring robustness.

)
return stdout.decode(), stderr.decode()

async def checkout_pr(self, pr_number: int, repo_dir: str):

Choose a reason for hiding this comment

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

The checkout_pr function is now asynchronous. It correctly fetches PR details using httpx.AsyncClient and uses a new async helper _run_git_command to execute git commands (clone, fetch, checkout) asynchronously. This improves performance by not blocking the event loop during I/O operations.


return converted_issues

async def post_review(self, pr_number: int, comments: list[ReviewComment]) -> None:

Choose a reason for hiding this comment

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

This function is now async. It first fetches MR details asynchronously to get diff SHAs required for positional comments. Then, it iterates through comments and posts each one as a separate discussion using httpx.AsyncClient. While async, posting comments individually might be less efficient than batching if GitLab supported it. Good error handling is included for both fetching details and posting comments.

)
# Consider raising

async def get_pr_diff(self, pr_number: int) -> str:

Choose a reason for hiding this comment

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

Converted get_pr_diff to async using httpx.AsyncClient. It correctly targets the GitLab diffs endpoint and extracts the diff content from the response list. Includes appropriate error handling and logging, raising exceptions after logging them for upstream handling.

@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

- Make line, code_snippet, line_number_justification mandatory unless review_level=pr
- Add instruction to only use finish tool for output
@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

- Fetch PR diff and head commit SHA before posting review.
- Map head commit line numbers to unified diff positions.
- Use position and commit_id instead of line in GitHub API call.
- Handle cases where line mapping fails by adding to general comments.
- Adds get_pr_head_commit method to GithubPRHandler.
@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

@phineas-remind101-sandbox
Copy link

OpenHands started reviewing the PR! You can monitor the progress here.

Copy link

@phineas-remind101-sandbox phineas-remind101-sandbox bot left a comment

Choose a reason for hiding this comment

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

OpenHands AI Code Review:\n\nGeneral Feedback / Unpositioned Comments:\n- (Unpositioned) /workspace/.github/workflows/openhands-code-reviewer.yml:150: The workflow installs openhands-ai directly from a specific feature branch (feat/code-reviewer-impl) on a fork (remind101/OpenHands). While suitable for testing this PR, this should be updated to point to a stable release tag or the main repository's development/stable branch before this workflow is widely adopted or merged into a stable branch.\n- (Unpositioned) /workspace/.github/workflows/openhands-code-reviewer.yml:316: The filename review_output_${{ env.PR_NUMBER }}.jsonl is specified here for the --output-file argument, implying JSON Lines format. However, the invoked script review_pr.py writes standard JSON. Consider changing the filename extension to .json in this workflow step and subsequent steps (like artifact upload and the post_review_comments script call) for clarity and consistency with the actual file content.\n- (Unpositioned) /workspace/openhands/code_reviewer/post_review_comments.py:123: The help text for the --output-file argument claims the expected file is .jsonl. However, the script correctly uses json.loads which parses standard JSON, consistent with the output of review_pr.py. Update the help text to refer to .json instead of .jsonl.\n\n

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.

2 participants