client runtime: fix config passing on init; added logging (#3233)

This commit is contained in:
tobitege 2024-08-03 04:37:38 +02:00 committed by GitHub
parent a1fec393ac
commit 1166b0e610
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,5 @@
import asyncio
import copy
import os
import tempfile
import uuid
@ -49,6 +50,7 @@ class EventStreamRuntime(Runtime):
plugins: list[PluginRequirement] | None = None,
container_image: str | None = None,
):
self.config = copy.deepcopy(config)
super().__init__(
config, event_stream, sid, plugins
) # will initialize the event stream
@ -136,12 +138,15 @@ class EventStreamRuntime(Runtime):
if mount_dir is not None:
volumes = {mount_dir: {'bind': sandbox_workspace_dir, 'mode': 'rw'}}
logger.info(f'Mount dir: {sandbox_workspace_dir}')
else:
logger.warn(
'Mount dir is not set, will not mount the workspace directory to the container.'
)
volumes = None
logger.info(f'run_as_devin: `{self.config.run_as_devin}`')
container = self.docker_client.containers.run(
self.container_image,
command=(
@ -170,26 +175,25 @@ class EventStreamRuntime(Runtime):
raise e
async def _ensure_session(self):
await asyncio.sleep(1)
if self.session is None or self.session.closed:
self.session = aiohttp.ClientSession()
return self.session
@tenacity.retry(
stop=tenacity.stop_after_attempt(10),
wait=tenacity.wait_exponential(multiplier=2, min=4, max=600),
wait=tenacity.wait_exponential(multiplier=2, min=4, max=60),
)
async def _wait_until_alive(self):
logger.info('Reconnecting session')
async with aiohttp.ClientSession() as session:
async with session.get(f'{self.api_url}/alive') as response:
if response.status == 200:
return
else:
logger.error(
f'Action execution API is not alive. Response: {response}'
)
raise RuntimeError(
f'Action execution API is not alive. Response: {response}'
)
msg = f'Action execution API is not alive. Response: {response}'
logger.error(msg)
raise RuntimeError(msg)
@property
def sandbox_workspace_dir(self):
@ -278,12 +282,14 @@ class EventStreamRuntime(Runtime):
f'Action {action_type} is not supported in the current runtime.'
)
logger.info('Awaiting session')
session = await self._ensure_session()
await self._wait_until_alive()
assert action.timeout is not None
try:
logger.info('Executing command')
async with session.post(
f'{self.api_url}/execute_action',
json={'action': event_to_dict(action)},