{"record":{"id":"181faa7da3110190","repo":"plandex-ai/plandex","slug":"total-context-size-is-too-large-d","errorCode":null,"errorMessage":"total context size is too large: %d","messagePattern":"total context size is too large: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/context_helpers_load.go","lineNumber":121,"sourceCode":"\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\n\texistingContextsByName := make(map[string]bool)\n\tfor _, context := range existingContexts {\n\t\tcomposite := strings.Join([]string{context.Name, string(context.ContextType)}, \"|\")\n\t\texistingContextsByName[composite] = true\n\n\t\tif planConfig.AutoLoadContext && context.ContextType == shared.ContextMapType {\n\t\t\ttotalMapTokens += context.NumTokens\n\t\t\ttotalPlannerTokens -= context.NumTokens\n\t\t}\n\n\t\tif !context.AutoLoaded && context.ContextType != shared.ContextMapType {\n\t\t\ttotalBasicPlannerTokens += context.NumTokens\n\t\t}\n\t}\n\n\tvar filteredReq []*shared.LoadContextParams","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/context_helpers_load.go#L103-L139","documentation":"LoadContexts in app/server/db/context_helpers_load.go returns this error when the combined size of all context bodies being loaded in one request exceeds shared.MaxTotalContextSize (1GB). The server enforces a hard aggregate cap so a single load call cannot saturate memory or the database with an enormous context payload.","triggerScenarios":"Calling LoadContexts (via the anonymous handler that invokes it) with a set of contexts whose summed body sizes exceed 1GB, e.g. loading hundreds of large file or map contexts in a single batch.","commonSituations":"Bulk-loading an entire repository's files as contexts, a client-side bug that sends duplicate bodies in one load call, migrating a project with huge generated assets (build artifacts, datasets) into context storage, or missing client-side chunking after a client version update.","solutions":["Reduce the number and/or size of contexts in the single LoadContexts call and split it into multiple smaller calls.","Remove generated artifacts, binaries, or large data files from the context list before loading.","Check for client bugs that duplicate the same body across multiple context params.","Upgrade/chunk the client to enforce shared.MaxTotalContextSize before sending (client-side pre-check)."],"exampleFix":"// before\nallCtxs := append(ctxs1, ctxs2...) // hundreds of MBs+ in one call\nLoadContexts(ctx, allCtxs)\n// after\nfor _, batch := range chunkContextsUnderTotal(allCtxs, shared.MaxTotalContextSize) {\n    LoadContexts(ctx, batch)\n}","handlingStrategy":"validation","validationCode":"total := int64(0)\nfor _, p := range contexts { total += int64(len(p.Body)) }\nif total > shared.MaxTotalContextSize {\n    return fmt.Errorf(\"payload %d exceeds total limit %d; split the load\", total, shared.MaxTotalContextSize)\n}","typeGuard":"func withinTotalLimit(bodies [][]byte) bool {\n    var total int64\n    for _, b := range bodies { total += int64(len(b)) }\n    return total <= shared.MaxTotalContextSize\n}","tryCatchPattern":null,"preventionTips":["Sum body sizes client-side before every LoadContexts call","Chunk large loads into multiple requests under 1GB each","Exclude generated artifacts and datasets from context loading","Keep client limit constants in sync with app/shared/context.go"],"tags":["go","context-size","limit-exceeded","payload"],"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"}