{"record":{"id":"7bb928973ca3717d","repo":"plandex-ai/plandex","slug":"batch-size-too-large-d-bytes-max-d-bytes","errorCode":null,"errorMessage":"Batch size too large: %d bytes (max %d bytes)","messagePattern":"Batch size too large: (.+?) bytes \\(max (.+?) bytes\\)","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"app/server/handlers/file_maps.go","lineNumber":63,"sourceCode":"\t\t\treturn\n\t\t}\n\t\ttotalSize += len(input)\n\t}\n\n\t// On the client, once the total size limit is exceeded, we send empty file maps for remaining files\n\tif totalSize > shared.MaxContextMapTotalInputSize+10000 {\n\t\thttp.Error(w, fmt.Sprintf(\"Max map size exceeded: %d (max %d)\", totalSize, shared.MaxContextMapTotalInputSize), http.StatusBadRequest)\n\t\treturn\n\t}\n\n\t// Check batch size limits\n\tif len(req.MapInputs) > shared.ContextMapMaxBatchSize {\n\t\thttp.Error(w, fmt.Sprintf(\"Batch contains too many files: %d (max %d)\", len(req.MapInputs), shared.ContextMapMaxBatchSize), http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tif int64(totalSize) > shared.ContextMapMaxBatchBytes {\n\t\thttp.Error(w, fmt.Sprintf(\"Batch size too large: %d bytes (max %d bytes)\", totalSize, shared.ContextMapMaxBatchBytes), http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tresults := make(chan shared.FileMapBodies, 1)\n\n\terr := queueProjectMapJob(projectMapJob{\n\t\tinputs:  req.MapInputs,\n\t\tctx:     r.Context(),\n\t\tresults: results,\n\t})\n\tif err != nil {\n\t\tlog.Println(\"GetFileMapHandler: map queue is full\")\n\t\thttp.Error(w, \"Too many project map jobs, please try again later\", http.StatusTooManyRequests)\n\t\treturn\n\t}\n\n\tselect {\n\tcase <-r.Context().Done():","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/file_maps.go#L45-L81","documentation":"GetFileMapHandler also caps per-batch bytes at shared.ContextMapMaxBatchBytes (10MB). If the summed content size of the batch exceeds 10MB it returns HTTP 400 with 'Batch size too large: %d bytes (max %d bytes)'. This is independent of the global 250MB total limit — each individual job must stay under 10MB.","triggerScenarios":"A single request whose MapInputs total content is > 10*1024*1024 bytes while staying within the 500-file and 250MB limits (e.g. 100 files at ~150KB each).","commonSituations":"Batches of near-max-size (500KB) files: 21 such files already exceed 10MB; batcher that only counts files, not bytes; upstream provider inputs that grew after a client version change.","solutions":["Split the batch by cumulative byte size, chunking when totalSize would exceed 10MB (see the CLI's MustLoadContext batching at app/cli/lib/context_load.go:492)","Trim or truncate large files before adding them to a batch","Track TotalSize() per batch alongside NumFiles()","Send more, smaller requests — the limit is per request, not global"],"exampleFix":"// before\nbatch := files[:500] // 500 x 400KB = 200MB\nsend(batch)\n// after\nvar batch []File; var sz int\nfor _, f := range files {\n    if len(batch) > 0 && (len(batch)+1 > shared.ContextMapMaxBatchSize || sz+len(f.Data) > shared.ContextMapMaxBatchBytes) {\n        send(batch); batch, sz = nil, 0\n    }\n    batch = append(batch, f); sz += len(f.Data)\n}\nsend(batch)","handlingStrategy":"validation","validationCode":"// Client-side byte-size batching before sending\nvar batch []Entry; var sz int\nfor _, e := range entries {\n    if len(batch) > 0 && (len(batch)+1 > shared.ContextMapMaxBatchSize || sz+len(e.Data) > shared.ContextMapMaxBatchBytes) {\n        send(batch); batch, sz = nil, 0\n    }\n    batch = append(batch, e); sz += len(e.Data)\n}\nsend(batch)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Track bytes per batch, not just file count","Chunk at 10MB with a safety margin (e.g. 8MB) for JSON overhead","Reuse the batching condition from app/cli/lib/context_load.go:492","Watch for batches of near-500KB files: ~21 of them hit 10MB"],"tags":["go","http","batching","payload-size"],"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-14T00:17:10.932Z"}