Skip to content

Commit

Permalink
Merge branch 'main' into openhands-fix-issue-5179
Browse files Browse the repository at this point in the history
  • Loading branch information
neubig authored Nov 23, 2024
2 parents b347226 + a2779fe commit 125ca38
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/openhands-resolver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ on:
required: false
type: string
default: "@openhands-agent"
target_branch:
required: false
type: string
default: "main"
description: "Target branch to pull and create PR against"
secrets:
LLM_MODEL:
required: true
Expand Down Expand Up @@ -48,12 +53,12 @@ jobs:
(
((github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment') &&
startsWith(github.event.comment.body, inputs.macro || '@openhands-agent') &&
contains(github.event.comment.body, inputs.macro || '@openhands-agent') &&
(github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'MEMBER')
) ||
(github.event_name == 'pull_request_review' &&
startsWith(github.event.review.body, inputs.macro || '@openhands-agent') &&
contains(github.event.review.body, inputs.macro || '@openhands-agent') &&
(github.event.review.author_association == 'OWNER' || github.event.review.author_association == 'COLLABORATOR' || github.event.review.author_association == 'MEMBER')
)
)
Expand All @@ -80,11 +85,11 @@ jobs:
github.event.label.name == 'fix-me-experimental' ||
(
(github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment') &&
startsWith(github.event.comment.body, '@openhands-agent-exp')
contains(github.event.comment.body, '@openhands-agent-exp')
) ||
(
github.event_name == 'pull_request_review' &&
startsWith(github.event.review.body, '@openhands-agent-exp')
contains(github.event.review.body, '@openhands-agent-exp')
)
)
uses: actions/cache@v3
Expand Down Expand Up @@ -135,6 +140,9 @@ jobs:
echo "MAX_ITERATIONS=${{ inputs.max_iterations || 50 }}" >> $GITHUB_ENV
echo "SANDBOX_ENV_GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
# Set branch variables
echo "TARGET_BRANCH=${{ inputs.target_branch }}" >> $GITHUB_ENV
- name: Comment on issue with start message
uses: actions/github-script@v7
with:
Expand Down Expand Up @@ -175,7 +183,7 @@ jobs:
--issue-number ${{ env.ISSUE_NUMBER }} \
--issue-type ${{ env.ISSUE_TYPE }} \
--max-iterations ${{ env.MAX_ITERATIONS }} \
--comment-id ${{ env.COMMENT_ID }}
--comment-id ${{ env.COMMENT_ID }} \
- name: Check resolution result
id: check_result
Expand Down
30 changes: 28 additions & 2 deletions openhands/resolver/resolve_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ async def resolve_issue(
repo_instruction: str | None,
issue_number: int,
comment_id: int | None,
target_branch: str | None = None,
reset_logger: bool = False,
) -> None:
"""Resolve a single github issue.
Expand All @@ -333,6 +334,7 @@ async def resolve_issue(
repo_instruction: Repository instruction to use.
issue_number: Issue number to resolve.
comment_id: Optional ID of a specific comment to focus on.
target_branch: Optional target branch to create PR against (for PRs).
reset_logger: Whether to reset the logger for multiprocessing.
"""
issue_handler = issue_handler_factory(issue_type, owner, repo, token)
Expand Down Expand Up @@ -422,15 +424,32 @@ async def resolve_issue(
try:
# checkout to pr branch if needed
if issue_type == 'pr':
branch_to_use = target_branch if target_branch else issue.head_branch
logger.info(
f'Checking out to PR branch {issue.head_branch} for issue {issue.number}'
f'Checking out to PR branch {target_branch} for issue {issue.number}'
)

if not branch_to_use:
raise ValueError('Branch name cannot be None')

# Fetch the branch first to ensure it exists locally
fetch_cmd = ['git', 'fetch', 'origin', branch_to_use]
subprocess.check_output(
fetch_cmd,
cwd=repo_dir,
)

# Checkout the branch
checkout_cmd = ['git', 'checkout', branch_to_use]
subprocess.check_output(
['git', 'checkout', f'{issue.head_branch}'],
checkout_cmd,
cwd=repo_dir,
)

# Update issue's base_branch if using custom target branch
if target_branch:
issue.base_branch = target_branch

base_commit = (
subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo_dir)
.decode('utf-8')
Expand Down Expand Up @@ -553,6 +572,12 @@ def int_or_none(value):
choices=['issue', 'pr'],
help='Type of issue to resolve, either open issue or pr comments.',
)
parser.add_argument(
'--target-branch',
type=str,
default=None,
help="Target branch to pull and create PR against (for PRs). If not specified, uses the PR's base branch.",
)

my_args = parser.parse_args()

Expand Down Expand Up @@ -613,6 +638,7 @@ def int_or_none(value):
repo_instruction=repo_instruction,
issue_number=my_args.issue_number,
comment_id=my_args.comment_id,
target_branch=my_args.target_branch,
)
)

Expand Down
1 change: 1 addition & 0 deletions openhands/runtime/impl/modal/modal_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def _init_sandbox(
self.config.sandbox.user_id,
plugin_args,
browsergym_args,
is_root=not self.config.run_as_openhands, # is_root=True when running as root
)
self.log('debug', f'Starting container with command: {sandbox_start_cmd}')
self.sandbox = modal.Sandbox.create(
Expand Down
1 change: 1 addition & 0 deletions openhands/runtime/impl/remote/remote_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def _start_runtime(self):
self.config.sandbox.user_id,
plugin_args,
browsergym_args,
is_root=not self.config.run_as_openhands, # is_root=True when running as root
)
start_request = {
'image': self.container_image,
Expand Down
1 change: 1 addition & 0 deletions openhands/runtime/impl/runloop/runloop_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def _create_new_devbox(self) -> DevboxView:
self.config.sandbox.user_id,
plugin_args,
browsergym_args,
is_root=not self.config.run_as_openhands, # is_root=True when running as root
)

# Add some additional commands based on our image
Expand Down
18 changes: 17 additions & 1 deletion openhands/runtime/utils/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ def get_remote_startup_command(
user_id: int,
plugin_args: list[str],
browsergym_args: list[str],
is_root: bool = False,
):
return [
base_cmd = [
'/openhands/micromamba/bin/micromamba',
'run',
'-n',
Expand All @@ -27,3 +28,18 @@ def get_remote_startup_command(
str(user_id),
*browsergym_args,
]

if is_root:
# If running as root, set highest priority and lowest OOM score
cmd_str = ' '.join(base_cmd)
return [
'nice',
'-n',
'-20', # Highest priority
'sh',
'-c',
f'echo -1000 > /proc/self/oom_score_adj && exec {cmd_str}'
]
else:
# If not root, run with normal priority
return base_cmd

0 comments on commit 125ca38

Please sign in to comment.