{"record":{"id":"12f65a7360282e69","repo":"microsoft/autogen","slug":"timeout-must-be-greater-than-or-equal-to-1-12f65a","errorCode":null,"errorMessage":"Timeout must be greater than or equal to 1.","messagePattern":"Timeout must be greater than or equal to 1\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/code_executors/jupyter/_jupyter_code_executor.py","lineNumber":146,"sourceCode":"        timeout (int): The timeout for code execution, by default 60.\n        output_dir (Path): The directory to save output files, by default a temporary directory.\n\n\n    .. note::\n        Using the current directory (\".\") as output directory is deprecated. Using it will raise a deprecation warning.\n    \"\"\"\n\n    component_config_schema = JupyterCodeExecutorConfig\n    component_provider_override = \"autogen_ext.code_executors.jupyter.JupyterCodeExecutor\"\n\n    def __init__(\n        self,\n        kernel_name: str = \"python3\",\n        timeout: int = 60,\n        output_dir: Optional[Union[Path, str]] = None,\n    ):\n        if timeout < 1:\n            raise ValueError(\"Timeout must be greater than or equal to 1.\")\n\n        self._output_dir: Path = Path(tempfile.mkdtemp()) if output_dir is None else Path(output_dir)\n        self._output_dir.mkdir(exist_ok=True, parents=True)\n\n        self._temp_dir: Optional[tempfile.TemporaryDirectory[str]] = None\n        self._temp_dir_path: Optional[Path] = None\n\n        self._started = False\n\n        self._kernel_name = kernel_name\n        self._timeout = timeout\n\n        self._client: Optional[NotebookClient] = None\n        self.kernel_context: Optional[AbstractAsyncContextManager[None]] = None\n\n    async def execute_code_blocks(\n        self, code_blocks: list[CodeBlock], cancellation_token: CancellationToken\n    ) -> JupyterCodeResult:","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/jupyter/_jupyter_code_executor.py#L128-L164","documentation":"Constructor validation in JupyterCodeExecutor: the timeout (seconds per cell execution, default 60) must be >= 1. Zero or negative values raise ValueError immediately; None is not accepted here.","triggerScenarios":"JupyterCodeExecutor(timeout=0) or a negative number, typically from unparsed config values, env vars defaulting to 0, or arithmetic that computes a non-positive timeout.","commonSituations":"int(os.getenv('TIMEOUT', 0)) when the var is unset, configs migrated from millisecond semantics, tests passing timeout=0 as a placeholder, computed timeouts that underflow to 0.","solutions":["Pass timeout >= 1 seconds (default 60 is usually fine).","Sanitize external config: timeout = max(1, int(raw_value)) before constructing.","Confirm you are not passing None where an int is required."],"exampleFix":"# before\nexecutor = JupyterCodeExecutor(timeout=0)\n\n# after\nexecutor = JupyterCodeExecutor(timeout=60)","handlingStrategy":"validation","validationCode":"timeout = int(os.getenv(\"EXEC_TIMEOUT\", \"60\")) or 60\ntimeout = max(1, timeout)","typeGuard":"def is_valid_timeout(t: object) -> bool:\n    return isinstance(t, int) and not isinstance(t, bool) and t >= 1","tryCatchPattern":"try:\n    JupyterCodeExecutor(timeout=t)\nexcept ValueError as e:\n    if \"Timeout\" in str(e):\n        executor = JupyterCodeExecutor(timeout=max(1, int(t)))\n    else:\n        raise","preventionTips":["Use a single config helper that clamps timeouts to >= 1.","Treat missing timeout config as the default 60, never 0."],"tags":["validation","constructor","jupyter","executor"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}