From 6ca0cd956ac223622560ea5646c63129a21cb96b Mon Sep 17 00:00:00 2001 From: Yazhou Cao Date: Mon, 22 Jul 2024 17:35:16 +0800 Subject: [PATCH] Remove health/liveness checking code --- vision_agent/utils/execute.py | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/vision_agent/utils/execute.py b/vision_agent/utils/execute.py index 3dc571c2..c37dcbb0 100644 --- a/vision_agent/utils/execute.py +++ b/vision_agent/utils/execute.py @@ -29,7 +29,6 @@ from typing_extensions import Self from vision_agent.utils.exceptions import ( - RemoteSandboxClosedError, RemoteSandboxCreationError, RemoteSandboxExecutionError, ) @@ -448,7 +447,9 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: print(f"Vision Agent version: {va_version}")""" ) sys_versions = "\n".join(result.logs.stdout) - _LOGGER.info(f"E2BCodeInterpreter (sandbox id: {self.interpreter.sandbox_id}) initialized:\n{sys_versions}") + _LOGGER.info( + f"E2BCodeInterpreter (sandbox id: {self.interpreter.sandbox_id}) initialized:\n{sys_versions}" + ) def close(self, *args: Any, **kwargs: Any) -> None: try: @@ -462,7 +463,6 @@ def close(self, *args: Any, **kwargs: Any) -> None: ) def restart_kernel(self) -> None: - self._check_sandbox_liveness() self.interpreter.notebook.restart_kernel() @tenacity.retry( @@ -474,12 +474,15 @@ def restart_kernel(self) -> None: after=tenacity.after_log(_LOGGER, logging.INFO), ) def exec_cell(self, code: str) -> Execution: - self._check_sandbox_liveness() self.interpreter.set_timeout(_SESSION_TIMEOUT) # Extend the life of the sandbox try: - _LOGGER.info(f"Start code execution in remote sandbox {self.interpreter.sandbox_id}. Timeout: {_SESSION_TIMEOUT}. Code hash: {hash(code)}") + _LOGGER.info( + f"Start code execution in remote sandbox {self.interpreter.sandbox_id}. Timeout: {_SESSION_TIMEOUT}. Code hash: {hash(code)}" + ) execution = self.interpreter.notebook.exec_cell(code) - _LOGGER.info(f"Finished code execution in remote sandbox {self.interpreter.sandbox_id}. Code hash: {hash(code)}") + _LOGGER.info( + f"Finished code execution in remote sandbox {self.interpreter.sandbox_id}. Code hash: {hash(code)}" + ) return Execution.from_e2b_execution(execution) except Exception as e: raise RemoteSandboxExecutionError( @@ -487,7 +490,6 @@ def exec_cell(self, code: str) -> Execution: ) from e def upload_file(self, file: Union[str, Path]) -> str: - self._check_sandbox_liveness() file_name = Path(file).name remote_path = f"/home/user/{file_name}" with open(file, "rb") as f: @@ -496,29 +498,17 @@ def upload_file(self, file: Union[str, Path]) -> str: return remote_path def download_file(self, file_path: str) -> Path: - self._check_sandbox_liveness() with tempfile.NamedTemporaryFile(mode="w+b", delete=False) as file: file.write(self.interpreter.files.read(path=file_path, format="bytes")) _LOGGER.info(f"File ({file_path}) is downloaded to: {file.name}") return Path(file.name) - def _check_sandbox_liveness(self) -> None: - try: - alive = self.interpreter.is_running(request_timeout=2) - except Exception as e: - _LOGGER.exception( - f"Failed to check the health of the remote sandbox ({self.interpreter.sandbox_id}) due to {e}. Consider the sandbox as dead." - ) - alive = False - if not alive: - raise RemoteSandboxClosedError( - "Remote sandbox ({self.interpreter.sandbox_id}) is closed unexpectedly. Please start a new VisionAgent instance." - ) - @staticmethod def _new_e2b_interpreter_impl(*args, **kwargs) -> E2BCodeInterpreterImpl: # type: ignore template_name = os.environ.get("E2B_TEMPLATE_NAME", "va-sandbox") - _LOGGER.info(f"Creating a new E2BCodeInterpreter using template: {template_name}") + _LOGGER.info( + f"Creating a new E2BCodeInterpreter using template: {template_name}" + ) return E2BCodeInterpreterImpl(template=template_name, *args, **kwargs)