{"record":{"id":"0bb0968f2b7cc8fd","repo":"microsoft/autogen","slug":"failed-to-restart-container-logs-logs-str","errorCode":null,"errorMessage":"Failed to restart container. Logs: {logs_str}","messagePattern":"Failed to restart container\\. Logs: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/code_executors/docker/_docker_code_executor.py","lineNumber":430,"sourceCode":"\n        Returns:\n            CommandlineCodeResult: The result of the code execution.\"\"\"\n\n        if not self._setup_functions_complete:\n            await self._setup_functions(cancellation_token)\n\n        return await self._execute_code_dont_check_setup(code_blocks, cancellation_token)\n\n    async def restart(self) -> None:\n        \"\"\"(Experimental) Restart the Docker container code executor.\"\"\"\n        if self._container is None or not self._running:\n            raise ValueError(\"Container is not running. Must first be started with either start or a context manager.\")\n\n        await asyncio.to_thread(self._container.restart)  # type: ignore\n        if self._container.status != \"running\":\n            self._running = False\n            logs_str = self._container.logs().decode(\"utf-8\")\n            raise ValueError(f\"Failed to restart container. Logs: {logs_str}\")\n\n    async def stop(self) -> None:\n        \"\"\"(Experimental) Stop the code executor.\n\n        Stops the Docker container and cleans up any temporary files (if they were created), along with the temporary directory.\n        The method first waits for all cancellation tasks to finish before stopping the container. Finally it marks the executor as not running.\n        If the container is not running, the method does nothing.\n        \"\"\"\n        if not self._running:\n            return\n\n        if self._temp_dir is not None:\n            self._temp_dir.cleanup()\n            self._temp_dir = None\n\n        client = docker.from_env()\n        try:\n            try:","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/docker/_docker_code_executor.py#L412-L448","documentation":"Raised by DockerCommandLineCodeExecutor.restart() when container.restart() returns but the container's status is no longer 'running' — i.e. the container came back up and immediately exited. The message embeds the container's logs to explain the crash. The executor also sets _running=False, so subsequent executions fail with the 'Container is not running' error until restarted properly.","triggerScenarios":"Calling restart() on a container whose process crashes on startup: an entrypoint that exits, OOM-killed processes, or a daemon hiccup where the container enters 'exited'/'restarting' state after the restart call.","commonSituations":"Long-running agents that restart executors periodically hitting Docker daemon instability; containers with memory limits OOMing on restart; images whose main process had already been killed inside the container so restart revives a dead entrypoint.","solutions":["Read the embedded logs_str — it contains the container's stdout/stderr explaining the exit","If logs show OOM, raise Docker memory limits or reduce workload before restarting again","Recreate the executor entirely (new instance + start()) since _running is now False: restart() alone will raise error 698","Check `docker inspect <container> --format '{{.State.Status}} {{.State.ExitCode}}'` for the concrete state"],"exampleFix":"# before\nawait executor.restart()  # may raise with logs embedded\n\n# after\ntry:\n    await executor.restart()\nexcept ValueError as e:\n    print(\"container logs:\", e)  # logs are in the message\n    executor = DockerCommandLineCodeExecutor(image=\"python:3-slim\")\n    await executor.start()  # fresh container","handlingStrategy":"fallback","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    await executor.restart()\nexcept ValueError as e:\n    logs = str(e)  # contains \"Failed to restart container. Logs: <container logs>\"\n    diagnose(logs)\n    executor = DockerCommandLineCodeExecutor(image=\"python:3-slim\")\n    await executor.start()  # _running is now False; recreate instead","preventionTips":["Check `docker inspect` exit codes and memory limits if containers die on restart","Always treat restart() failure as terminal for that executor instance: recreate it","Capture the embedded logs before discarding the exception — they hold the crash reason"],"tags":["docker","restart","container","crash"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}