{"record":{"id":"0bc0dee3abb448f4","repo":"JuliusBrussee/caveman","slug":"cachebench-invalid-replay-gap","errorCode":null,"errorMessage":"cachebench: invalid replay gap","messagePattern":"cachebench: invalid replay gap","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/cachebench/replay.go","lineNumber":783,"sourceCode":"func replayEvidenceBase(record TraceRecord, optimized cacheengine.NativeResult, scale float64, scheduled, started time.Time, tolerance time.Duration) ReplayEvidenceRecord {\n\tdrift := absDuration(started.Sub(scheduled))\n\treturn ReplayEvidenceRecord{\n\t\tSchema: ReplayEvidenceSchema, RequestID: record.RequestID,\n\t\tTraceBodySHA256: record.BodySHA256, WireBodySHA256: bodyDigest(optimized.Body),\n\t\tProvider: record.Provider, Model: record.Model, Epoch: record.Epoch,\n\t\tTimingBasis: record.TimingBasis, TokenBasis: record.TokenBasis, TimeScale: scale,\n\t\tTimingFaithful: record.TimingBasis == TimingGrounded && scale == 1 && drift <= tolerance,\n\t\tScheduledAt:    scheduled.Format(time.RFC3339Nano), ScheduleDriftMilliseconds: drift.Milliseconds(),\n\t\tScheduleToleranceMilliseconds: tolerance.Milliseconds(),\n\t\tStartedAt:                     started.Format(time.RFC3339Nano), Applied: optimized.Applied,\n\t\tDecision: optimized.Decision, Reason: optimized.Reason, Attribution: optimized.Profile.Attribution,\n\t\tOptimizerIDs: append([]string(nil), optimized.OptimizerIDs...),\n\t}\n}\n\nfunc scaledReplayGap(gap time.Duration, scale float64) (time.Duration, error) {\n\tif gap < 0 || scale <= 0 || math.IsNaN(scale) || math.IsInf(scale, 0) {\n\t\treturn 0, errors.New(\"cachebench: invalid replay gap\")\n\t}\n\tif gap == 0 {\n\t\treturn 0, nil\n\t}\n\tif scale > float64(math.MaxInt64)/float64(gap) {\n\t\treturn 0, errors.New(\"cachebench: replay gap overflow\")\n\t}\n\treturn time.Duration(float64(gap) * scale), nil\n}\n\nfunc sleepContext(ctx context.Context, delay time.Duration) error {\n\tif delay <= 0 {\n\t\treturn nil\n\t}\n\ttimer := time.NewTimer(delay)\n\tdefer timer.Stop()\n\tselect {\n\tcase <-ctx.Done():","sourceCodeStart":765,"sourceCodeEnd":801,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/cacheengine/cachebench/replay.go#L765-L801","documentation":"Raised while building replay evidence: the computed per-request gap (the interval between scheduled and started times, or a derived pause) is not a valid non-negative duration — negative, NaN-like, or otherwise out of allowed range for gap accounting.","triggerScenarios":"Thrown at cacheengine/cachebench/replay.go:783 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check clock sources: a monotonic-vs-wall-clock mix can yield negative intervals","Ensure the runner's Now func is injectable and consistent across scheduling and dispatch","Reject trace records whose timing fields produce negative gaps at preflight"],"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"}