{"record":{"id":"1648c69f3e80569b","repo":"JuliusBrussee/caveman","slug":"cachebench-duplicate-trace-request-q","errorCode":null,"errorMessage":"cachebench: duplicate trace request %q","messagePattern":"cachebench: duplicate trace request %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/cachebench/observed.go","lineNumber":46,"sourceCode":"\t\tQualityEvidenceSHA256: bodyDigest(verification.Evidence), Usage: append(json.RawMessage(nil), rawUsage...),\n\t}\n}\n\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 {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/cacheengine/cachebench/observed.go#L28-L64","documentation":"Two trace records share the same RequestID, which would make the by-ID join ambiguous. The evaluator builds a map keyed by RequestID and rejects the second occurrence, quoting the duplicated ID.","triggerScenarios":"EvaluateObservedAgainstTrace over a trace where any RequestID appears more than once — e.g. concatenated trace files, or a retry that appended the same request twice.","commonSituations":"Merging trace shards that overlap; replay reruns appending to an existing trace file instead of truncating; exporters that reuse sequence numbers after a restart.","solutions":["Deduplicate the trace by request_id, keeping one record per ID.","Do not append a new replay to an existing trace file; write to a fresh file per epoch.","If both entries are genuinely distinct requests, assign unique request_ids at generation time."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func dedupeTrace(trace []TraceRecord) ([]TraceRecord, error) {\n\tseen := map[string]bool{}\n\tout := make([]TraceRecord, 0, len(trace))\n\tfor _, r := range trace {\n\t\tif seen[r.RequestID] {\n\t\t\treturn nil, fmt.Errorf(\"duplicate trace request %q\", r.RequestID)\n\t\t}\n\t\tseen[r.RequestID] = true\n\t\tout = append(out, r)\n\t}\n\treturn out, nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write each replay epoch to a fresh trace file; never append across runs.","Deduplicate merged trace shards by request_id before evaluation.","Make request_id generation idempotent per logical request."],"tags":["go","cachebench","duplicates","data-integrity"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}