{"record":{"id":"8385ed27a51be4bf","repo":"JuliusBrussee/caveman","slug":"trial-compression-replay-exceeds-d-byte-payload-b","errorCode":null,"errorMessage":"trial compression replay exceeds %d-byte payload budget","messagePattern":"trial compression replay exceeds (.+?)-byte payload budget","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/trial_store.go","lineNumber":552,"sourceCode":"\t\tif recovery != nil {\n\t\t\t_ = recovery.Close()\n\t\t}\n\t}()\n\tvar eng *engine.Engine\n\tvar totalBytes int64\n\tvar payloadCount, before, after, transformed int\n\tfor rows.Next() {\n\t\tvar p struct {\n\t\t\traw                       []byte\n\t\t\tbytes                     int64\n\t\t\tprovider, model, endpoint string\n\t\t}\n\t\tif err := rows.Scan(&p.raw, &p.bytes, &p.provider, &p.model, &p.endpoint); err != nil {\n\t\t\treturn TrialMove{}, \"\", err\n\t\t}\n\t\tpayloadCount++\n\t\tif p.bytes < 0 || p.bytes > maxBytes || totalBytes > maxBytes-p.bytes {\n\t\t\treturn TrialMove{}, \"\", fmt.Errorf(\"trial compression replay exceeds %d-byte payload budget\", maxBytes)\n\t\t}\n\t\ttotalBytes += p.bytes\n\t\tadapter := replayAdapter(p.provider)\n\t\tif adapter == nil {\n\t\t\tcontinue\n\t\t}\n\t\tsegments, reassemble, ok := adapter.ExtractCompressible(p.raw, providers.RequestMetadata{\n\t\t\tProvider: p.provider,\n\t\t\tModel:    p.model,\n\t\t\tEndpoint: p.endpoint,\n\t\t})\n\t\tif !ok || len(segments) == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tif eng == nil {\n\t\t\tif err := os.MkdirAll(filepath.Dir(ccrPath), 0o700); err != nil {\n\t\t\t\treturn TrialMove{}, \"\", err\n\t\t\t}","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/proxy/internal/store/trial_store.go#L534-L570","documentation":"During AnalyzeTrial's compression replay, the store accumulates the request_bytes of every captured payload for the trial and aborts as soon as any single payload is negative/oversized or the running total would exceed maxBytes (CAVE_TRIAL_REPLAY_MAX_BYTES, default 256 MiB, clamped back to the default if misconfigured). This is a resource guard: replay decompresses and transforms payloads in memory, so an unbounded trial could exhaust RAM.","triggerScenarios":"Analyzing a long-running trial whose captured requests sum past 256 MiB (e.g. hundreds of large-context Claude/OpenAI requests), or one single payload larger than the budget; alternatively setting CAVE_TRIAL_REPLAY_MAX_BYTES very low so even modest trials trip it.","commonSituations":"Long agent sessions with big system prompts and file contexts; lowering the env cap without realizing it applies to the cumulative sum; a corrupted row where request_bytes disagrees wildly with raw_request length.","solutions":["Raise the budget for the analysis run: CAVE_TRIAL_REPLAY_MAX_BYTES=1073741824 caveman ... (confirm host RAM first).","Start a fresh trial for the workload you actually want to analyze so captured payloads stay under the default budget.","If the cap was deliberately lowered, re-check its value — values <= 0 fall back to the 256 MiB default, but a small positive value silently shrinks it.","Inspect trial_payloads (SELECT SUM(request_bytes) ...) to see whether one giant request or sheer count is the cause."],"exampleFix":"# before\nexport CAVE_TRIAL_REPLAY_MAX_BYTES=1048576  # 1 MiB, too small\ncaveman trial analyze\n\n# after\nexport CAVE_TRIAL_REPLAY_MAX_BYTES=1073741824  # 1 GiB, sized to the trial\ncaveman trial analyze","handlingStrategy":"validation","validationCode":"// Estimate before analyzing: sum captured payload bytes for the trial.\nvar total int64\ns.DB().QueryRow(`SELECT COALESCE(SUM(request_bytes),0) FROM trial_payloads WHERE trial_id = ?`, trialID).Scan(&total)\nconst budget = int64(256 << 20) // mirror CAVE_TRIAL_REPLAY_MAX_BYTES default\nif total > budget {\n    log.Printf(\"trial captures %d bytes > %d budget; raising env or splitting trial\", total, budget)\n}","typeGuard":null,"tryCatchPattern":"plan, err := s.AnalyzeTrial(trialID, ccrPath)\nif err != nil {\n    if strings.Contains(err.Error(), \"payload budget\") {\n    // deterministic resource limit — raise the env cap deliberately or use a smaller trial; do not blind-retry\n        return handleBudgetExceeded(trialID, err)\n    }\n    return err\n}","preventionTips":["Size CAVE_TRIAL_REPLAY_MAX_BYTES to host RAM before long trials.","Start fresh trials per experiment rather than one giant trial.","Monitor SUM(request_bytes) growth during long-running trials."],"tags":["go","resource-limit","trial-store","replay","configuration"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}