{"record":{"id":"acffb658b3b19a53","repo":"langchain-ai/deepagents","slug":"cli-max-retries-must-be-0-got-self-cli-max-re","errorCode":null,"errorMessage":"cli_max_retries must be >= 0, got {self.cli_max_retries}","messagePattern":"cli_max_retries must be >= 0, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/config.py","lineNumber":5581,"sourceCode":"\n        Raises:\n            TypeError: If `model_retries` or `cli_max_retries` is a `bool`.\n            ValueError: If `model_retries` or `cli_max_retries` is negative.\n        \"\"\"\n        if isinstance(self.model_retries, bool):\n            msg = f\"model_retries must be an int, got {self.model_retries!r}\"\n            raise TypeError(msg)\n        if self.model_retries < 0:\n            msg = f\"model_retries must be >= 0, got {self.model_retries}\"\n            raise ValueError(msg)\n        if isinstance(self.cli_max_retries, bool):\n            msg = (\n                f\"cli_max_retries must be None or an int, got {self.cli_max_retries!r}\"\n            )\n            raise TypeError(msg)\n        if self.cli_max_retries is not None and self.cli_max_retries < 0:\n            msg = f\"cli_max_retries must be >= 0, got {self.cli_max_retries}\"\n            raise ValueError(msg)\n\n    def apply_to_runtime_state(self) -> None:\n        \"\"\"Commit this result's metadata to global `runtime_state`.\"\"\"\n        state = _get_runtime_state()\n        state.model_name = self.model_name\n        state.model_provider = self.provider\n        state.model_context_limit = self.context_limit\n        state.model_unsupported_modalities = self.unsupported_modalities\n\n\ndef _apply_profile_overrides(\n    model: BaseChatModel,\n    overrides: dict[str, Any],\n    model_name: str,\n    *,\n    label: str,\n    raise_on_failure: bool = False,\n) -> None:","sourceCodeStart":5563,"sourceCodeEnd":5599,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/config.py#L5563-L5599","documentation":"`ModelResult.__post_init__` raising ValueError because `cli_max_retries` is a non-None negative int. The `--max-retries` flag value must be zero or positive; None means 'not set'.","triggerScenarios":"Constructing `ModelResult(...)` with a negative `cli_max_retries` (e.g. -1). Argparse's `non_negative_int` normally blocks this at the CLI, so it indicates a value injected programmatically or via config plumbing.","commonSituations":"Programmatic re-resolution for a different provider passing along a badly computed flag value, tests with sentinel negatives, config parsers accepting negative numbers.","solutions":["Clamp before construction: `max(0, value)`.","Pass None when the flag was not set instead of a negative default.","Fix the producer of the value (config/CLI plumbing) to enforce non-negativity."],"exampleFix":"// before\nModelResult(..., cli_max_retries=-2)\n// after\nModelResult(..., cli_max_retries=max(0, requested_retries))","handlingStrategy":"validation","validationCode":"if cli_max_retries is not None and cli_max_retries < 0:\n    cli_max_retries = 0  # clamp before ModelResult(...)","typeGuard":null,"tryCatchPattern":"try:\n    result = ModelResult(..., cli_max_retries=v)\nexcept ValueError:\n    result = ModelResult(..., cli_max_retries=max(0, v))","preventionTips":["Clamp flag-derived values with max(0, value)","Rely on argparse's non_negative_int at the CLI boundary; don't bypass it programmatically","Use None for 'unset' rather than a negative sentinel","Re-validate the value when re-resolving for a different provider"],"tags":["validation","retry-budget","cli"],"backgroundTag":"negative-retry-budget","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}