{"record":{"id":"773f80e18c9552f4","repo":"langchain-ai/deepagents","slug":"rewarmestimate-costs-must-be-finite-got-cold-sel","errorCode":null,"errorMessage":"RewarmEstimate costs must be finite, got cold={self.cold_cost_usd!r}, incremental={self.incremental_cost_usd!r}","messagePattern":"RewarmEstimate costs must be finite, got cold=(.+?), incremental=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/cold_cache.py","lineNumber":206,"sourceCode":"        \"\"\"Enforce the documented finiteness, ordering, and sign invariants.\n\n        Raises:\n            ValueError: When either figure is non-finite or negative, or the\n                delta exceeds the total it is a part of.\n        \"\"\"\n        # Checked first, and separately: `NaN` satisfies neither comparison\n        # below (`nan < 0` and `nan > nan` are both `False`), so it would slide\n        # past both guards and reach `format_cost_estimate`, where the\n        # magnitude arithmetic raises far from the value's real origin.\n        if not math.isfinite(self.cold_cost_usd) or not math.isfinite(\n            self.incremental_cost_usd\n        ):\n            msg = (\n                f\"RewarmEstimate costs must be finite, got \"\n                f\"cold={self.cold_cost_usd!r}, \"\n                f\"incremental={self.incremental_cost_usd!r}\"\n            )\n            raise ValueError(msg)\n        if self.cold_cost_usd < 0 or self.incremental_cost_usd < 0:\n            msg = (\n                f\"RewarmEstimate costs must be non-negative, got \"\n                f\"cold={self.cold_cost_usd!r}, \"\n                f\"incremental={self.incremental_cost_usd!r}\"\n            )\n            raise ValueError(msg)\n        if self.incremental_cost_usd > self.cold_cost_usd:\n            msg = (\n                f\"RewarmEstimate incremental cost {self.incremental_cost_usd!r} \"\n                f\"cannot exceed the cold cost {self.cold_cost_usd!r}\"\n            )\n            raise ValueError(msg)\n\n\n@dataclass(frozen=True, slots=True)\nclass ColdCacheWarning:\n    \"\"\"Validated data needed to render one advisory warning.","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/cold_cache.py#L188-L224","documentation":"RewarmEstimate is a frozen dataclass validated in __post_init__ to ensure its two cost fields are finite numbers. This error means cold_cost_usd or incremental_cost_usd was NaN or +/-inf, which would corrupt any downstream cost comparison or budget math. The library fails fast at construction rather than propagating non-finite costs.","triggerScenarios":"Constructing RewarmEstimate(cold_cost_usd=..., incremental_cost_usd=...) where either value is math.nan, math.inf, or -math.inf (e.g. computed by dividing by zero or from a missing pricing entry).","commonSituations":"Estimating costs from a pricing table with a missing model entry (0/0 division), loading cached estimates from corrupted JSON, or passing float('inf') as a sentinel for 'unknown cost'.","solutions":["Check both cost inputs with math.isfinite() before constructing RewarmEstimate and substitute a real estimate for the missing value.","Fix the upstream pricing/telemetry data source so it no longer yields NaN or infinity.","If 'unknown cost' must be represented, use None or a separate flag at the call site instead of inf, before the dataclass boundary."],"exampleFix":"// before\nest = RewarmEstimate(cold_cost_usd=total / count, incremental_cost_usd=0.02)  # count==0 -> inf\n// after\nimport math\ncold = total / count if count else 0.0\nassert math.isfinite(cold), \"cold cost estimate not computable\"\nest = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=0.02)","handlingStrategy":"validation","validationCode":"import math\nif not (math.isfinite(cold) and math.isfinite(inc)):\n    raise ValueError(f\"cost estimates must be finite: cold={cold!r}, inc={inc!r}\")\nest = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc)","typeGuard":"def is_finite_cost(v: object) -> bool:\n    return isinstance(v, (int, float)) and math.isfinite(v)","tryCatchPattern":"try:\n    est = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc)\nexcept ValueError as e:\n    logger.warning(\"invalid rewarm estimate: %s\", e)\n    est = None","preventionTips":["Run math.isfinite() on every cost derived from division or external data","Never use inf/nan as an 'unknown' sentinel; use None","Sanitize pricing-table lookups with explicit defaults"],"tags":["validation","dataclass","config"],"backgroundTag":"non-finite-number-value","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}