{"record":{"id":"df46deb2df3efab0","repo":"JuliusBrussee/caveman","slug":"cachebench-observation-request-q-body-digest-mis","errorCode":null,"errorMessage":"cachebench: observation request %q body digest mismatch","messagePattern":"cachebench: observation request %q body digest mismatch","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/cachebench/observed.go","lineNumber":65,"sourceCode":"\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}\n\treport, err := EvaluateObserved(records, target)\n\tif err != nil {\n\t\treturn Report{}, err\n\t}\n\treport.EvidenceLimitations = append([]string{\n\t\t\"observation population exactly joined to supplied request trace by request ID and body SHA-256\",\n\t}, report.EvidenceLimitations...)\n\treturn report, nil\n}\n\n// ObservationReadLimits bounds JSONL evidence decoding.\ntype ObservationReadLimits struct {\n\tMaxLineBytes int\n\tMaxRecords   int\n}\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/cacheengine/cachebench/observed.go#L47-L83","documentation":"The final join check: an observation's RequestBodySHA256 must be non-empty and equal to the trace record's BodySHA256. A mismatch means the body the provider actually saw differs from the body the trace recorded, invalidating any cache-reuse attribution.","triggerScenarios":"EvaluateObservedAgainstTrace where record.RequestBodySHA256 is empty or differs from request.BodySHA256 — e.g. the replay sent a re-serialized body (key order or whitespace changed) after the trace digest was computed.","commonSituations":"Body re-encoding between trace generation and replay (map iteration order in Go, JSON pretty-printers, proxy reformatting); observations captured against a different corpus revision than the trace.","solutions":["Replay with byte-identical bodies: pass the trace's raw body bytes through untouched.","Recompute the trace digest from the exact bytes the replay sends, or regenerate both together.","Remove intermediaries that normalize/reformat JSON between trace capture and observation."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func digestsAlign(records []ObservationRecord, trace []TraceRecord) error {\n\tbyID := map[string]TraceRecord{}\n\tfor _, t := range trace {\n\t\tbyID[t.RequestID] = t\n\t}\n\tfor _, r := range records {\n\t\tif t, ok := byID[r.RequestID]; ok && r.RequestBodySHA256 != t.BodySHA256 {\n\t\t\treturn fmt.Errorf(\"observation %q body digest mismatch\", r.RequestID)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Replay bodies as raw bytes from the trace; never re-marshal them.","Keep bodyDigest as the single digest implementation everywhere.","Beware Go map iteration order if you ever rebuild bodies from maps."],"tags":["go","cachebench","sha256","replay","data-integrity"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}