{"record":{"id":"a00bdc312a4804b4","repo":"plandex-ai/plandex","slug":"total-context-body-size-exceeds-limit-size-2f-m","errorCode":null,"errorMessage":"total context body size exceeds limit (size %.2f MB, limit %d MB)","messagePattern":"total context body size exceeds limit \\(size %\\.2f MB, limit (.+?) MB\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/context_helpers_update.go","lineNumber":127,"sourceCode":"\n\t\tif size > shared.MaxContextBodySize {\n\t\t\treturn nil, fmt.Errorf(\"context body is too large: %d\", size)\n\t\t}\n\n\t\tif context, ok := contextsById[id]; ok {\n\t\t\ttotalBodySize += size - context.BodySize\n\t\t} else {\n\t\t\ttotalContextCount++\n\t\t\ttotalBodySize += size\n\t\t}\n\t}\n\n\tif totalContextCount > shared.MaxContextCount {\n\t\treturn nil, fmt.Errorf(\"too many contexts to update (found %d, limit is %d)\", totalContextCount, shared.MaxContextCount)\n\t}\n\n\tif totalBodySize > shared.MaxContextBodySize {\n\t\treturn nil, fmt.Errorf(\"total context body size exceeds limit (size %.2f MB, limit %d MB)\", float64(totalBodySize)/1024/1024, int(shared.MaxContextBodySize)/1024/1024)\n\t}\n\n\tvar updatedContexts []*shared.Context\n\n\tnumFiles := 0\n\tnumUrls := 0\n\tnumTrees := 0\n\tnumMaps := 0\n\n\tvar mu sync.Mutex\n\terrCh := make(chan error, len(*req))\n\n\tfor id, params := range *req {\n\t\tgo func(id string, params *shared.UpdateContextParams) {\n\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\tlog.Printf(\"panic in UpdateContexts: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\terrCh <- fmt.Errorf(\"panic in UpdateContexts: %v\\n%s\", r, debug.Stack())","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/context_helpers_update.go#L109-L145","documentation":"UpdateContexts accumulates the net body size for the update (new bodies count fully; existing contexts contribute size minus their stored BodySize) and returns this error if totalBodySize exceeds shared.MaxContextBodySize (25MB). The message reports both the observed size and limit in MB.","triggerScenarios":"Calling UpdateContexts where the summed (net) body sizes of the request — including deltas against existing contexts — exceed 25MB, even though each individual body is under the per-body limit.","commonSituations":"Updating many medium-sized files in one call whose combined size crosses 25MB; shrink-wrapping an entire directory into one update; a repeated sync that adds new contexts without removing old ones.","solutions":["Split the update into multiple calls each staying under the 25MB aggregate budget.","Shrink bodies (truncate, summarize, drop binaries) before updating.","Delete stale contexts in the same flow to offset the net size.","Mirror the net-size calculation client-side to pre-batch requests."],"exampleFix":"// before\nUpdateContexts(orgId, planId, branch, allChangedFiles) // 40MB net\n// after\nfor _, batch := range splitByNetSize(allChangedFiles, shared.MaxContextBodySize) {\n    UpdateContexts(orgId, planId, branch, batch)\n}","handlingStrategy":"validation","validationCode":"var net int64\nfor id, p := range req {\n    if c, ok := existingById[id]; ok { net += int64(len(p.Body)) - c.BodySize } else { net += int64(len(p.Body)) }\n}\nif net > shared.MaxContextBodySize {\n    return fmt.Errorf(\"net body size %d exceeds %d; split the update\", net, shared.MaxContextBodySize)\n}","typeGuard":"func netSizeWithinLimit(req map[string]*shared.UpdateContextParams, existingById map[string]*shared.Context) bool {\n    var net int64\n    for id, p := range req {\n        if c, ok := existingById[id]; ok { net += int64(len(p.Body)) - c.BodySize } else { net += int64(len(p.Body)) }\n    }\n    return net <= shared.MaxContextBodySize\n}","tryCatchPattern":"_, err := UpdateContexts(orgId, planId, branch, &req)\nif err != nil && strings.Contains(err.Error(), \"total context body size exceeds limit\") {\n    // split req by cumulative net size and retry in batches\n}","preventionTips":["Compute net size deltas (including existing BodySize offsets) before updating","Split large syncs into sub-25MB batches","Delete stale contexts in the same flow to offset net size"],"tags":["go","body-size","aggregate-limit","update"],"backgroundTag":"payload-size-limit-exceeded","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}