JuliusBrussee/caveman · error

cachebench: trace request %d has invalid schema or request_i

Error message

cachebench: trace request %d has invalid schema or request_id

What it means

Each trace entry must carry schema exactly TraceSchema or TraceSchemaV2 and a non-blank RequestID; otherwise the trace's identity model is broken and the exact join against observations cannot be trusted. The error reports the offending trace index.

Source

Thrown at cacheengine/cachebench/observed.go:43

		EngineDecision: result.Decision, EngineReason: result.Reason, ProfileID: result.Profile.ID,
		Attribution: result.Profile.Attribution, OptimizerIDs: append([]string(nil), result.OptimizerIDs...),
		QualityPassed: verification.Passed, QualityVerifier: verification.Verifier,
		QualityEvidenceSHA256: bodyDigest(verification.Evidence), Usage: append(json.RawMessage(nil), rawUsage...),
	}
}

// EvaluateObservedAgainstTrace requires exact request population and body joins.
func EvaluateObservedAgainstTrace(records []ObservationRecord, trace []TraceRecord, target Target) (Report, error) {
	if err := validateObservationRecords(records); err != nil {
		return Report{}, err
	}
	if len(records) != len(trace) {
		return Report{}, fmt.Errorf("cachebench: observation population %d does not match trace population %d", len(records), len(trace))
	}
	byID := make(map[string]TraceRecord, len(trace))
	for index, request := range trace {
		if request.Schema != TraceSchema && request.Schema != TraceSchemaV2 || strings.TrimSpace(request.RequestID) == "" {
			return Report{}, fmt.Errorf("cachebench: trace request %d has invalid schema or request_id", index)
		}
		if _, exists := byID[request.RequestID]; exists {
			return Report{}, fmt.Errorf("cachebench: duplicate trace request %q", request.RequestID)
		}
		if strings.TrimSpace(request.Provider) == "" || strings.TrimSpace(request.Epoch) == "" || !validUniqueJSONObject(request.Body) || request.BodySHA256 == "" || request.BodySHA256 != bodyDigest(request.Body) {
			return Report{}, fmt.Errorf("cachebench: trace request %q has invalid identity, body, or digest", request.RequestID)
		}
		if request.StableSegmentCount < 0 || request.StableSegmentCount > len(request.Prefix) || !validPrefix(request.Prefix) {
			return Report{}, fmt.Errorf("cachebench: trace request %q has invalid prefix", request.RequestID)
		}
		byID[request.RequestID] = request
	}
	for _, record := range records {
		request, exists := byID[record.RequestID]
		if !exists {
			return Report{}, fmt.Errorf("cachebench: observation request %q absent from trace", record.RequestID)
		}
		if record.Provider != request.Provider || record.Epoch != request.Epoch {

View on GitHub (pinned to 27d5a3981a)

Solutions

  1. Set each trace record's schema to the tool's current TraceSchema/TraceSchemaV2 value (check the package constants).
  2. Populate a unique non-empty request_id on every trace line.
  3. Regenerate the trace with the current tool version instead of editing it by hand.
Defensive patterns

Strategy: validation

Validate before calling

func validTraceHeader(requests []TraceRecord) error {
	for i, r := range requests {
		if (r.Schema != TraceSchema && r.Schema != TraceSchemaV2) || strings.TrimSpace(r.RequestID) == "" {
			return fmt.Errorf("trace request %d has invalid schema or request_id", i)
		}
	}
	return nil
}

Type guard

func isTraceSchema(s string) bool { return s == TraceSchema || s == TraceSchemaV2 }

Prevention

When it happens

Trigger: EvaluateObservedAgainstTrace iterates trace records; record i whose Schema is neither accepted constant, or whose RequestID is empty/whitespace, returns this error immediately.

Common situations: Hand-built or third-party trace JSONL missing the schema field; renamed schema constants after a version upgrade; blank request_id lines from a buggy exporter.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@27d5a3981a (2026-08-15). Data as JSON: /api/errors/1efa9da1e1a5f69c. Report an issue: GitHub.