{"record":{"id":"cba9f67287a0f954","repo":"plandex-ai/plandex","slug":"too-many-contexts-to-load-found-d-limit-is-d","errorCode":null,"errorMessage":"Too many contexts to load (found %d, limit is %d)","messagePattern":"Too many contexts to load \\(found (.+?), limit is (.+?)\\)","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"app/server/handlers/context_helper.go","lineNumber":71,"sourceCode":"\t\t\tif len(context.MapBodies) > shared.MaxContextMapPaths {\n\t\t\t\tlog.Printf(\"Error: Too many map files to load (found %d, limit is %d)\\n\", len(context.MapBodies), shared.MaxContextMapPaths)\n\t\t\t\thttp.Error(w, fmt.Sprintf(\"Too many map files to load (found %d, limit is %d)\", len(context.MapBodies), shared.MaxContextMapPaths), http.StatusBadRequest)\n\t\t\t\treturn nil, nil\n\t\t\t}\n\n\t\t\t// these are already mapped, so they shouldn't be anywhere close to the input limit, but we'll use it for the sanity check\n\t\t\tfor _, body := range context.MapBodies {\n\t\t\t\tif len(body) > shared.MaxContextMapSingleInputSize {\n\t\t\t\t\tlog.Printf(\"Error: Map file %s exceeds size limit (size %d, limit %d)\\n\", context.FilePath, len(body), shared.MaxContextMapSingleInputSize)\n\t\t\t\t\thttp.Error(w, fmt.Sprintf(\"Map file %s exceeds size limit (size %d, limit %d)\", context.FilePath, len(body), shared.MaxContextMapSingleInputSize), http.StatusBadRequest)\n\t\t\t\t\treturn nil, nil\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif totalFiles > shared.MaxContextCount {\n\t\t\tlog.Printf(\"Error: Too many contexts to load (found %d, limit is %d)\\n\", totalFiles, shared.MaxContextCount)\n\t\t\thttp.Error(w, fmt.Sprintf(\"Too many contexts to load (found %d, limit is %d)\", totalFiles, shared.MaxContextCount), http.StatusBadRequest)\n\t\t\treturn nil, nil\n\t\t}\n\n\t\tfileSize := int64(len(context.Body))\n\t\tif fileSize > shared.MaxContextBodySize {\n\t\t\tlog.Printf(\"Error: Context %s exceeds size limit (size %.2f MB, limit %d MB)\\n\", context.Name, float64(fileSize)/1024/1024, int(shared.MaxContextBodySize)/1024/1024)\n\t\t\thttp.Error(w, fmt.Sprintf(\"Context %s exceeds size limit (size %.2f MB, limit %d MB)\", context.Name, float64(fileSize)/1024/1024, int(shared.MaxContextBodySize)/1024/1024), http.StatusBadRequest)\n\t\t\treturn nil, nil\n\t\t}\n\n\t}\n\n\tif mapFilesCount > 0 {\n\t\tlog.Printf(\"[ContextHelper] Processing %d map files out of %d total contexts\", mapFilesCount, totalFiles)\n\t}\n\n\tvar err error\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/context_helper.go#L53-L89","documentation":"loadContexts caps the number of contexts in a single load request at shared.MaxContextCount. If the request would push the total above that cap, the server returns HTTP 400 and loads nothing. This protects the plan's context budget and downstream LLM calls.","triggerScenarios":"A LoadContexts request whose context list length exceeds shared.MaxContextCount (checked incrementally as totalFiles during the validation loop).","commonSituations":"Bulk-loading many files at once via the CLI or API; recursive directory adds; automation scripts appending contexts in a loop without batching.","solutions":["Split the load into multiple smaller requests","Remove or unload unneeded contexts first to stay under the cap","Check shared.MaxContextCount for the server version and batch accordingly"],"exampleFix":"// before\nclient.LoadContexts(ctx, planId, branch, allContexts) // allContexts > MaxContextCount\n// after\nfor batch := range chunk(allContexts, shared.MaxContextCount) {\n    client.LoadContexts(ctx, planId, branch, batch)\n}","handlingStrategy":"validation","validationCode":"if len(loadReq) > shared.MaxContextCount {\n    return fmt.Errorf(\"context count %d exceeds limit %d; batch the request\", len(loadReq), shared.MaxContextCount)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Chunk bulk loads into batches under MaxContextCount","Unload stale contexts before adding many new ones","Check MaxContextCount on the target server version"],"tags":["http-400","limit-exceeded","context-count","plandex"],"backgroundTag":"context-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"}