JuliusBrussee/caveman · error

cachebench: replay gap overflow

Error message

cachebench: replay gap overflow

What it means

Raised when a replay gap value cannot be represented as a time.Duration milliseconds count without int64 overflow. Individual gaps large enough (or scaled sums) to exceed the duration range trip this before evidence emission.

Solutions

  1. Clamp trace gap values to sane bounds during corpus validation
  2. Split extremely long idle periods into separate replay sessions
  3. Verify the gap derivation isn't double-counting elapsed time across rows
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cacheengine/cachebench/replay.go:789 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/61a6766b016f5d38. Report an issue: GitHub.

Appendix: source

Thrown at cacheengine/cachebench/replay.go:789

		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():
		return ctx.Err()
	case <-timer.C:
		return nil
	}
}

View on GitHub (pinned to 766dce6b13)