JuliusBrussee/caveman · error
cachebench: invalid replay gap
Error message
cachebench: invalid replay gap
What it means
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.
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
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at cacheengine/cachebench/replay.go:783 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18).
Data as JSON: /api/errors/0bc0dee3abb448f4.
Report an issue: GitHub.
Appendix: source
Thrown at cacheengine/cachebench/replay.go:783
func replayEvidenceBase(record TraceRecord, optimized cacheengine.NativeResult, scale float64, scheduled, started time.Time, tolerance time.Duration) ReplayEvidenceRecord {
drift := absDuration(started.Sub(scheduled))
return ReplayEvidenceRecord{
Schema: ReplayEvidenceSchema, RequestID: record.RequestID,
TraceBodySHA256: record.BodySHA256, WireBodySHA256: bodyDigest(optimized.Body),
Provider: record.Provider, Model: record.Model, Epoch: record.Epoch,
TimingBasis: record.TimingBasis, TokenBasis: record.TokenBasis, TimeScale: scale,
TimingFaithful: record.TimingBasis == TimingGrounded && scale == 1 && drift <= tolerance,
ScheduledAt: scheduled.Format(time.RFC3339Nano), ScheduleDriftMilliseconds: drift.Milliseconds(),
ScheduleToleranceMilliseconds: tolerance.Milliseconds(),
StartedAt: started.Format(time.RFC3339Nano), Applied: optimized.Applied,
Decision: optimized.Decision, Reason: optimized.Reason, Attribution: optimized.Profile.Attribution,
OptimizerIDs: append([]string(nil), optimized.OptimizerIDs...),
}
}
func scaledReplayGap(gap time.Duration, scale float64) (time.Duration, error) {
if gap < 0 || scale <= 0 || math.IsNaN(scale) || math.IsInf(scale, 0) {
return 0, errors.New("cachebench: invalid replay gap")
}
if gap == 0 {
return 0, nil
}
if scale > float64(math.MaxInt64)/float64(gap) {
return 0, errors.New("cachebench: replay gap overflow")
}
return time.Duration(float64(gap) * scale), nil
}
func sleepContext(ctx context.Context, delay time.Duration) error {
if delay <= 0 {
return nil
}
timer := time.NewTimer(delay)
defer timer.Stop()
select {
case <-ctx.Done():View on GitHub (pinned to 766dce6b13)