{"record":{"id":"d5b3571c34938f62","repo":"JuliusBrussee/caveman","slug":"usage-export-contained-no-priced-rows","errorCode":null,"errorMessage":"usage export contained no priced rows","messagePattern":"usage export contained no priced rows","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/learn_reconcile.go","lineNumber":177,"sourceCode":"\t\tmodelIndex := columns[\"model\"]\n\t\tif modelIndex >= len(record) {\n\t\t\tcontinue\n\t\t}\n\t\tmodel := strings.TrimSpace(record[modelIndex])\n\t\tif model == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\ttotal := reconcileCell(record, columns, \"input\") +\n\t\t\treconcileCell(record, columns, \"output\") +\n\t\t\treconcileCell(record, columns, \"cache_read\") +\n\t\t\treconcileCell(record, columns, \"cache_write\")\n\t\tif total <= 0 {\n\t\t\tcontinue\n\t\t}\n\t\tbilled[model] += total\n\t}\n\tif len(billed) == 0 {\n\t\treturn nil, fmt.Errorf(\"usage export contained no priced rows\")\n\t}\n\treturn billed, nil\n}\n\n// BuildLearnReconcile compares an export against the scanned window.\nfunc (s *Store) BuildLearnReconcile(cwd, exportPath string, sources []string, sinceExpr string) (LearnReconcile, error) {\n\tbilled, err := parseUsageExport(exportPath)\n\tif err != nil {\n\t\treturn LearnReconcile{}, err\n\t}\n\tplan, err := s.BuildLearnPlan(cwd, sources, sinceExpr)\n\tif err != nil {\n\t\treturn LearnReconcile{}, err\n\t}\n\treturn buildLearnReconcile(billed, plan.Spend, exportPath), nil\n}\n\nfunc buildLearnReconcile(billed map[string]int64, spend *LearnSpend, source string) LearnReconcile {","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/store/learn_reconcile.go#L159-L195","documentation":"parseUsageExport reads a usage export CSV, accumulates billed cost per model, and skips rows whose computed total is <= 0. If, after that filtering, no priced rows remain, it refuses to return an empty map and fails closed so BuildLearnReconcile never reconciles against an empty baseline. The library treats 'export parsed but nothing billable in it' as an error rather than silently producing a meaningless reconcile.","triggerScenarios":"Calling BuildLearnReconcile with an export file whose rows all produce total <= 0 (zero prices, unknown schema columns yielding zero totals, or an export containing only header/unpriced rows). Also produced directly by tests TestReconcileFailsClosedOnUnknownSchema and TestReconcileAcceptsProviderHeaderVariants.","commonSituations":"Pointing the CLI at a stale, truncated, or wrong-format usage export; a provider changed its CSV column names so cost parsing yields 0 for every row; exporting a date window with no billable traffic; forgetting that transcript-only rows without pricing are skipped.","solutions":["Open the export file and confirm it actually contains priced rows (a cost/total column with values > 0) for the requested window","Re-export usage from the provider with a date range that includes billable requests","Check the provider's export schema for renamed columns (header variants) and update parsing expectations","If the export is legitimately empty for the window, widen the window rather than expecting a reconcile result"],"exampleFix":"// before\nplan, err := store.BuildLearnReconcile(cwd, \"empty-export.csv\", sources, since)\n// after\nif err != nil {\n    return fmt.Errorf(\"learn reconcile needs a non-empty priced export: %w\", err)\n}","handlingStrategy":"validation","validationCode":"rows, err := readCSVRows(exportPath)\nif err != nil { return err }\npriced := 0\nfor _, r := range rows[1:] {\n    if total, err := computeRowTotal(r); err == nil && total > 0 { priced++ }\n}\nif priced == 0 { return fmt.Errorf(\"export %s has no priced rows; re-export a window with billable traffic\", exportPath) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Peek at the export CSV before reconciling and assert at least one row has a positive cost","Re-export from the provider after schema changes and diff headers","Pin the provider export format version used by your pipeline","Log a warning when an export window yields zero billable rows"],"tags":["csv","validation","learn-reconcile"],"backgroundTag":"empty-result-set","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"}