{"record":{"id":"10dfc9d4755392a7","repo":"plandex-ai/plandex","slug":"batch-contains-too-many-files-d-max-d","errorCode":null,"errorMessage":"Batch contains too many files: %d (max %d)","messagePattern":"Batch contains too many files: (.+?) \\(max (.+?)\\)","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"app/server/handlers/file_maps.go","lineNumber":58,"sourceCode":"\ttotalSize := 0\n\tfor path, input := range req.MapInputs {\n\t\t// the client should be truncating inputs to the max size, but we'll check here too\n\t\tif len(input) > shared.MaxContextMapSingleInputSize {\n\t\t\thttp.Error(w, fmt.Sprintf(\"File %s is too large: %d (max %d)\", path, len(input), shared.MaxContextMapSingleInputSize), http.StatusBadRequest)\n\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)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/file_maps.go#L40-L76","documentation":"Beyond global limits, GetFileMapHandler enforces a per-batch file count: shared.ContextMapMaxBatchSize (500). If req.MapInputs has more than 500 entries, the handler returns HTTP 400 with 'Batch contains too many files: %d (max %d)'.","triggerScenarios":"A request whose MapInputs contains 501–3000 entries — under the 3000 MaxContextMapPaths cap but over the 500-per-batch limit.","commonSituations":"Clients that batch by the 3000 path limit instead of the 500 batch limit; batcher logic (like MustLoadContext's ContextMapMaxBatchSize check) skipped; hand-written scripts posting all paths at once.","solutions":["Split MapInputs into batches of at most 500 files","Reuse the CLI batching logic in app/cli/lib/context_shared.go / context_load.go that already chunks on ContextMapMaxBatchSize and ContextMapMaxBatchBytes","Issue sequential batch requests instead of one large request","Verify against the error's reported count that no path duplication is inflating the batch"],"exampleFix":"// before\nsendMapRequest(inputs) // 800 files\n// after\nfor i := 0; i < len(inputs); i += shared.ContextMapMaxBatchSize {\n    end := min(i+shared.ContextMapMaxBatchSize, len(inputs))\n    sendMapRequest(inputs[i:end])\n}","handlingStrategy":"validation","validationCode":"// Client-side batch-count check before sending\nif len(inputs) > shared.ContextMapMaxBatchSize { // 500\n    return fmt.Errorf(\"batch has %d files, max %d\", len(inputs), shared.ContextMapMaxBatchSize)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Batch on the 500-file limit, not the 3000 total-path limit","Reuse the CLI's batching (ContextMapMaxBatchSize/ContextMapMaxBatchBytes) logic","Chunk before each request instead of sending the full set","Add a test asserting no batch exceeds 500 entries"],"tags":["go","http","batching","rate-limit"],"backgroundTag":"request-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"}