{"record":{"id":"36b8f86a3986122a","repo":"JuliusBrussee/caveman","slug":"cachebench-replay-request-q-has-invalid-billed-t","errorCode":null,"errorMessage":"cachebench: replay request %q has invalid billed-token budget","messagePattern":"cachebench: replay request %q has invalid billed-token budget","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/cachebench/replay.go","lineNumber":397,"sourceCode":"\t\t\treturn ReplayPreflight{}, fmt.Errorf(\"cachebench: replay request %q needs %s billed-token metadata\", record.RequestID, TraceSchema)\n\t\t}\n\t\tif _, err := record.NativeRequest(); err != nil {\n\t\t\treturn ReplayPreflight{}, fmt.Errorf(\"cachebench: replay request %d: %w\", index, err)\n\t\t}\n\t\tat, err := time.Parse(time.RFC3339Nano, record.At)\n\t\tif err != nil || !previous.IsZero() && at.Before(previous) {\n\t\t\treturn ReplayPreflight{}, fmt.Errorf(\"cachebench: replay request %q has invalid time order\", record.RequestID)\n\t\t}\n\t\tif limits.RequireGroundedTiming && record.TimingBasis != TimingGrounded {\n\t\t\treturn ReplayPreflight{}, fmt.Errorf(\"cachebench: replay request %q timing basis %q is not globally grounded\", record.RequestID, record.TimingBasis)\n\t\t}\n\t\ttiming[record.TimingBasis] = true\n\t\tif limits.RequireProviderTokens && record.TokenBasis != TokenProviderCounted {\n\t\t\treturn ReplayPreflight{}, fmt.Errorf(\"cachebench: replay request %q token basis %q is not provider-counted\", record.RequestID, record.TokenBasis)\n\t\t}\n\t\ttokens[record.TokenBasis] = true\n\t\tif record.DeclaredInputTokens <= 0 || record.DeclaredInputTokens < record.PrefixTokens || record.MaxOutputTokens <= 0 || !requestBudgetMatchesBody(record) {\n\t\t\treturn ReplayPreflight{}, fmt.Errorf(\"cachebench: replay request %q has invalid billed-token budget\", record.RequestID)\n\t\t}\n\t\tinput, output := int64(record.DeclaredInputTokens), int64(record.MaxOutputTokens)\n\t\tif input > limits.MaxDeclaredBilledTokens-worstCase || output > limits.MaxDeclaredBilledTokens-worstCase-input {\n\t\t\treturn ReplayPreflight{}, fmt.Errorf(\"cachebench: replay declared billed-token ceiling exceeds limit %d\", limits.MaxDeclaredBilledTokens)\n\t\t}\n\t\tdeclaredInput += input\n\t\tdeclaredOutput += output\n\t\tworstCase += input + output\n\t\tif !previous.IsZero() {\n\t\t\tgap, err := scaledReplayGap(at.Sub(previous), timeScale)\n\t\t\tif err != nil || gap > limits.MaxGap {\n\t\t\t\treturn ReplayPreflight{}, fmt.Errorf(\"cachebench: replay gap before %q exceeds limit %s\", record.RequestID, limits.MaxGap)\n\t\t\t}\n\t\t\tif int64(gap) > math.MaxInt64-scheduled {\n\t\t\t\treturn ReplayPreflight{}, errors.New(\"cachebench: replay schedule duration overflow\")\n\t\t\t}\n\t\t\tscheduled += int64(gap)\n\t\t}","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/cacheengine/cachebench/replay.go#L379-L415","documentation":"The record's declared token budget is inconsistent: DeclaredInputTokens <= 0 or below its own PrefixTokens, MaxOutputTokens <= 0, or the declared budget does not match what the request body encodes (requestBudgetMatchesBody failed).","triggerScenarios":"Thrown at cacheengine/cachebench/replay.go:397 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Regenerate the trace so declared token ceilings match the bodies","Fix the max-token field embedded in the request body"],"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"}