{"record":{"id":"3577497b13bb14d2","repo":"JuliusBrussee/caveman","slug":"cachebench-optimize-request-q-w","errorCode":null,"errorMessage":"cachebench: optimize request %q: %w","messagePattern":"cachebench: optimize request %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/cachebench/replay.go","lineNumber":513,"sourceCode":"\ntype preparedReplay struct {\n\trecord    TraceRecord\n\toptimized cacheengine.NativeResult\n}\n\nfunc (runner ReplayRunner) prepare(ctx context.Context, records []TraceRecord) ([]preparedReplay, error) {\n\tprepared := make([]preparedReplay, 0, len(records))\n\tfor _, record := range records {\n\t\tif err := ctx.Err(); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: replay preparation interrupted: %w\", err)\n\t\t}\n\t\tnative, err := record.NativeRequest()\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\toptimized, err := runner.Engine.Optimize(ctx, native)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: optimize request %q: %w\", record.RequestID, err)\n\t\t}\n\t\tequivalent := bytes.Equal(native.Body, optimized.Body)\n\t\tif optimized.Applied {\n\t\t\tequivalent = ModelVisibleEquivalent(native.Body, optimized.Body)\n\t\t}\n\t\tif !equivalent {\n\t\t\treturn nil, &ReplayRunError{\n\t\t\t\tRequestID: record.RequestID, FailureCode: \"model_visible_mismatch\",\n\t\t\t\tErr: fmt.Errorf(\"cachebench: request %q failed model-visible equivalence\", record.RequestID),\n\t\t\t}\n\t\t}\n\t\tif optimized.Decision != cacheengine.DecisionApply && optimized.Decision != cacheengine.DecisionObserveOnly && optimized.Reason != cacheengine.ReasonBelowMinimum {\n\t\t\treturn nil, &ReplayRunError{\n\t\t\t\tRequestID: record.RequestID, FailureCode: \"engine_not_cacheable\",\n\t\t\t\tErr: fmt.Errorf(\"cachebench: request %q is not cacheable: %s\", record.RequestID, optimized.Reason),\n\t\t\t}\n\t\t}\n\t\tprepared = append(prepared, preparedReplay{record: record, optimized: optimized})","sourceCodeStart":495,"sourceCodeEnd":531,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/cacheengine/cachebench/replay.go#L495-L531","documentation":"Engine.Optimize returned an error while preparing the record identified by RequestID. The replay runner refuses to send a request it could not optimize, and wraps the engine's error with the request id for correlation.","triggerScenarios":"Any cacheengine.Optimize failure during prepare: malformed request body that the engine cannot parse, engine misconfiguration (no rules loaded), engine backend/store errors, or context cancellation surfacing through the engine.","commonSituations":"Trace bodies recorded against an older API schema than the engine expects; engine initialized without its rule set; a dependency (cache store) down when Optimize consults it; version skew between the trace capture and the engine.","solutions":["Unwrap the error (%w chain) and read the underlying engine error — it names the actual cause.","Replay the single failing RequestID through Engine.Optimize directly to reproduce in isolation.","Check engine initialization (rules/config loaded, backend reachable) before starting the replay.","If the record's body is malformed or from an incompatible schema version, re-capture the trace or upgrade the engine."],"exampleFix":"// before\nif err := runner.Run(ctx, records, emit); err != nil { log.Fatal(err) } // opaque chain\n\n// after\nif err := runner.Run(ctx, records, emit); err != nil {\n\tvar rre *cachebench.ReplayRunError\n\tif errors.As(err, &rre) {\n\t\tlog.Printf(\"request %s failed: %v\", rre.RequestID, rre.Err)\n\t}\n\tlog.Fatal(err)\n}","handlingStrategy":"try-catch","validationCode":"for _, r := range records {\n    if _, err := r.NativeRequest(); err != nil {\n        return fmt.Errorf(\"record %s has malformed native request: %w\", r.RequestID, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := runner.Run(ctx, records, emit); err != nil {\n    var rre *cachebench.ReplayRunError\n    if errors.As(err, &rre) {\n        log.Printf(\"request %s: optimize failed: %v\", rre.RequestID, errors.Unwrap(err))\n    }\n    return err\n}","preventionTips":["Smoke-test Engine.Optimize against a sample record before the full replay.","Keep trace schema and engine version in lockstep; re-capture traces after provider schema changes.","Log engine initialization results (rules loaded, backend reachable) before replay."],"tags":["cachebench","engine","optimization","replay"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}