JuliusBrussee/caveman · error

cachebench: trace line

Error message

cachebench: trace line %d: incomplete or mismatched billed-token budget

What it means

Fires in ReadTraceJSONLWithLimits for v3 (TraceSchema) records: the declared billed-token budget (DeclaredInputTokens and related declared totals) must be present and consistent — DeclaredInputTokens must be positive and at least PrefixTokens. It means the record's declared token accounting is missing or contradicts the measured prefix tokens, so replay billing cannot be reconstructed faithfully.

Solutions

  1. Regenerate the trace so DeclaredInputTokens is positive and >= PrefixTokens on every v3 record
  2. Re-capture the trace with the current cachebench writer; older writers may have omitted the billed-token fields
  3. Edit the offending JSONL line to carry a consistent declared budget and re-run replay
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cacheengine/cachebench/trace.go:331 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/b53ab24d852cc860. Report an issue: GitHub.

Appendix: source

Thrown at cacheengine/cachebench/trace.go:331

			return nil, fmt.Errorf("cachebench: trace line %d: invalid schema or request_id", line)
		}
		if _, err := time.Parse(time.RFC3339Nano, record.At); err != nil || !validTraceIdentity(record) || record.PrefixTokens < 0 {
			return nil, fmt.Errorf("cachebench: trace line %d: incomplete request identity", line)
		}
		if len(record.Body) > limits.MaxBodyBytes || !json.Valid(record.Body) || record.BodySHA256 == "" || record.BodySHA256 != bodyDigest(record.Body) {
			return nil, fmt.Errorf("cachebench: trace line %d: invalid body or digest", line)
		}
		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.

View on GitHub (pinned to 766dce6b13)