JuliusBrussee/caveman · error
usage export has no header row
Error message
usage export has no header row: %w
What it means
After opening the CSV, parseUsageExport reads the first row as the header. If csv.Reader.Read() fails (empty file, or a non-CSV/binary file with a read error) it wraps the cause as "usage export has no header row". This keeps schema detection from running on nothing.
Solutions
- Check the file is non-empty and is a real CSV (head -1 usage.csv)
- Re-download/re-export the usage file from the provider
- Fix any truncated or partial download before running reconcile
Example fix
// before $ wc -c usage.csv 0 // after $ head -1 usage.csv model,input_tokens,output_tokens
Defensive patterns
Strategy: validation
Validate before calling
fi, _ := os.Stat(path); if fi.Size() == 0 { return fmt.Errorf("usage export is empty: %s", path) } Try / catch
if _, err := store.BuildLearnReconcile(ctx, opts); err != nil { if strings.Contains(err.Error(), "no header row") { log.Error("usage export empty or not CSV; re-download") } } Prevention
- Check file size > 0 after downloading the export
- Verify the file is CSV (starts with a header line), not HTML/JSON
- Detect truncated downloads via provider-provided checksums
When it happens
Trigger: The usage-export file is empty (zero bytes), or reading the first line errors (binary content, decode error, I/O failure on first read).
Common situations: Provider export failed and produced a 0-byte file; pointing reconcile at an HTML error page saved instead of the CSV; truncated download.
Related errors
- read usage export
- caveman agent: invalid .caveman/provider.json
- local learn snapshot is unreadable at
- changed during MCP update; refusing overwrite
- postgres: read
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/4467cbc4a542316f.
Report an issue: GitHub.
Appendix: source
Thrown at proxy/internal/store/learn_reconcile.go:144
value, err := strconv.ParseFloat(raw, 64)
if err != nil || value < 0 {
return 0
}
return int64(value)
}
// parseUsageExport reads a provider usage CSV into billed tokens per model.
func parseUsageExport(path string) (map[string]int64, error) {
file, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("read usage export: %w", err)
}
defer file.Close()
reader := csv.NewReader(file)
reader.FieldsPerRecord = -1
header, err := reader.Read()
if err != nil {
return nil, fmt.Errorf("usage export has no header row: %w", err)
}
columns, err := mapReconcileHeader(header)
if err != nil {
return nil, err
}
billed := map[string]int64{}
for {
record, err := reader.Read()
if err == io.EOF {
break
}
if err != nil {
return nil, fmt.Errorf("usage export row: %w", err)
}
modelIndex := columns["model"]
if modelIndex >= len(record) {
continue
}View on GitHub (pinned to 3ee70a1026)