{"record":{"id":"04cad23073f98145","repo":"JuliusBrussee/caveman","slug":"cacheengine-request-exceeds-configured-byte-limit","errorCode":null,"errorMessage":"cacheengine: request exceeds configured byte limit","messagePattern":"cacheengine: request exceeds configured byte limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/native.go","lineNumber":32,"sourceCode":")\n\n// Optimize applies provider-native cache metadata or returns copied original\n// bytes on every unsupported or unsafe path. It makes no network call.\nfunc (e *Engine) Optimize(ctx context.Context, request NativeRequest) (NativeResult, error) {\n\tif e == nil || e.guard == nil || e.prefixSafety == nil || e.resolveProfile == nil {\n\t\treturn NativeResult{}, errors.New(\"cacheengine: nil engine\")\n\t}\n\tif e.configErr != nil {\n\t\treturn NativeResult{}, e.configErr\n\t}\n\tif ctx == nil {\n\t\treturn NativeResult{}, errors.New(\"cacheengine: nil context\")\n\t}\n\tif err := ctx.Err(); err != nil {\n\t\treturn NativeResult{}, err\n\t}\n\tif len(request.Body) > e.maxRequestBytes {\n\t\treturn NativeResult{}, errors.New(\"cacheengine: request exceeds configured byte limit\")\n\t}\n\toriginal := append([]byte(nil), request.Body...)\n\tunsupported := Profile{ID: \"unsupported\", Mode: ModeUnsupported, Attribution: AttributionNone}\n\tresult := NativeResult{\n\t\tBody:     original,\n\t\tDecision: DecisionPassThrough,\n\t\tReason:   ReasonUnsupported,\n\t\tProfile:  unsupported,\n\t\tPlan: Plan{\n\t\t\tDecision: DecisionPassThrough, Reason: ReasonUnsupported,\n\t\t\tProfileID: unsupported.ID, Mode: unsupported.Mode, Attribution: unsupported.Attribution,\n\t\t\tEconomicsBasis: \"unavailable\", KeyShardCount: 1,\n\t\t},\n\t\tClaimBasis:         \"none\",\n\t\tVerifiedSavingsUSD: 0,\n\t}\n\tif !validNativeIdentity(request) {\n\t\tresult.Reason = ReasonMalformedRequest","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/cacheengine/native.go#L14-L50","documentation":"Thrown by the native engine entry point when len(request.Body) exceeds the configured e.maxRequestBytes. The check is a hard trust-boundary guard before any parsing or caching logic runs (and after nil-context/configErr checks), so oversized bodies are rejected without being read or copied.","triggerScenarios":"Calling the native Execute/Evaluate entry point with a request body larger than the engine's configured maximum request size, while ctx is non-nil and the engine has no config error.","commonSituations":"Whole conversation histories or large attached documents inlined into the body; raising prompt sizes in production without raising the engine's byte cap; a middleware in front that enforces a different (higher) limit than the engine's, so requests pass one guard and fail the other.","solutions":["Raise the engine's maxRequestBytes configuration to match your real request sizes (and your provider's own body limit)","Trim or offload large content (documents to retrieval, older turns dropped) before sending","Align limits: make any upstream proxy/body limit <= the engine's configured cap so rejection happens at the edge with a clear error"],"exampleFix":"// before\nengine, _ := cacheengine.NewNative(cacheengine.Config{}) // default cap too small for big chats\n\n// after\nengine, _ := cacheengine.NewNative(cacheengine.Config{MaxRequestBytes: 16 * 1024 * 1024})","handlingStrategy":"validation","validationCode":"if len(body) > cfg.MaxRequestBytes { return fmt.Errorf(\"body %d bytes exceeds cap %d\", len(body), cfg.MaxRequestBytes) }","typeGuard":"// n/a","tryCatchPattern":"if err := eng.Execute(ctx, req); err != nil {\n    if strings.Contains(err.Error(), \"request exceeds configured byte limit\") { return http.StatusRequestEntityTooLarge, trim(req) }\n    return 0, err\n}","preventionTips":["Set the engine cap at or above your ingress body cap","Drop old turns / offload documents instead of growing bodies unbounded"],"tags":["cacheengine","limits","request-size","configuration","go"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}