{"record":{"id":"085448e963c91a98","repo":"langchain-ai/deepagents","slug":"rewarmestimate-costs-must-be-non-negative-got-col","errorCode":null,"errorMessage":"RewarmEstimate costs must be non-negative, got cold={self.cold_cost_usd!r}, incremental={self.incremental_cost_usd!r}","messagePattern":"RewarmEstimate costs must be non-negative, got cold=(.+?), incremental=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/cold_cache.py","lineNumber":213,"sourceCode":"        # 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.\n\n    Constructed only after every gate has passed -- a policy resolved, the\n    prefix cleared the provider's cache minimum, and the priced delta reached\n    the configured threshold -- so the modal renders it without re-deciding\n    anything.\n    \"\"\"\n","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/cold_cache.py#L195-L231","documentation":"RewarmEstimate.__post_init__ rejects negative cold_cost_usd or incremental_cost_usd. Costs in USD cannot be negative, so a negative value indicates a sign error, a refund misapplied as a cost, or corrupted data. The library raises immediately to keep cost accounting sane.","triggerScenarios":"Calling RewarmEstimate(cold_cost_usd=-0.5, ...) or passing a negative incremental_cost_usd, typically from subtracting in the wrong order or negating a delta.","commonSituations":"Computing incremental cost as (new_total - old_total) when values were swapped, parsing cost columns from a CSV with currency signs, or reusing a signed 'savings' value as a cost.","solutions":["Compute costs with abs() or verify the subtraction order so both values are >= 0 before constructing RewarmEstimate.","If a negative number signals 'savings', model that separately (e.g. a savings field) instead of passing it as a cost.","Validate values at the data-ingestion boundary and log/skip corrupted records instead of feeding them into estimates."],"exampleFix":"// before\ninc = old_total - new_total  # negative when new is cheaper\nest = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc)\n// after\ninc = max(0.0, new_total - old_total)\nest = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc)","handlingStrategy":"validation","validationCode":"if cold < 0 or inc < 0:\n    raise ValueError(f\"costs cannot be negative: cold={cold!r}, inc={inc!r}\")\nest = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc)","typeGuard":"def is_non_negative_number(v: object) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool) and v >= 0","tryCatchPattern":"try:\n    est = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc)\nexcept ValueError:\n    est = RewarmEstimate(cold_cost_usd=abs(cold), incremental_cost_usd=abs(inc))","preventionTips":["Verify subtraction order when computing deltas; use abs() for magnitudes","Keep 'savings' (signed) separate from 'cost' (non-negative) fields","Validate cost fields at CSV/JSON ingestion time"],"tags":["validation","dataclass","config"],"backgroundTag":"invalid-cost-value","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}