JuliusBrussee/caveman · error
cachebench: read trace
Error message
cachebench: read trace: %w
What it means
Wraps the bufio.Scanner error surfaced after the JSONL decode loop in ReadTraceJSONLWithLimits finishes. It does not indicate a bad record; it means the underlying reader failed mid-stream (I/O error, or a line exceeding MaxLineBytes), so the trace file could not be read to completion.
Solutions
- Check the wrapped error: ErrTooLong means a trace line exceeds the reader's MaxLineBytes limit — raise the limit or fix the trace
- Retry the read after verifying the file is not truncated or on a failing disk
- Regenerate the trace file if it was incompletely written (e.g. a crashed writer)
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at cacheengine/cachebench/trace.go:339 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18).
Data as JSON: /api/errors/b20bddb8eb0f6566.
Report an issue: GitHub.
Appendix: source
Thrown at cacheengine/cachebench/trace.go:339
if record.StableSegmentCount < 0 || record.StableSegmentCount > len(record.Prefix) || !validPrefix(record.Prefix) {
return nil, fmt.Errorf("cachebench: trace line %d: invalid prefix", line)
}
if record.Schema == TraceSchema || record.Schema == TraceSchemaV2 {
if record.ExpectedRPM <= 0 || record.ExpectedCalls <= 0 || !validTimingBasis(record.TimingBasis) {
return nil, fmt.Errorf("cachebench: trace line %d: incomplete replay metadata", line)
}
}
if record.Schema == TraceSchema {
if record.DeclaredInputTokens <= 0 || record.DeclaredInputTokens < record.PrefixTokens || record.MaxOutputTokens <= 0 || !requestBudgetMatchesBody(record) {
return nil, fmt.Errorf("cachebench: trace line %d: incomplete or mismatched billed-token budget", line)
}
}
seen[record.RequestID] = true
record.Body = append(json.RawMessage(nil), record.Body...)
records = append(records, record)
}
if err := scanner.Err(); err != nil {
return nil, fmt.Errorf("cachebench: read trace: %w", err)
}
if len(records) == 0 {
return nil, errors.New("cachebench: no trace records")
}
return records, nil
}
// NativeRequest reconstructs exact optimizer input captured by v2 or v3 trace.
// Legacy v1 traces remain readable for observation joins, but cannot drive live
// replay because they omitted routing and economics inputs.
func (record TraceRecord) NativeRequest() (cacheengine.NativeRequest, error) {
if record.Schema != TraceSchema && record.Schema != TraceSchemaV2 {
return cacheengine.NativeRequest{}, fmt.Errorf("cachebench: request %q needs %s or %s for reconstruction", record.RequestID, TraceSchemaV2, TraceSchema)
}
if !validTraceIdentity(record) || !validTimingBasis(record.TimingBasis) || record.ExpectedRPM <= 0 || record.ExpectedCalls <= 0 || record.PrefixTokens < 0 || !validUniqueJSONObject(record.Body) || record.BodySHA256 != bodyDigest(record.Body) || record.StableSegmentCount < 0 || record.StableSegmentCount > len(record.Prefix) || !validPrefix(record.Prefix) {
return cacheengine.NativeRequest{}, fmt.Errorf("cachebench: request %q has incomplete or invalid replay identity", record.RequestID)
}
return cacheengine.NativeRequest{View on GitHub (pinned to 766dce6b13)