Skip to content

Commit a839bfb

Browse files
committed
revert All-Hands-AI#3233 but more logging
1 parent a889388 commit a839bfb

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

opendevin/runtime/client/runtime.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import copy
32
import os
43
import tempfile
54
import uuid
@@ -50,7 +49,6 @@ def __init__(
5049
plugins: list[PluginRequirement] | None = None,
5150
container_image: str | None = None,
5251
):
53-
self.config = copy.deepcopy(config)
5452
super().__init__(
5553
config, event_stream, sid, plugins
5654
) # will initialize the event stream
@@ -72,6 +70,9 @@ def __init__(
7270

7371
self.container = None
7472
self.action_semaphore = asyncio.Semaphore(1) # Ensure one action at a time
73+
logger.info(
74+
f'EventStreamRuntime `{sid}` __init__ run_as_devin: {self.config.run_as_devin}'
75+
)
7576

7677
async def ainit(self, env_vars: dict[str, str] | None = None):
7778
self.container_image = build_runtime_image(
@@ -145,7 +146,7 @@ async def _init_container(
145146
)
146147
volumes = None
147148

148-
logger.info(f'run_as_devin: `{self.config.run_as_devin}`')
149+
logger.info(f'_init_container run_as_devin: {self.config.run_as_devin}')
149150

150151
container = self.docker_client.containers.run(
151152
self.container_image,

opendevin/runtime/runtime.py

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def __init__(
7070
self.config = copy.deepcopy(config)
7171
self.DEFAULT_ENV_VARS = _default_env_vars(config.sandbox)
7272
atexit.register(self.close_sync)
73+
logger.info(
74+
f'Runtime `{sid}` __init__ run_as_devin = {self.config.run_as_devin}'
75+
)
7376

7477
async def ainit(self, env_vars: dict[str, str] | None = None) -> None:
7578
"""

opendevin/runtime/server/runtime.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import copy
21
from typing import Any, Optional
32

43
from opendevin.core.config import AppConfig
@@ -44,7 +43,6 @@ def __init__(
4443
plugins: list[PluginRequirement] | None = None,
4544
sandbox: Sandbox | None = None,
4645
):
47-
self.config = copy.deepcopy(config)
4846
super().__init__(config, event_stream, sid, plugins)
4947
self.file_store = LocalFileStore(config.workspace_base)
5048
if sandbox is None:
@@ -54,6 +52,9 @@ def __init__(
5452
self.sandbox = sandbox
5553
self._is_external_sandbox = True
5654
self.browser: BrowserEnv | None = None
55+
logger.info(
56+
f'ServerRuntime {sid} __init__ run_as_devin = {self.config.run_as_devin}'
57+
)
5758

5859
def create_sandbox(self, sid: str = 'default', box_type: str = 'ssh') -> Sandbox:
5960
if box_type == 'local':

tests/unit/test_runtime.py

+34-14
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_box_classes():
5858
elif runtime.lower() == 'server':
5959
return [ServerRuntime]
6060
else:
61-
return [EventStreamRuntime, ServerRuntime]
61+
return [ServerRuntime, EventStreamRuntime]
6262

6363

6464
# This assures that all tests run together per runtime, not alternating between them,
@@ -141,9 +141,6 @@ async def _load_runtime(
141141
runtime = ServerRuntime(
142142
config=config, event_stream=event_stream, sid=sid, plugins=plugins
143143
)
144-
assert (
145-
runtime.sandbox.run_as_devin == run_as_devin
146-
), f'run_as_devin in sandbox should be {run_as_devin}'
147144
await runtime.ainit()
148145
from opendevin.runtime.tools import (
149146
RuntimeTool, # deprecate this after ServerRuntime is deprecated
@@ -792,6 +789,9 @@ async def test_ipython_simple(temp_dir, box_class):
792789
logger.info(obs, extra={'msg_type': 'OBSERVATION'})
793790
assert obs.content.strip() == '1'
794791

792+
await runtime.close()
793+
await asyncio.sleep(1)
794+
795795

796796
async def _test_ipython_agentskills_fileop_pwd_impl(
797797
runtime: ServerRuntime | EventStreamRuntime, enable_auto_lint: bool
@@ -904,40 +904,45 @@ async def _test_ipython_agentskills_fileop_pwd_impl(
904904

905905

906906
@pytest.mark.asyncio
907-
async def test_ipython_agentskills_fileop_pwd(temp_dir, box_class, enable_auto_lint):
907+
async def test_ipython_agentskills_fileop_pwd(
908+
temp_dir, box_class, run_as_devin, enable_auto_lint
909+
):
908910
"""Make sure that cd in bash also update the current working directory in ipython."""
909911

910912
runtime = await _load_runtime(
911-
temp_dir, box_class, enable_auto_lint=enable_auto_lint
913+
temp_dir, box_class, run_as_devin, enable_auto_lint=enable_auto_lint
912914
)
913915
await _test_ipython_agentskills_fileop_pwd_impl(runtime, enable_auto_lint)
916+
914917
await runtime.close()
915918
await asyncio.sleep(1)
916919

917920

918-
@pytest.mark.skipif(
919-
TEST_RUNTIME.lower() == 'eventstream',
920-
reason='Skip this if we want to test EventStreamRuntime',
921-
)
922921
@pytest.mark.skipif(
923922
os.environ.get('TEST_IN_CI', 'false').lower() == 'true',
924923
# FIXME: There's some weird issue with the CI environment.
925924
reason='Skip this if in CI.',
926925
)
927926
@pytest.mark.asyncio
928927
async def test_ipython_agentskills_fileop_pwd_agnostic_sandbox(
929-
temp_dir, enable_auto_lint, container_image
928+
temp_dir, box_class, run_as_devin, enable_auto_lint, container_image
930929
):
931-
"""Make sure that cd in bash also update the current working directory in ipython."""
930+
"""Make sure that cd in bash also updates the current working directory in iPython."""
931+
932+
# NOTE: we only test for ServerRuntime, since EventStreamRuntime
933+
# is image agnostic by design.
934+
if box_class != 'server':
935+
pytest.skip('Skip this if box_class is not server')
932936

933937
runtime = await _load_runtime(
934938
temp_dir,
935-
# NOTE: we only test for ServerRuntime, since EventStreamRuntime is image agnostic by design.
936-
ServerRuntime,
939+
box_class,
940+
run_as_devin,
937941
enable_auto_lint=enable_auto_lint,
938942
container_image=container_image,
939943
)
940944
await _test_ipython_agentskills_fileop_pwd_impl(runtime, enable_auto_lint)
945+
941946
await runtime.close()
942947
await asyncio.sleep(1)
943948

@@ -1030,6 +1035,9 @@ async def test_copy_single_file(temp_dir, box_class):
10301035
assert obs.exit_code == 0
10311036
assert 'Hello, World!' in obs.content
10321037

1038+
await runtime.close()
1039+
await asyncio.sleep(1)
1040+
10331041

10341042
def _create_test_dir_with_files(host_temp_dir):
10351043
os.mkdir(os.path.join(host_temp_dir, 'test_dir'))
@@ -1077,6 +1085,9 @@ async def test_copy_directory_recursively(temp_dir, box_class):
10771085
assert obs.exit_code == 0
10781086
assert 'File 1 content' in obs.content
10791087

1088+
await runtime.close()
1089+
await asyncio.sleep(1)
1090+
10801091

10811092
@pytest.mark.asyncio
10821093
async def test_copy_to_non_existent_directory(temp_dir, box_class):
@@ -1096,6 +1107,9 @@ async def test_copy_to_non_existent_directory(temp_dir, box_class):
10961107
assert obs.exit_code == 0
10971108
assert 'Hello, World!' in obs.content
10981109

1110+
await runtime.close()
1111+
await asyncio.sleep(1)
1112+
10991113

11001114
@pytest.mark.asyncio
11011115
async def test_overwrite_existing_file(temp_dir, box_class):
@@ -1131,6 +1145,9 @@ async def test_overwrite_existing_file(temp_dir, box_class):
11311145
assert obs.exit_code == 0
11321146
assert 'Hello, World!' in obs.content
11331147

1148+
await runtime.close()
1149+
await asyncio.sleep(1)
1150+
11341151

11351152
@pytest.mark.asyncio
11361153
async def test_copy_non_existent_file(temp_dir, box_class):
@@ -1148,3 +1165,6 @@ async def test_copy_non_existent_file(temp_dir, box_class):
11481165
logger.info(obs, extra={'msg_type': 'OBSERVATION'})
11491166
assert isinstance(obs, CmdOutputObservation)
11501167
assert obs.exit_code != 0 # File should not exist
1168+
1169+
await runtime.close()
1170+
await asyncio.sleep(1)

0 commit comments

Comments
 (0)