{"record":{"id":"5e5d64ab9d7c4c8f","repo":"microsoft/autogen","slug":"no-code-blocks-to-execute","errorCode":null,"errorMessage":"No code blocks to execute.","messagePattern":"No code blocks to execute\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/code_executors/docker/_docker_code_executor.py","lineNumber":334,"sourceCode":"                    logging.debug(f\"Kill command scheduled, future: {future!r}\")\n                except RuntimeError as e:\n                    logging.error(f\"Failed to schedule kill command on loop {self._loop!r}: {e}\")\n                except Exception as e:\n                    logging.exception(f\"Unexpected error scheduling kill command: {e}\")\n            else:\n                logging.warning(\n                    f\"Cannot schedule kill command: Executor loop is not available or closed (loop: {self._loop!r}).\"\n                )\n            return \"Code execution was cancelled.\", 1\n\n    async def _execute_code_dont_check_setup(\n        self, code_blocks: List[CodeBlock], cancellation_token: CancellationToken\n    ) -> CommandLineCodeResult:\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        if len(code_blocks) == 0:\n            raise ValueError(\"No code blocks to execute.\")\n\n        outputs: List[str] = []\n        files: List[Path] = []\n        last_exit_code = 0\n        try:\n            for code_block in code_blocks:\n                lang = code_block.language.lower()\n                code = silence_pip(code_block.code, lang)\n\n                # Check if there is a filename comment\n                try:\n                    filename = get_file_name_from_content(code, self.work_dir)\n                except ValueError:\n                    outputs.append(\"Filename is not in the workspace\")\n                    last_exit_code = 1\n                    break\n\n                if not filename:","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/docker/_docker_code_executor.py#L316-L352","documentation":"Raised by DockerCommandLineCodeExecutor._execute_code_dont_check_setup (and the public execute_code_blocks path) when the code_blocks list passed in is empty. It is a simple fail-fast validation: there is nothing to execute, and the API refuses rather than returning an empty result.","triggerScenarios":"Calling execute_code_blocks([], cancellation_token); passing a filtered list where every block was dropped (e.g. selecting only 'python' blocks from an LLM message that contained none); splitting an empty string into blocks programmatically.","commonSituations":"Agents whose last message contained no code fences; upstream code that extracts code blocks via regex and forwards an empty list when extraction fails; loops over messages where some messages legitimately have no code.","solutions":["Guard the call: only invoke the executor when code_blocks is non-empty","Fix the extraction logic so an empty result is handled before reaching the executor (log the raw message to see why extraction failed)","Return a neutral CodeResult yourself if your agent protocol expects one for empty turns"],"exampleFix":"# before\nresult = await executor.execute_code_blocks(extract_blocks(msg), ct)  # may be []\n\n# after\nblocks = extract_blocks(msg)\nif not blocks:\n    return CodeResult(exit_code=0, output=\"No code blocks to execute.\")\nresult = await executor.execute_code_blocks(blocks, ct)","handlingStrategy":"validation","validationCode":"from autogen_core.code_executor import CodeResult\n\nasync def execute_safe(executor, blocks, ct) -> CodeResult:\n    if not blocks:\n        return CodeResult(exit_code=0, output=\"No code blocks to execute.\")\n    return await executor.execute_code_blocks(blocks, ct)","typeGuard":"def has_code_blocks(blocks) -> bool:\n    return isinstance(blocks, list) and len(blocks) > 0","tryCatchPattern":"null","preventionTips":["Filter then check: never forward extraction results without a non-empty assertion","Log the source message when extraction yields zero blocks — it usually means the model produced no code fence"],"tags":["docker","validation","code-execution","empty-input"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}