{"record":{"id":"2f6b4a8ec769b034","repo":"JuliusBrussee/caveman","slug":"native-session-usage-w","errorCode":null,"errorMessage":"native session usage: %w","messagePattern":"native session usage: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/store.go","lineNumber":749,"sourceCode":"\t\t`SELECT COUNT(*),\n\t\t        COALESCE(SUM(CASE WHEN token_usage_basis = 'provider_complete' THEN 1 ELSE 0 END),0),\n\t\t        COALESCE(SUM(input_tokens),0), COALESCE(SUM(output_tokens),0),\n\t\t        COALESCE(SUM(cached_input_tokens),0), COALESCE(SUM(cache_creation_input_tokens),0),\n\t\t        COALESCE(SUM(reasoning_tokens),0), COALESCE(SUM(total_cost_usd),0),\n\t\t        COALESCE(SUM(savings_usd),0), COALESCE(SUM(compression_tokens_before),0),\n\t\t        COALESCE(SUM(compression_tokens_after),0),\n\t\t        COALESCE(GROUP_CONCAT(DISTINCT NULLIF(compression_token_count_basis,'')),''),\n\t\t        COALESCE(GROUP_CONCAT(DISTINCT NULLIF(session_correlation_basis,'')),'')\n\t\t   FROM requests WHERE session_id = ?`,\n\t\tsessionID,\n\t).Scan(\n\t\t&out.Requests, &out.ProviderCompleteRequests, &out.InputTokens, &out.OutputTokens,\n\t\t&out.CachedInputTokens, &out.CacheCreationInputTokens, &out.ReasoningTokens,\n\t\t&out.CatalogListPriceSubtotalUSD, &out.InferredSavingsUSD,\n\t\t&out.CompressionTokensBefore, &out.CompressionTokensAfter, &compressionBases, &correlationBases,\n\t)\n\tif err != nil {\n\t\treturn out, fmt.Errorf(\"native session usage: %w\", err)\n\t}\n\tif out.Requests == 0 {\n\t\treturn out, nil\n\t}\n\tout.Status = \"correlated\"\n\tif !strings.Contains(correlationBases, \",\") {\n\t\tout.CorrelationBasis = correlationBases\n\t} else {\n\t\tout.CorrelationBasis = \"mixed\"\n\t}\n\tif out.ProviderCompleteRequests == out.Requests {\n\t\tout.TokenUsageCoverage = \"provider_complete\"\n\t} else {\n\t\tout.TokenUsageCoverage = \"mixed_or_unavailable\"\n\t}\n\tif compressionBases == \"estimated_engine_o200k\" || compressionBases == \"legacy_unspecified\" {\n\t\tout.CompressionTokenCountBasis = compressionBases\n\t} else if compressionBases != \"\" {","sourceCodeStart":731,"sourceCodeEnd":767,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/store/store.go#L731-L767","documentation":"SessionUsage wraps the error from the aggregate usage QueryRow scan with this message. It means the underlying SQL query or scan failed — typically a database-level problem (locked db, I/O error, corruption) rather than a data problem (no rows just yields status \"not_observed\").","triggerScenarios":"Calling Store.SessionUsage with a valid session ID when the SELECT fails or the columns cannot be scanned into the ObserveSummary fields (e.g. database locked, disk error, schema drift).","commonSituations":"Another process holds a write lock on the SQLite file, the db file is on a full/failing disk, or the schema was modified externally so scan targets no longer match.","solutions":["Inspect the wrapped driver error for 'database is locked', 'disk I/O error', or scan-type mismatches.","Retry after ensuring other processes have released the SQLite lock.","Check disk health/space on the machine hosting the DB.","If schema drift is suspected, reopen via store.Open so migrations run, or restore the DB from backup."],"exampleFix":"// before\nusage, err := store.SessionUsage(sid)\nif err != nil { return err }\n// after\nusage, err := store.SessionUsage(sid)\nif err != nil {\n    if strings.Contains(err.Error(), \"database is locked\") { time.Sleep(250 * time.Millisecond); usage, err = store.SessionUsage(sid) }\n    if err != nil { return err }\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"usage, err := store.SessionUsage(sid)\nif err != nil {\n    if isLocked(err) { time.Sleep(250*time.Millisecond); usage, err = store.SessionUsage(sid) }\n    if err != nil { return err }\n}","preventionTips":["Avoid concurrent writers to the same SQLite file.","Keep WAL mode / busy_timeout configured via the DSN where possible.","Monitor disk health and space on the DB host."],"tags":["sqlite","query","usage"],"backgroundTag":"database-query-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}