Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent docker session #1998

Merged
merged 31 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
035229c
Persistent docker session
SmartManoj May 23, 2024
570141b
Merge branch 'main' into docker
SmartManoj May 23, 2024
700f76d
Removed outdated comment
SmartManoj May 23, 2024
6e5432c
made persist_session as default
SmartManoj May 23, 2024
eaffd72
disabled sandbox persistence in tests
SmartManoj May 24, 2024
24d7d0e
disabled sandbox persistence in tests
SmartManoj May 24, 2024
96e09a2
Merge branch 'main' into docker
SmartManoj May 24, 2024
25ce84c
Merge branch 'main' into docker
SmartManoj May 24, 2024
e7e8ed3
Merge branch 'main' into docker
neubig May 24, 2024
8256155
disabled removing persistant sandbox
SmartManoj May 24, 2024
9b9b070
Merge branch 'main' into docker
SmartManoj May 24, 2024
5f95303
Merge branch 'docker' of https://github.com/SmartManoj/Kevin into docker
SmartManoj May 24, 2024
38be74d
revert timeout change
SmartManoj May 24, 2024
0d2cb2d
Merge branch 'main' into docker
SmartManoj May 25, 2024
9a1d29b
load bashrc
SmartManoj May 25, 2024
c6b7f56
Merge branch 'main' into docker
SmartManoj May 25, 2024
4892a0a
Merge branch 'main' into docker
SmartManoj May 25, 2024
24b8105
fixed actions
SmartManoj May 25, 2024
39b09f5
fixed actions
SmartManoj May 25, 2024
516e629
Merge branch 'main' into docker
SmartManoj May 26, 2024
031f7e3
Merge branch 'main' into docker
SmartManoj May 27, 2024
a1eeb70
Merge branch 'main' into docker
SmartManoj May 27, 2024
b6a685e
Merge branch 'main' into docker
SmartManoj May 27, 2024
4da9605
reverted reset changes
SmartManoj May 27, 2024
ce293f6
Merge branch 'main' into docker
SmartManoj May 27, 2024
054d88d
removed default password
SmartManoj May 28, 2024
40073e0
Merge branch 'main' into docker
SmartManoj May 28, 2024
5ea6138
Update dummy-agent-test.yml
SmartManoj May 28, 2024
8511f42
Merge branch 'docker' of https://github.com/SmartManoj/Kevin into docker
SmartManoj May 28, 2024
cda7105
Update intro.mdx
SmartManoj May 28, 2024
9d5f411
Merge branch 'main' into docker
SmartManoj May 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/run-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
- 'evaluation/**'
pull_request:

env:
PERSIST_SANDBOX : "false"

jobs:
integration-tests-on-linux:
name: Integration Tests on Linux
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/run-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
- 'evaluation/**'
pull_request:

env:
PERSIST_SANDBOX : "false"

jobs:
test-on-macos:
name: Test on macOS
Expand Down
2 changes: 1 addition & 1 deletion agenthub/codeact_agent/codeact_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def step(self, state: State) -> Action:
{'role': 'system', 'content': self.system_message},
{
'role': 'user',
'content': f"Here is an example of how you can interact with the environment for task solving:\n{EXAMPLES}\n\nNOW, LET'S START!",
'content': f"Here is an example of how you can interact with the environment for task solving:\n{EXAMPLES}\n\nNOW, LET'S START!\n",
},
]

Expand Down
4 changes: 4 additions & 0 deletions opendevin/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ class AppConfig(metaclass=Singleton):
disable_color: bool = False
sandbox_user_id: int = os.getuid() if hasattr(os, 'getuid') else 1000
sandbox_timeout: int = 120
persist_sandbox: bool = True
ssh_port: int = 63710
# https://xkcd.com/936/
ssh_password: str = 'correct horse battery staple1'
github_token: str | None = None
jwt_secret: str = uuid.uuid4().hex
debug: bool = False
Expand Down
1 change: 1 addition & 0 deletions opendevin/core/schema/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


class ConfigType(str, Enum):
# For frontend
LLM_CUSTOM_LLM_PROVIDER = 'LLM_CUSTOM_LLM_PROVIDER'
LLM_MAX_INPUT_TOKENS = 'LLM_MAX_INPUT_TOKENS'
LLM_MAX_OUTPUT_TOKENS = 'LLM_MAX_OUTPUT_TOKENS'
Expand Down
70 changes: 42 additions & 28 deletions opendevin/runtime/docker/ssh_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,38 +216,46 @@ def __init__(
)
raise ex

self.instance_id = (
sid + str(uuid.uuid4()) if sid is not None else str(uuid.uuid4())
)
if config.persist_sandbox:
self.instance_id = 'persisted'
else:
self.instance_id = (sid or '') + str(uuid.uuid4())

self.timeout = timeout
self.container_image = (
config.sandbox_container_image
if container_image is None
else container_image
)
self.container_image = container_image or config.sandbox_container_image
self.container_name = self.container_name_prefix + self.instance_id

# set up random user password
self._ssh_password = str(uuid.uuid4())
self._ssh_port = find_available_tcp_port()

# always restart the container, cuz the initial be regarded as a new session
n_tries = 5
while n_tries > 0:
try:
self.restart_docker_container()
break
except Exception as e:
logger.exception(
'Failed to start Docker container, retrying...', exc_info=False
)
n_tries -= 1
if n_tries == 0:
raise e
time.sleep(5)
self.setup_user()

if config.persist_sandbox:
self._ssh_password = config.ssh_password
self._ssh_port = config.ssh_port
else:
self._ssh_password = str(uuid.uuid4())
self._ssh_port = find_available_tcp_port()
try:
docker.DockerClient().containers.get(self.container_name)
is_initial_session = False
except docker.errors.NotFound:
is_initial_session = True
logger.info('Creating new Docker container')
if not config.persist_sandbox or is_initial_session:
n_tries = 5
while n_tries > 0:
try:
self.restart_docker_container()
break
except Exception as e:
logger.exception(
'Failed to start Docker container, retrying...', exc_info=False
)
n_tries -= 1
if n_tries == 0:
raise e
time.sleep(5)
self.setup_user()
else:
self.container = self.docker_client.containers.get(self.container_name)
logger.info('Using existing Docker container')
try:
self.start_ssh_session()
except pxssh.ExceptionPxssh as e:
Expand Down Expand Up @@ -391,6 +399,9 @@ def start_ssh_session(self):
# cd to workspace
self.ssh.sendline(f'cd {self.sandbox_workspace_dir}')
self.ssh.prompt()
# load bashrc
self.ssh.sendline('source ~/.bashrc')
self.ssh.prompt()

def get_exec_cmd(self, cmd: str) -> list[str]:
if self.run_as_devin:
Expand Down Expand Up @@ -704,7 +715,10 @@ def close(self):
containers = self.docker_client.containers.list(all=True)
for container in containers:
try:
if container.name.startswith(self.container_name):
if (
container.name.startswith(self.container_name)
and not config.persist_sandbox
):
# only remove the container we created
# otherwise all other containers with the same prefix will be removed
# which will mess up with parallel evaluation
Expand Down
2 changes: 1 addition & 1 deletion opendevin/runtime/plugins/jupyter/execute_server
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class JupyterKernel:
)
self.heartbeat_callback.start()

async def execute(self, code, timeout=60):
async def execute(self, code, timeout=120):
if not self.ws:
await self._connect()

Expand Down