JuliusBrussee/caveman · error

cacheengine: cumulative token count overflow

Error message

cacheengine: cumulative token count overflow

What it means

breakpointCandidates accumulates segment token counts and detects overflow of the cumulative counter; an overflow means the prefix is too large to plan breakpoints for, so planning fails rather than producing wrong cache metadata.

Solutions

  1. Fix the segment token measurements — realistic counts are many orders of magnitude below MaxInt
  2. Reject telemetry that reports near-overflow token values at ingestion
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cacheengine/engine.go:369 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/d33c202147a5dc3b. Report an issue: GitHub.

Appendix: source

Thrown at cacheengine/engine.go:369

	var lengths [8]byte
	binary.BigEndian.PutUint32(lengths[:4], uint32(len(name)))
	binary.BigEndian.PutUint32(lengths[4:], uint32(len(content)))
	dst = append(dst, lengths[:]...)
	dst = append(dst, name...)
	return append(dst, content...)
}

func breakpointCandidates(segments []Segment, defaultCalls int, profile Profile) ([]Breakpoint, bool, bool, error) {
	var candidates []Breakpoint
	var prefix []byte
	cumulativeTokens := 0
	previousCalls := math.MaxInt
	belowMinimum := false
	negative := false
	for index, segment := range segments {
		prefix = appendFrame(prefix, segment.Name, segment.Content)
		if segment.Tokens > math.MaxInt-cumulativeTokens {
			return nil, false, false, errors.New("cacheengine: cumulative token count overflow")
		}
		cumulativeTokens += segment.Tokens
		calls := segment.ExpectedCalls
		if calls == 0 {
			calls = defaultCalls
		}
		if calls > previousCalls {
			return nil, false, false, errors.New("cacheengine: longer prefix cannot have higher expected reuse")
		}
		previousCalls = calls
		if calls < 2 {
			continue
		}
		if cumulativeTokens > 0 && cumulativeTokens < profile.MinPrefixTokens {
			belowMinimum = true
			continue
		}
		net := 0.0

View on GitHub (pinned to 766dce6b13)