{"record":{"id":"176a27be5619ec5d","repo":"JuliusBrussee/caveman","slug":"cacheengine-invalid-cache-thresholds","errorCode":null,"errorMessage":"cacheengine: invalid cache thresholds","messagePattern":"cacheengine: invalid cache thresholds","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/engine.go","lineNumber":290,"sourceCode":"\tif !validIdentity(request.Epoch, 4096, false) {\n\t\treturn errors.New(\"cacheengine: invalid epoch\")\n\t}\n\tif !validIdentity(request.PartitionKey, 4096, true) {\n\t\treturn errors.New(\"cacheengine: invalid partition key\")\n\t}\n\tif request.ExpectedCalls < 0 || request.ExpectedRequestsPerMinute < 0 {\n\t\treturn errors.New(\"cacheengine: negative traffic expectation\")\n\t}\n\tprofile := normalizedProfile(request.Profile)\n\tif !validIdentity(profile.ID, 256, false) || !validIdentity(profile.Provider, 64, true) || !validIdentity(profile.OptimizerID, 256, true) {\n\t\treturn errors.New(\"cacheengine: invalid profile identity\")\n\t}\n\tif profile.Mode != ModeUnsupported && profile.Mode != ModeImplicit && profile.Mode != ModeAffinity && profile.Mode != ModeExplicit {\n\t\treturn fmt.Errorf(\"cacheengine: unknown mode %q\", profile.Mode)\n\t}\n\tif profile.Mode != ModeUnsupported {\n\t\tif profile.MaxBreakpoints <= 0 || profile.MinPrefixTokens < 0 || profile.MaxRPMPerKey < 0 || profile.TTL < 0 {\n\t\t\treturn errors.New(\"cacheengine: invalid cache thresholds\")\n\t\t}\n\t\tswitch profile.Attribution {\n\t\tcase AttributionNone, AttributionOrganic, AttributionAffinity, AttributionCausal:\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"cacheengine: unknown attribution %q\", profile.Attribution)\n\t\t}\n\t\tif profile.EconomicsKnown && (!finiteNonNegative(profile.WriteMultiplier) || !finiteNonNegative(profile.ReadMultiplier)) {\n\t\t\treturn errors.New(\"cacheengine: invalid cache economics\")\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc normalizedProfile(profile Profile) Profile {\n\tif profile.Mode == ModeUnsupported {\n\t\tif profile.ID == \"\" {\n\t\t\tprofile.ID = \"unsupported\"\n\t\t}","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/cacheengine/engine.go#L272-L308","documentation":"Thrown by validatePlanRequest for any profile mode other than ModeUnsupported when threshold fields are out of range: MaxBreakpoints must be > 0, and MinPrefixTokens, MaxRPMPerKey, and TTL must all be >= 0. These thresholds drive breakpoint selection and key rotation, so zero/negative values would break planning.","triggerScenarios":"Calling Plan with ModeImplicit/ModeAffinity/ModeExplicit and MaxBreakpoints == 0 (often the zero value of an unset struct field), a negative TTL, negative MinPrefixTokens, or negative MaxRPMPerKey.","commonSituations":"Constructing a Profile literal and forgetting MaxBreakpoints (int zero value is 0, which fails the > 0 check); loading thresholds from YAML/JSON where a typo yields 0; passing a negative TTL to mean 'no expiry'.","solutions":["Set MaxBreakpoints to a positive value (e.g. 4) whenever the mode is not ModeUnsupported","Use 0 rather than negative values for MinPrefixTokens/MaxRPMPerKey/TTL when you want the 'none' behavior","Validate loaded config numbers before building the PlanRequest"],"exampleFix":"// before\nprofile := cacheengine.Profile{ID: \"p\", Mode: cacheengine.ModeImplicit} // MaxBreakpoints zero value = 0\n\n// after\nprofile := cacheengine.Profile{ID: \"p\", Mode: cacheengine.ModeImplicit, MaxBreakpoints: 4, MinPrefixTokens: 1024, TTL: 5 * time.Minute}","handlingStrategy":"validation","validationCode":"func thresholdsOK(p cacheengine.Profile) bool {\n    if p.Mode == cacheengine.ModeUnsupported { return true }\n    return p.MaxBreakpoints > 0 && p.MinPrefixTokens >= 0 && p.MaxRPMPerKey >= 0 && p.TTL >= 0\n}","typeGuard":"// n/a","tryCatchPattern":null,"preventionTips":["Unit-test profile construction so MaxBreakpoints is never the zero value","Validate config-loaded numbers before building the request"],"tags":["cacheengine","validation","thresholds","go"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}