{"record":{"id":"574c887eaf208446","repo":"tinyhumansai/openhuman","slug":"estimated-cost-must-be-a-finite-non-negative-valu","errorCode":null,"errorMessage":"Estimated cost must be a finite, non-negative value","messagePattern":"Estimated cost must be a finite, non-negative value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/openhuman/platform/cost/tracker.rs","lineNumber":72,"sourceCode":"    /// Check if a request is within budget.\n    ///\n    /// Only **managed-route** spend is considered (#5016). The local `[cost]`\n    /// limits cap spend against OpenHuman credits; bring-your-own-key and\n    /// local inference is billed by the user's own provider, so counting it\n    /// here produced a phantom limit — a pure-BYOK user accrued locally\n    /// *estimated* spend they were never charged for and got \"You're out of\n    /// credits\" at the default $10/day. See [`super::route`].\n    ///\n    /// A pure-BYOK user therefore has zero managed spend and can never trip\n    /// this gate. Real managed-credit exhaustion is unaffected: it is enforced\n    /// server-side by the backend, which returns its own billing error.\n    pub fn check_budget(&self, estimated_cost_usd: f64) -> Result<BudgetCheck> {\n        if !self.config.enabled {\n            return Ok(BudgetCheck::Allowed);\n        }\n\n        if !estimated_cost_usd.is_finite() || estimated_cost_usd < 0.0 {\n            return Err(anyhow!(\n                \"Estimated cost must be a finite, non-negative value\"\n            ));\n        }\n\n        let mut storage = self.lock_storage();\n        let (daily_cost, monthly_cost) = storage.get_aggregated_managed_costs()?;\n        // The all-routes totals exist purely to make the managed-vs-BYOK split\n        // visible in a debug log. `tracing` evaluates field expressions eagerly,\n        // so compute them only when that level is actually enabled rather than\n        // on every budget check in production.\n        if tracing::enabled!(tracing::Level::DEBUG) {\n            let (daily_all, monthly_all) = storage.get_aggregated_costs()?;\n            tracing::debug!(\n                daily_managed_usd = daily_cost,\n                monthly_managed_usd = monthly_cost,\n                daily_all_routes_usd = daily_all,\n                monthly_all_routes_usd = monthly_all,\n                daily_limit_usd = self.config.daily_limit_usd,","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/openhuman/platform/cost/tracker.rs#L54-L90","documentation":"A numeric-sanity guard on estimated cost values passed to the cost tracker: the value is either NaN, infinite, or negative, so it is rejected before being recorded. This fires when an upstream pricing calculation produces a non-finite result (division by zero in a per-token rate, a deserialized NaN from a provider payload) or a negative one — recording it would corrupt budget accounting, so the tracker fails closed.","triggerScenarios":"Thrown at src/openhuman/platform/cost/tracker.rs:72 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Trace where the estimate originates — a provider returning garbage usage/pricing numbers is the usual source","If computing cost locally, guard the arithmetic (per-token rates divided by zero token counts are a classic cause)","Reject or clamp bad provider payloads at the ingestion boundary rather than passing them into the tracker"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"749120085864ce16e0f273c7b86fac7740b39c5b","analyzedAt":"2026-08-17T21:21:45.363Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}