{"record":{"id":"8586f2bc54029a5a","repo":"langchain-ai/deepagents","slug":"timeout-must-be-positive-got-effective-timeout","errorCode":null,"errorMessage":"timeout must be positive, got {effective_timeout}","messagePattern":"timeout must be positive, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/backends/local_shell.py","lineNumber":301,"sourceCode":"\n            # Override timeout for long-running commands\n            result = backend.execute(\"make build\", timeout=300)\n\n            # Commands run in root_dir, but can access any path\n            result = backend.execute(\"cat /etc/passwd\")  # Can read system files!\n            ```\n        \"\"\"\n        if not command or not isinstance(command, str):\n            return ExecuteResponse(\n                output=\"Error: Command must be a non-empty string.\",\n                exit_code=1,\n                truncated=False,\n            )\n\n        effective_timeout = timeout if timeout is not None else self._default_timeout\n        if effective_timeout <= 0:\n            msg = f\"timeout must be positive, got {effective_timeout}\"\n            raise ValueError(msg)\n\n        try:\n            result = subprocess.run(  # noqa: S602\n                command,\n                check=False,\n                shell=True,  # Intentional: designed for LLM-controlled shell execution\n                capture_output=True,\n                stdin=subprocess.DEVNULL,  # Prevent hanging on commands that read stdin (e.g. python, cat)\n                text=True,\n                timeout=effective_timeout,\n                env=self._env,\n                cwd=str(self.cwd),  # Use the root_dir from FilesystemBackend\n                start_new_session=(sys.platform != \"win32\"),\n            )\n\n            # Combine stdout and stderr\n            # Prefix each stderr line with [stderr] for clear attribution.\n            # Example: \"hello\\n[stderr] error: file not found\"  # noqa: ERA001","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/backends/local_shell.py#L283-L319","documentation":"execute validates the effective timeout — the explicit argument, or the backend's default_timeout when None — and raises ValueError if it is not positive. Unlike the constructor check, this one fires per call, so a bad per-call timeout triggers it even on a correctly constructed backend.","triggerScenarios":"Calling execute(command, timeout=0) or timeout=-5, or execute(command, timeout=None) on an instance whose default_timeout ended up non-positive.","commonSituations":"Dynamic timeouts computed from a remaining-time budget that already hit zero, or passing user-supplied timeout values through unvalidated.","solutions":["Pass a positive timeout to execute, e.g. execute(cmd, timeout=30)","Clamp computed budgets: timeout=max(1.0, remaining)","Recheck the instance's default_timeout if relying on the default path","Validate user-provided timeout values at your API boundary before forwarding"],"exampleFix":"// before\nshell.execute(cmd, timeout=deadline - time.monotonic())\n// after\nshell.execute(cmd, timeout=max(1.0, deadline - time.monotonic()))","handlingStrategy":"validation","validationCode":"timeout = explicit_timeout if explicit_timeout is not None else shell._default_timeout\nif timeout <= 0:\n    timeout = DEFAULT_CMD_TIMEOUT\nshell.execute(cmd, timeout=timeout)","typeGuard":null,"tryCatchPattern":"try:\n    result = shell.execute(cmd, timeout=t)\nexcept ValueError as exc:\n    if \"timeout must be positive\" in str(exc):\n        result = shell.execute(cmd, timeout=30)\n    else:\n        raise","preventionTips":["Clamp dynamic budgets with max(min_seconds, remaining)","Validate user-supplied timeouts at your API boundary"],"tags":["python","argument-validation","shell","timeout"],"backgroundTag":"invalid-timeout-value","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}