JuliusBrussee/caveman · error

cacheengine: invalid epoch

Error message

cacheengine: invalid epoch

What it means

validatePlanRequest rejects a PlanRequest whose Epoch field fails validIdentity at up to 4096 bytes. The epoch names the cache generation a plan is computed against; the error fires when it is empty, longer than 4096 bytes, or contains characters outside the identity validator's allowed set, since an unbounded or malformed epoch could not safely key plan state. Reached from both Plan and StartEpoch.

Solutions

  1. Set a non-empty epoch identifier within 4096 bytes and identity-safe characters
  2. Derive the epoch from a stable version/rollout identifier instead of arbitrary text
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at cacheengine/engine.go:273

	return Plan{
		Decision:       DecisionNewEpoch,
		Reason:         string(cacheguard.DecisionNewEpoch),
		ProfileID:      profile.ID,
		Mode:           profile.Mode,
		Attribution:    profile.Attribution,
		PrefixSHA256:   result.PrefixSHA256,
		EconomicsBasis: economicsBasis,
		KeyShardCount:  1,
		Warnings:       warnings,
	}, nil
}

func validatePlanRequest(request PlanRequest) error {
	if !validIdentity(request.Scope, 4096, false) {
		return errors.New("cacheengine: invalid scope")
	}
	if !validIdentity(request.Epoch, 4096, false) {
		return errors.New("cacheengine: invalid epoch")
	}
	if !validIdentity(request.PartitionKey, 4096, true) {
		return errors.New("cacheengine: invalid partition key")
	}
	if request.ExpectedCalls < 0 || request.ExpectedRequestsPerMinute < 0 {
		return errors.New("cacheengine: negative traffic expectation")
	}
	profile := normalizedProfile(request.Profile)
	if !validIdentity(profile.ID, 256, false) || !validIdentity(profile.Provider, 64, true) || !validIdentity(profile.OptimizerID, 256, true) {
		return errors.New("cacheengine: invalid profile identity")
	}
	if profile.Mode != ModeUnsupported && profile.Mode != ModeImplicit && profile.Mode != ModeAffinity && profile.Mode != ModeExplicit {
		return fmt.Errorf("cacheengine: unknown mode %q", profile.Mode)
	}
	if profile.Mode != ModeUnsupported {
		if profile.MaxBreakpoints <= 0 || profile.MinPrefixTokens < 0 || profile.MaxRPMPerKey < 0 || profile.TTL < 0 {
			return errors.New("cacheengine: invalid cache thresholds")
		}

View on GitHub (pinned to 766dce6b13)