|
1 | 1 | import asyncio
|
| 2 | +import copy |
2 | 3 | import os
|
3 | 4 | import tempfile
|
4 | 5 | import uuid
|
@@ -49,6 +50,7 @@ def __init__(
|
49 | 50 | plugins: list[PluginRequirement] | None = None,
|
50 | 51 | container_image: str | None = None,
|
51 | 52 | ):
|
| 53 | + self.config = copy.deepcopy(config) |
52 | 54 | super().__init__(
|
53 | 55 | config, event_stream, sid, plugins
|
54 | 56 | ) # will initialize the event stream
|
@@ -136,12 +138,15 @@ async def _init_container(
|
136 | 138 |
|
137 | 139 | if mount_dir is not None:
|
138 | 140 | volumes = {mount_dir: {'bind': sandbox_workspace_dir, 'mode': 'rw'}}
|
| 141 | + logger.info(f'Mount dir: {sandbox_workspace_dir}') |
139 | 142 | else:
|
140 | 143 | logger.warn(
|
141 | 144 | 'Mount dir is not set, will not mount the workspace directory to the container.'
|
142 | 145 | )
|
143 | 146 | volumes = None
|
144 | 147 |
|
| 148 | + logger.info(f'run_as_devin: `{self.config.run_as_devin}`') |
| 149 | + |
145 | 150 | container = self.docker_client.containers.run(
|
146 | 151 | self.container_image,
|
147 | 152 | command=(
|
@@ -170,26 +175,25 @@ async def _init_container(
|
170 | 175 | raise e
|
171 | 176 |
|
172 | 177 | async def _ensure_session(self):
|
| 178 | + await asyncio.sleep(1) |
173 | 179 | if self.session is None or self.session.closed:
|
174 | 180 | self.session = aiohttp.ClientSession()
|
175 | 181 | return self.session
|
176 | 182 |
|
177 | 183 | @tenacity.retry(
|
178 | 184 | stop=tenacity.stop_after_attempt(10),
|
179 |
| - wait=tenacity.wait_exponential(multiplier=2, min=4, max=600), |
| 185 | + wait=tenacity.wait_exponential(multiplier=2, min=4, max=60), |
180 | 186 | )
|
181 | 187 | async def _wait_until_alive(self):
|
| 188 | + logger.info('Reconnecting session') |
182 | 189 | async with aiohttp.ClientSession() as session:
|
183 | 190 | async with session.get(f'{self.api_url}/alive') as response:
|
184 | 191 | if response.status == 200:
|
185 | 192 | return
|
186 | 193 | else:
|
187 |
| - logger.error( |
188 |
| - f'Action execution API is not alive. Response: {response}' |
189 |
| - ) |
190 |
| - raise RuntimeError( |
191 |
| - f'Action execution API is not alive. Response: {response}' |
192 |
| - ) |
| 194 | + msg = f'Action execution API is not alive. Response: {response}' |
| 195 | + logger.error(msg) |
| 196 | + raise RuntimeError(msg) |
193 | 197 |
|
194 | 198 | @property
|
195 | 199 | def sandbox_workspace_dir(self):
|
@@ -278,12 +282,14 @@ async def run_action(self, action: Action) -> Observation:
|
278 | 282 | f'Action {action_type} is not supported in the current runtime.'
|
279 | 283 | )
|
280 | 284 |
|
| 285 | + logger.info('Awaiting session') |
281 | 286 | session = await self._ensure_session()
|
282 | 287 | await self._wait_until_alive()
|
283 | 288 |
|
284 | 289 | assert action.timeout is not None
|
285 | 290 |
|
286 | 291 | try:
|
| 292 | + logger.info('Executing command') |
287 | 293 | async with session.post(
|
288 | 294 | f'{self.api_url}/execute_action',
|
289 | 295 | json={'action': event_to_dict(action)},
|
|
0 commit comments