{"record":{"id":"c1c69351c23c875a","repo":"langchain-ai/deepagents","slug":"model-retries-must-be-0-got-self-model-retrie","errorCode":null,"errorMessage":"model_retries must be >= 0, got {self.model_retries}","messagePattern":"model_retries must be >= 0, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/config.py","lineNumber":5573,"sourceCode":"        `_model_max_retries` and `CodeModelRetryMiddleware.__init__` reject it:\n        `True` would silently read as a budget of one.\n\n        `cli_max_retries` gets the same gate. It is the field that carries the\n        explicit flag onward to a re-resolution for a different provider, and\n        it was the one budget field in dcode without the check -- which is the\n        argument for a single validated budget type rather than a ninth copy of\n        this predicate.\n\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","sourceCodeStart":5555,"sourceCodeEnd":5591,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/config.py#L5555-L5591","documentation":"`ModelResult.__post_init__` validation raising ValueError because `model_retries` is negative. The retry middleware cannot honor a negative attempt budget, so negative values are rejected at construction.","triggerScenarios":"Constructing `ModelResult(...)` with `model_retries < 0` (e.g. -1) directly; upstream config coercion (`_coerce_max_retries`, `non_negative_int`) normally prevents this, so it signals a hand-built result.","commonSituations":"Computing a retry budget with subtraction that can go negative, tests constructing ModelResult with sentinel values, misread CLI flags.","solutions":["Clamp the computed value before construction: `max(0, computed_retries)`.","Pass `0` to disable retries rather than a negative number.","Fix the upstream calculation that produced the negative budget."],"exampleFix":"// before\nModelResult(..., model_retries=n_used - n_total)  # can be negative\n// after\nModelResult(..., model_retries=max(0, n_used - n_total))","handlingStrategy":"validation","validationCode":"if model_retries < 0:\n    model_retries = 0  # clamp before ModelResult(...)","typeGuard":null,"tryCatchPattern":"try:\n    result = ModelResult(..., model_retries=retries)\nexcept ValueError:\n    result = ModelResult(..., model_retries=0)","preventionTips":["Clamp computed budgets with max(0, value)","Use 0 as the canonical 'retries disabled' value","Enforce non-negativity at the config parse boundary","Avoid arithmetic on budgets that can go negative"],"tags":["validation","retry-budget"],"backgroundTag":"negative-retry-budget","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}