Fix Bash commands now do not block and actually respect the timeout (#4058)

This commit is contained in:
tofarr
2024-09-27 18:40:00 -06:00
committed by GitHub
parent 575a829d94
commit 5ccee7c8a7
2 changed files with 11 additions and 2 deletions

View File

@@ -323,7 +323,13 @@ class RuntimeClient:
logger.debug('Requesting exit code...')
self.shell.expect(self.__bash_expect_regex, timeout=timeout)
_exit_code_output = self.shell.before
exit_code = int(_exit_code_output.strip().split()[0])
try:
exit_code = int(_exit_code_output.strip().split()[0])
except:
logger.error('Error getting exit code from bash script')
# If we try to run an invalid shell script the output sometimes includes error text
# rather than the error code - we assume this is an error
exit_code = 2
except pexpect.TIMEOUT as e:
if kill_on_timeout:
@@ -622,7 +628,7 @@ if __name__ == '__main__':
observation = await client.run_action(action)
return event_to_dict(observation)
except Exception as e:
logger.error(f'Error processing command: {str(e)}')
logger.error(f'Error processing command: {str(e)}', exc_info=True, stack_info=True)
raise HTTPException(status_code=500, detail=str(e))
@app.post('/upload_file')

View File

@@ -162,6 +162,9 @@ class Session:
'Model does not support image upload, change to a different model or try without an image.'
)
return
asyncio.run_coroutine_threadsafe(self._add_event(event, EventSource.USER), self.agent_session.loop) # type: ignore
async def _add_event(self, event, event_source):
self.agent_session.event_stream.add_event(event, EventSource.USER)
async def send(self, data: dict[str, object]) -> bool: