JuliusBrussee/caveman · error

cachebench: replay gap before

Error message

cachebench: replay gap before %q exceeds limit %s

What it means

ValidateReplay measures the absolute-time gap between consecutive trace records; the gap before request %q exceeds ReplayLimits.MaxGap. Large gaps would make faithful replay impractically long, so preflight rejects them.

Solutions

  1. Raise MaxGap or increase TimeScale to compress idle periods
  2. Split the trace at long idle boundaries
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at cacheengine/cachebench/replay.go:409

		timing[record.TimingBasis] = true
		if limits.RequireProviderTokens && record.TokenBasis != TokenProviderCounted {
			return ReplayPreflight{}, fmt.Errorf("cachebench: replay request %q token basis %q is not provider-counted", record.RequestID, record.TokenBasis)
		}
		tokens[record.TokenBasis] = true
		if record.DeclaredInputTokens <= 0 || record.DeclaredInputTokens < record.PrefixTokens || record.MaxOutputTokens <= 0 || !requestBudgetMatchesBody(record) {
			return ReplayPreflight{}, fmt.Errorf("cachebench: replay request %q has invalid billed-token budget", record.RequestID)
		}
		input, output := int64(record.DeclaredInputTokens), int64(record.MaxOutputTokens)
		if input > limits.MaxDeclaredBilledTokens-worstCase || output > limits.MaxDeclaredBilledTokens-worstCase-input {
			return ReplayPreflight{}, fmt.Errorf("cachebench: replay declared billed-token ceiling exceeds limit %d", limits.MaxDeclaredBilledTokens)
		}
		declaredInput += input
		declaredOutput += output
		worstCase += input + output
		if !previous.IsZero() {
			gap, err := scaledReplayGap(at.Sub(previous), timeScale)
			if err != nil || gap > limits.MaxGap {
				return ReplayPreflight{}, fmt.Errorf("cachebench: replay gap before %q exceeds limit %s", record.RequestID, limits.MaxGap)
			}
			if int64(gap) > math.MaxInt64-scheduled {
				return ReplayPreflight{}, errors.New("cachebench: replay schedule duration overflow")
			}
			scheduled += int64(gap)
		}
		previous = at
	}
	bases := make([]string, 0, len(timing))
	for basis := range timing {
		bases = append(bases, basis)
	}
	sort.Strings(bases)
	tokenBases := make([]string, 0, len(tokens))
	for basis := range tokens {
		tokenBases = append(tokenBases, basis)
	}
	sort.Strings(tokenBases)

View on GitHub (pinned to 766dce6b13)