{"record":{"id":"aa4fbca65c591fea","repo":"plandex-ai/plandex","slug":"too-many-contexts-d","errorCode":null,"errorMessage":"too many contexts: %d","messagePattern":"too many contexts: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/context_helpers_load.go","lineNumber":105,"sourceCode":"\tplanConfig, err := GetPlanConfig(planId)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"error getting plan config: %v\", err)\n\t}\n\n\tplannerMaxTokens := settings.GetPlannerEffectiveMaxTokens()\n\tcontextLoaderMaxTokens := settings.GetArchitectEffectiveMaxTokens()\n\n\tmapContextsByFilePath := make(map[string]Context)\n\n\texistingContexts, err := GetPlanContexts(orgId, planId, false, false)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"error getting existing contexts: %v\", err)\n\t}\n\n\t// check overall context limits - these should be getting enforced by the client, so just error out if exceeded\n\tnumExistingContexts := len(existingContexts)\n\tif numExistingContexts+len(*req) > shared.MaxContextCount {\n\t\treturn nil, nil, fmt.Errorf(\"too many contexts: %d\", numExistingContexts+len(*req))\n\t}\n\n\tvar totalContextSize int64\n\tfor _, context := range existingContexts {\n\t\ttotalContextSize += context.BodySize\n\t}\n\tfor _, context := range *req {\n\t\tsize := int64(len(context.Body))\n\t\ttotalContextSize += size\n\t\tif size > shared.MaxContextBodySize {\n\t\t\treturn nil, nil, fmt.Errorf(\"context body is too large: %d\", size)\n\t\t}\n\t}\n\n\tif totalContextSize > shared.MaxTotalContextSize {\n\t\treturn nil, nil, fmt.Errorf(\"total context size is too large: %d\", totalContextSize)\n\t}\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/context_helpers_load.go#L87-L123","documentation":"LoadContexts enforces the server-side cap shared.MaxContextCount on how many contexts a plan branch may hold. It sums existing contexts plus the incoming request batch and errors if the total would exceed the limit. The client normally enforces this first, so hitting it server-side means the client-side guard was bypassed or raced with concurrent loads.","triggerScenarios":"A LoadContexts request where len(existingContexts) + len(req) > shared.MaxContextCount — e.g. loading many files at once onto a branch that already holds close to the maximum number of contexts.","commonSituations":"Bulk-loading a large directory of files; scripts/integrations calling the API directly without the CLI's limit checks; concurrent sessions adding contexts to the same plan branch.","solutions":["Remove unneeded contexts from the plan branch (plandex rm) before adding more.","Split the load into smaller batches and clear contexts between batches.","Start a new branch or plan for the additional files.","If calling the API directly, check the current context count against MaxContextCount before sending."],"exampleFix":"// before: one giant load\nreq := make([]shared.LoadContextParams, 300) // exceeds MaxContextCount with existing\nres, err := LoadContexts(ctx, params)\n// after: batch and trim\nconst batchSize = shared.MaxContextCount - len(existingContexts)\nfor i := 0; i < len(allParams); i += batchSize {\n\tbatch := allParams[i : i+batchSize]\n\tif _, err := LoadContexts(ctx, LoadContextsParams{Req: &batch, ...}); err != nil {\n\t\treturn err\n\t}\n}","handlingStrategy":"validation","validationCode":"existing, _ := GetPlanContexts(orgId, planId, false, false)\nif len(existing)+len(reqParams) > shared.MaxContextCount {\n\treturn fmt.Errorf(\"would exceed MaxContextCount (%d > %d)\", len(existing)+len(reqParams), shared.MaxContextCount)\n}","typeGuard":null,"tryCatchPattern":"resp, err := client.LoadContexts(req)\nif err != nil {\n\tif strings.Contains(err.Error(), \"too many contexts\") {\n\t\t// trim contexts and retry with a smaller batch\n\t\treturn retryWithFewerContexts()\n\t}\n\treturn err\n}","preventionTips":["Check existing context count before bulk loads","Split large file sets into batches under MaxContextCount","Remove stale contexts (plandex rm) before adding new ones","Enforce the limit client-side in any direct API integrations"],"tags":["limits","server","contexts","validation"],"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-14T05:17:10.506Z"}