{"record":{"id":"b53ab24d852cc860","repo":"JuliusBrussee/caveman","slug":"cachebench-trace-line-d-incomplete-or-mismatche","errorCode":null,"errorMessage":"cachebench: trace line %d: incomplete or mismatched billed-token budget","messagePattern":"cachebench: trace line (.+?): incomplete or mismatched billed-token budget","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/cachebench/trace.go","lineNumber":331,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"cachebench: trace line %d: invalid schema or request_id\", line)\n\t\t}\n\t\tif _, err := time.Parse(time.RFC3339Nano, record.At); err != nil || !validTraceIdentity(record) || record.PrefixTokens < 0 {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: trace line %d: incomplete request identity\", line)\n\t\t}\n\t\tif len(record.Body) > limits.MaxBodyBytes || !json.Valid(record.Body) || record.BodySHA256 == \"\" || record.BodySHA256 != bodyDigest(record.Body) {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: trace line %d: invalid body or digest\", line)\n\t\t}\n\t\tif record.StableSegmentCount < 0 || record.StableSegmentCount > len(record.Prefix) || !validPrefix(record.Prefix) {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: trace line %d: invalid prefix\", line)\n\t\t}\n\t\tif record.Schema == TraceSchema || record.Schema == TraceSchemaV2 {\n\t\t\tif record.ExpectedRPM <= 0 || record.ExpectedCalls <= 0 || !validTimingBasis(record.TimingBasis) {\n\t\t\t\treturn nil, fmt.Errorf(\"cachebench: trace line %d: incomplete replay metadata\", line)\n\t\t\t}\n\t\t}\n\t\tif record.Schema == TraceSchema {\n\t\t\tif record.DeclaredInputTokens <= 0 || record.DeclaredInputTokens < record.PrefixTokens || record.MaxOutputTokens <= 0 || !requestBudgetMatchesBody(record) {\n\t\t\t\treturn nil, fmt.Errorf(\"cachebench: trace line %d: incomplete or mismatched billed-token budget\", line)\n\t\t\t}\n\t\t}\n\t\tseen[record.RequestID] = true\n\t\trecord.Body = append(json.RawMessage(nil), record.Body...)\n\t\trecords = append(records, record)\n\t}\n\tif err := scanner.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"cachebench: read trace: %w\", err)\n\t}\n\tif len(records) == 0 {\n\t\treturn nil, errors.New(\"cachebench: no trace records\")\n\t}\n\treturn records, nil\n}\n\n// NativeRequest reconstructs exact optimizer input captured by v2 or v3 trace.\n// Legacy v1 traces remain readable for observation joins, but cannot drive live\n// replay because they omitted routing and economics inputs.","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/cacheengine/cachebench/trace.go#L313-L349","documentation":"Fires in ReadTraceJSONLWithLimits for v3 (TraceSchema) records: the declared billed-token budget (DeclaredInputTokens and related declared totals) must be present and consistent — DeclaredInputTokens must be positive and at least PrefixTokens. It means the record's declared token accounting is missing or contradicts the measured prefix tokens, so replay billing cannot be reconstructed faithfully.","triggerScenarios":"Thrown at cacheengine/cachebench/trace.go:331 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Regenerate the trace so DeclaredInputTokens is positive and >= PrefixTokens on every v3 record","Re-capture the trace with the current cachebench writer; older writers may have omitted the billed-token fields","Edit the offending JSONL line to carry a consistent declared budget and re-run replay"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}