{"record":{"id":"f714c276b417b029","repo":"tinyhumansai/openhuman","slug":"token-usage-cost-must-be-a-finite-non-negative-va","errorCode":null,"errorMessage":"Token usage cost must be a finite, non-negative value","messagePattern":"Token usage cost must be a finite, non-negative value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/openhuman/platform/cost/tracker.rs","lineNumber":159,"sourceCode":"    ///\n    /// Honours `cost.enabled` — when budget enforcement is disabled the call\n    /// is a no-op. Use [`Self::record_usage_unconditional`] for telemetry\n    /// paths (dashboard, observability) that must capture data even when\n    /// the budget enforcement path is off, so the user can flip enforcement\n    /// on later without losing history.\n    pub fn record_usage(&self, usage: TokenUsage) -> Result<()> {\n        if !self.config.enabled {\n            return Ok(());\n        }\n        self.record_usage_unconditional(usage)\n    }\n\n    /// Persist a usage event ignoring `cost.enabled`. Used by the dashboard\n    /// telemetry hook so cost history is recorded regardless of whether the\n    /// budget-enforcement gate is on.\n    pub fn record_usage_unconditional(&self, usage: TokenUsage) -> Result<()> {\n        if !usage.cost_usd.is_finite() || usage.cost_usd < 0.0 {\n            return Err(anyhow!(\n                \"Token usage cost must be a finite, non-negative value\"\n            ));\n        }\n\n        let record = CostRecord::new(&self.session_id, usage);\n\n        // Persist first for durability guarantees.\n        {\n            let mut storage = self.lock_storage();\n            storage.add_record(record.clone())?;\n        }\n\n        // Then update in-memory session snapshot.\n        let mut session_costs = self.lock_session_costs();\n        session_costs.push(record);\n\n        Ok(())\n    }","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/openhuman/platform/cost/tracker.rs#L141-L177","documentation":"The same finite/non-negative guard as the estimate variant, applied to the computed cost of a `TokenUsage` event in `record_usage_unconditional`: the cost derived from the usage record is NaN, infinite, or negative. This fires when token counts or pricing rates feeding the multiplication are themselves non-finite or the provider supplied malformed numbers — persisting such a value would poison the spend ledger and budget gates.","triggerScenarios":"Thrown at src/openhuman/platform/cost/tracker.rs:159 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the offending `TokenUsage` record — zero/negative token counts or non-finite values from the provider are typical","Validate and sanitize provider usage payloads at deserialization time","Keep per-model pricing tables well-formed; a missing rate defaulting to NaN will surface here"],"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-14T00:17:10.932Z"}