JuliusBrussee/caveman · error

cachebench: trace line

Error message

cachebench: trace line %d: incomplete replay metadata

What it means

Raised while validating a trace record in ReadTraceJSONLWithLimits: for v2/v3 (replay-capable) schema records, the replay metadata block (ExpectedRPM, ExpectedCalls, TimingBasis) is required to drive live replay. Fires when any of those fields is zero, negative, or an unrecognized timing basis, meaning the trace was captured without (or with corrupted) replay-driving metadata.

Solutions

  1. Regenerate the trace with a writer that emits ExpectedRPM > 0, ExpectedCalls > 0, and a valid TimingBasis for v2/v3 schema records
  2. Inspect the offending JSONL line (the %d line number) and fix or remove the malformed record
  3. If the trace only needs observation joins rather than live replay, use a v1-schema trace or an observation-only code path
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at cacheengine/cachebench/trace.go:326

		var trailing any
		if err := decoder.Decode(&trailing); err != io.EOF {
			return nil, fmt.Errorf("cachebench: trace line %d: trailing JSON", line)
		}
		if record.Schema != TraceSchema && record.Schema != TraceSchemaV2 && record.Schema != TraceSchemaV1 || !validBoundedText(record.RequestID, 512, false) || seen[record.RequestID] {
			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

View on GitHub (pinned to 766dce6b13)