Skip to content

Commit 6d1ad50

Browse files
authored
Revert "Unrevert "Add username parameter to AsyncBashSession" (#8771)"
This reverts commit 80e496d.
1 parent 80e496d commit 6d1ad50

File tree

4 files changed

+9
-41
lines changed

4 files changed

+9
-41
lines changed

openhands/runtime/action_execution_server.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,7 @@ async def run(
390390
try:
391391
if action.is_static:
392392
path = action.cwd or self._initial_cwd
393-
result = await AsyncBashSession.execute(
394-
action.command, path, self.username
395-
)
393+
result = await AsyncBashSession.execute(action.command, path)
396394
obs = CmdOutputObservation(
397395
content=result.content,
398396
exit_code=result.exit_code,

openhands/runtime/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ async def clone_or_init_repo(
400400
'No repository selected. Initializing a new git repository in the workspace.'
401401
)
402402
action = CmdRunAction(
403-
command=f'git init && git config --global --add safe.directory {self.workspace_root}'
403+
command='git init',
404404
)
405405
self.run_action(action)
406406
else:

openhands/runtime/utils/async_bash.py

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import asyncio
22
import os
3-
import pwd
4-
import sys
5-
from typing import Any, Optional
63

74
from openhands.runtime.base import CommandResult
85

96

107
class AsyncBashSession:
118
@staticmethod
12-
async def execute(
13-
command: str, work_dir: str, username: Optional[str] = None
14-
) -> CommandResult:
9+
async def execute(command: str, work_dir: str) -> CommandResult:
1510
"""Execute a command in the bash session asynchronously."""
1611
work_dir = os.path.abspath(work_dir)
1712

@@ -22,31 +17,12 @@ async def execute(
2217
if not command:
2318
return CommandResult(content='', exit_code=0)
2419

25-
# Create subprocess arguments
26-
subprocess_kwargs: dict[str, Any] = {
27-
'stdout': asyncio.subprocess.PIPE,
28-
'stderr': asyncio.subprocess.PIPE,
29-
'cwd': work_dir,
30-
}
31-
32-
# Only apply user-specific settings on non-Windows platforms
33-
if username and sys.platform != 'win32':
34-
try:
35-
user_info = pwd.getpwnam(username)
36-
env: dict[str, str] = {
37-
'HOME': user_info.pw_dir,
38-
'USER': username,
39-
'LOGNAME': username,
40-
}
41-
subprocess_kwargs['env'] = env
42-
subprocess_kwargs['user'] = username
43-
except KeyError:
44-
raise ValueError(f'User {username} does not exist.')
45-
46-
# Prepare to run the command
4720
try:
4821
process = await asyncio.subprocess.create_subprocess_shell(
49-
command, **subprocess_kwargs
22+
command,
23+
stdout=asyncio.subprocess.PIPE,
24+
stderr=asyncio.subprocess.PIPE,
25+
cwd=work_dir,
5026
)
5127

5228
try:

tests/unit/test_runtime_git_tokens.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ async def test_clone_or_init_repo_no_repo_with_user_id(temp_dir):
234234
# Verify that git init was called
235235
assert len(runtime.run_action_calls) == 1
236236
assert isinstance(runtime.run_action_calls[0], CmdRunAction)
237-
assert (
238-
runtime.run_action_calls[0].command
239-
== f'git init && git config --global --add safe.directory {runtime.workspace_root}'
240-
)
237+
assert runtime.run_action_calls[0].command == 'git init'
241238
assert result == ''
242239

243240

@@ -258,10 +255,7 @@ async def test_clone_or_init_repo_no_repo_no_user_id_no_workspace_base(temp_dir)
258255
# Verify that git init was called
259256
assert len(runtime.run_action_calls) == 1
260257
assert isinstance(runtime.run_action_calls[0], CmdRunAction)
261-
assert (
262-
runtime.run_action_calls[0].command
263-
== f'git init && git config --global --add safe.directory {runtime.workspace_root}'
264-
)
258+
assert runtime.run_action_calls[0].command == 'git init'
265259
assert result == ''
266260

267261

0 commit comments

Comments
 (0)