From c76809a766cdbf44f418ac2944c519cf86a7352c Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Wed, 28 May 2025 14:28:26 -0400 Subject: [PATCH] Revert "Add username parameter to AsyncBashSession" (#8767) --- openhands/runtime/action_execution_server.py | 4 +--- openhands/runtime/base.py | 2 +- openhands/runtime/utils/async_bash.py | 17 +---------------- tests/unit/test_runtime_git_tokens.py | 10 ++-------- 4 files changed, 5 insertions(+), 28 deletions(-) diff --git a/openhands/runtime/action_execution_server.py b/openhands/runtime/action_execution_server.py index 4e1f5b96aa..30a48df1a5 100644 --- a/openhands/runtime/action_execution_server.py +++ b/openhands/runtime/action_execution_server.py @@ -390,9 +390,7 @@ class ActionExecutor: try: if action.is_static: path = action.cwd or self._initial_cwd - result = await AsyncBashSession.execute( - action.command, path, self.username - ) + result = await AsyncBashSession.execute(action.command, path) obs = CmdOutputObservation( content=result.content, exit_code=result.exit_code, diff --git a/openhands/runtime/base.py b/openhands/runtime/base.py index a7950d4c08..92a3a707a8 100644 --- a/openhands/runtime/base.py +++ b/openhands/runtime/base.py @@ -346,7 +346,7 @@ class Runtime(FileEditRuntimeMixin): 'No repository selected. Initializing a new git repository in the workspace.' ) action = CmdRunAction( - command=f'git init && git config --global --add safe.directory {self.workspace_root}' + command='git init', ) self.run_action(action) else: diff --git a/openhands/runtime/utils/async_bash.py b/openhands/runtime/utils/async_bash.py index 3df675d610..b7ac3823e5 100644 --- a/openhands/runtime/utils/async_bash.py +++ b/openhands/runtime/utils/async_bash.py @@ -1,15 +1,12 @@ import asyncio import os -import pwd from openhands.runtime.base import CommandResult class AsyncBashSession: @staticmethod - async def execute( - command: str, work_dir: str, username: str | None = None - ) -> CommandResult: + async def execute(command: str, work_dir: str) -> CommandResult: """Execute a command in the bash session asynchronously.""" work_dir = os.path.abspath(work_dir) @@ -20,24 +17,12 @@ class AsyncBashSession: if not command: return CommandResult(content='', exit_code=0) - env = {} - if username: - try: - user_info = pwd.getpwnam(username) - env['HOME'] = user_info.pw_dir - env['USER'] = username - env['LOGNAME'] = username - except KeyError: - raise ValueError(f'User {username} does not exist.') - # Prepare to run the command try: process = await asyncio.subprocess.create_subprocess_shell( command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, cwd=work_dir, - user=username, - env=env, ) try: diff --git a/tests/unit/test_runtime_git_tokens.py b/tests/unit/test_runtime_git_tokens.py index 7bf7ac0996..8a3f6f4c26 100644 --- a/tests/unit/test_runtime_git_tokens.py +++ b/tests/unit/test_runtime_git_tokens.py @@ -234,10 +234,7 @@ async def test_clone_or_init_repo_no_repo_with_user_id(temp_dir): # Verify that git init was called assert len(runtime.run_action_calls) == 1 assert isinstance(runtime.run_action_calls[0], CmdRunAction) - assert ( - runtime.run_action_calls[0].command - == f'git init && git config --global --add safe.directory {runtime.workspace_root}' - ) + assert runtime.run_action_calls[0].command == 'git init' assert result == '' @@ -258,10 +255,7 @@ async def test_clone_or_init_repo_no_repo_no_user_id_no_workspace_base(temp_dir) # Verify that git init was called assert len(runtime.run_action_calls) == 1 assert isinstance(runtime.run_action_calls[0], CmdRunAction) - assert ( - runtime.run_action_calls[0].command - == f'git init && git config --global --add safe.directory {runtime.workspace_root}' - ) + assert runtime.run_action_calls[0].command == 'git init' assert result == ''