{"record":{"id":"18af1f30ea0e8495","repo":"microsoft/autogen","slug":"functions-failed-to-load-exec-result-output-18af1f","errorCode":null,"errorMessage":"Functions failed to load: {exec_result.output}","messagePattern":"Functions failed to load: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/code_executors/local/__init__.py","lineNumber":320,"sourceCode":"            cancellation_token.link_future(task)\n            try:\n                proc = await task\n                stdout, stderr = await asyncio.wait_for(proc.communicate(), self._timeout)\n            except asyncio.TimeoutError as e:\n                raise ValueError(\"Pip install timed out\") from e\n            except asyncio.CancelledError as e:\n                raise ValueError(\"Pip install was cancelled\") from e\n\n            if proc.returncode is not None and proc.returncode != 0:\n                raise ValueError(f\"Pip install failed. {stdout.decode()}, {stderr.decode()}\")\n\n        # Attempt to load the function file to check for syntax errors, imports etc.\n        exec_result = await self._execute_code_dont_check_setup(\n            [CodeBlock(code=func_file_content, language=\"python\")], cancellation_token\n        )\n\n        if exec_result.exit_code != 0:\n            raise ValueError(f\"Functions failed to load: {exec_result.output}\")\n\n        self._setup_functions_complete = True\n\n    async def execute_code_blocks(\n        self, code_blocks: List[CodeBlock], cancellation_token: CancellationToken\n    ) -> CommandLineCodeResult:\n        \"\"\"(Experimental) Execute the code blocks and return the result.\n\n        Args:\n            code_blocks (List[CodeBlock]): The code blocks to execute.\n            cancellation_token (CancellationToken): a token to cancel the operation\n\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","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/local/__init__.py#L302-L338","documentation":"Raised after a successful pip install during LocalCommandLineCodeExecutor setup: the generated functions module is executed once as a smoke test (_execute_code_dont_check_setup), and if that execution returns a nonzero exit code (syntax error, failing import, exception at import time), the ValueError embeds the captured output.","triggerScenarios":"A registered function's module has a syntax error, or its top-level/import code raises (missing optional dependency not captured by pip, file/network access at import time), so the smoke-test execution fails.","commonSituations":"Functions that read files or env vars at import time which do not exist in the executor's working directory, syntax errors in hand-written function bodies, imports of packages installed in a different interpreter than the executor's virtual_env_context.","solutions":["Read the exec output embedded in the message - it contains the Python traceback of the failed import/exec; fix the function code accordingly.","Make function modules import-safe: move I/O and side effects inside the function body, not at module top level.","Ensure the dependency is importable in the interpreter the executor uses (same venv); add the missing package to the function's imports so pip installs it."],"exampleFix":"# before\n@register_function\ndef load_config() -> dict:\n    import json, os\n    return json.load(open(os.environ.get(\"CONFIG\", \"/etc/app/config.json\")))  # fails during smoke test\n\n# after\n@register_function\ndef load_config(path: str) -> dict:\n    import json\n    return json.load(open(path))","handlingStrategy":"try-catch","validationCode":"import ast\n\ndef functions_module_valid(module_src: str) -> bool:\n    try:\n        ast.parse(module_src)\n        return True\n    except SyntaxError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    await executor.execute_code_blocks(blocks, token)\nexcept ValueError as e:\n    if \"Functions failed to load\" in str(e):\n        log.error(\"function module smoke test failed:\\n%s\", str(e))\n        raise  # output contains the traceback; fix the function body\n    raise","preventionTips":["Keep registered functions import-safe: no top-level I/O or env access.","Unit-test function modules by importing them directly before registering.","Ensure the executor's interpreter (virtual_env_context) has the function's dependencies."],"tags":["functions","local-executor","setup","imports"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}