{"record":{"id":"0a6e530755a19f0d","repo":"JuliusBrussee/caveman","slug":"cachebench-trace-request-q-has-invalid-identity","errorCode":null,"errorMessage":"cachebench: trace request %q has invalid identity, body, or digest","messagePattern":"cachebench: trace request %q has invalid identity, body, or digest","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/cachebench/observed.go","lineNumber":49,"sourceCode":"\n// EvaluateObservedAgainstTrace requires exact request population and body joins.\nfunc EvaluateObservedAgainstTrace(records []ObservationRecord, trace []TraceRecord, target Target) (Report, error) {\n\tif err := validateObservationRecords(records); err != nil {\n\t\treturn Report{}, err\n\t}\n\tif len(records) != len(trace) {\n\t\treturn Report{}, fmt.Errorf(\"cachebench: observation population %d does not match trace population %d\", len(records), len(trace))\n\t}\n\tbyID := make(map[string]TraceRecord, len(trace))\n\tfor index, request := range trace {\n\t\tif request.Schema != TraceSchema && request.Schema != TraceSchemaV2 || strings.TrimSpace(request.RequestID) == \"\" {\n\t\t\treturn Report{}, fmt.Errorf(\"cachebench: trace request %d has invalid schema or request_id\", index)\n\t\t}\n\t\tif _, exists := byID[request.RequestID]; exists {\n\t\t\treturn Report{}, fmt.Errorf(\"cachebench: duplicate trace request %q\", request.RequestID)\n\t\t}\n\t\tif strings.TrimSpace(request.Provider) == \"\" || strings.TrimSpace(request.Epoch) == \"\" || !validUniqueJSONObject(request.Body) || request.BodySHA256 == \"\" || request.BodySHA256 != bodyDigest(request.Body) {\n\t\t\treturn Report{}, fmt.Errorf(\"cachebench: trace request %q has invalid identity, body, or digest\", request.RequestID)\n\t\t}\n\t\tif request.StableSegmentCount < 0 || request.StableSegmentCount > len(request.Prefix) || !validPrefix(request.Prefix) {\n\t\t\treturn Report{}, fmt.Errorf(\"cachebench: trace request %q has invalid prefix\", request.RequestID)\n\t\t}\n\t\tbyID[request.RequestID] = request\n\t}\n\tfor _, record := range records {\n\t\trequest, exists := byID[record.RequestID]\n\t\tif !exists {\n\t\t\treturn Report{}, fmt.Errorf(\"cachebench: observation request %q absent from trace\", record.RequestID)\n\t\t}\n\t\tif record.Provider != request.Provider || record.Epoch != request.Epoch {\n\t\t\treturn Report{}, fmt.Errorf(\"cachebench: observation request %q provider/epoch mismatch\", record.RequestID)\n\t\t}\n\t\tif record.RequestBodySHA256 == \"\" || record.RequestBodySHA256 != request.BodySHA256 {\n\t\t\treturn Report{}, fmt.Errorf(\"cachebench: observation request %q body digest mismatch\", record.RequestID)\n\t\t}\n\t}","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/cacheengine/cachebench/observed.go#L31-L67","documentation":"A trace record failed one of the identity/body checks: Provider or Epoch blank, Body not a valid unique JSON object, BodySHA256 empty, or BodySHA256 not equal to bodyDigest(Body). The digest check guarantees the recorded body is byte-faithful, which the evidence chain in the report relies on.","triggerScenarios":"EvaluateObservedAgainstTrace validating a trace record whose provider/epoch fields are whitespace, whose body is an array or contains duplicate JSON keys, or whose recorded BodySHA256 does not match a fresh SHA-256 of the body bytes.","commonSituations":"Re-serializing trace JSON through a tool that reformats the body field (breaking the digest); editing body content by hand after generation; body stored as a JSON array instead of an object.","solutions":["Recompute and store bodyDigest(body) whenever the body field is written or modified.","Keep body as a compact, canonical JSON object; avoid pretty-printing or key reordering after generation.","Fill in provider and epoch on every trace record.","Regenerate the trace from the replay rather than transforming it externally."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func validTraceRecord(r TraceRecord) error {\n\tif strings.TrimSpace(r.Provider) == \"\" || strings.TrimSpace(r.Epoch) == \"\" {\n\t\treturn fmt.Errorf(\"request %q missing provider/epoch\", r.RequestID)\n\t}\n\tif !validUniqueJSONObject(r.Body) {\n\t\treturn fmt.Errorf(\"request %q body not a unique JSON object\", r.RequestID)\n\t}\n\tif r.BodySHA256 != bodyDigest(r.Body) {\n\t\treturn fmt.Errorf(\"request %q digest stale; recompute\", r.RequestID)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute BodySHA256 with bodyDigest at write time and never reformat the body afterwards.","Treat body bytes as opaque; pass them through unchanged between stages.","Add a CI check that recomputes digests over fixture traces."],"tags":["go","cachebench","sha256","data-integrity","validation"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}