plandex-ai/plandex · error
total context size is too large: %d
Error message
total context size is too large: %d
What it means
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.
Source
Thrown at app/server/db/context_helpers_load.go:121
numExistingContexts := len(existingContexts)
if numExistingContexts+len(*req) > shared.MaxContextCount {
return nil, nil, fmt.Errorf("too many contexts: %d", numExistingContexts+len(*req))
}
var totalContextSize int64
for _, context := range existingContexts {
totalContextSize += context.BodySize
}
for _, context := range *req {
size := int64(len(context.Body))
totalContextSize += size
if size > shared.MaxContextBodySize {
return nil, nil, fmt.Errorf("context body is too large: %d", size)
}
}
if totalContextSize > shared.MaxTotalContextSize {
return nil, nil, fmt.Errorf("total context size is too large: %d", totalContextSize)
}
existingContextsByName := make(map[string]bool)
for _, context := range existingContexts {
composite := strings.Join([]string{context.Name, string(context.ContextType)}, "|")
existingContextsByName[composite] = true
if planConfig.AutoLoadContext && context.ContextType == shared.ContextMapType {
totalMapTokens += context.NumTokens
totalPlannerTokens -= context.NumTokens
}
if !context.AutoLoaded && context.ContextType != shared.ContextMapType {
totalBasicPlannerTokens += context.NumTokens
}
}
var filteredReq []*shared.LoadContextParamsView on GitHub (pinned to e2d772072e)
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).
Example fix
// before
allCtxs := append(ctxs1, ctxs2...) // hundreds of MBs+ in one call
LoadContexts(ctx, allCtxs)
// after
for _, batch := range chunkContextsUnderTotal(allCtxs, shared.MaxTotalContextSize) {
LoadContexts(ctx, batch)
} Defensive patterns
Strategy: validation
Validate before calling
total := int64(0)
for _, p := range contexts { total += int64(len(p.Body)) }
if total > shared.MaxTotalContextSize {
return fmt.Errorf("payload %d exceeds total limit %d; split the load", total, shared.MaxTotalContextSize)
} Type guard
func withinTotalLimit(bodies [][]byte) bool {
var total int64
for _, b := range bodies { total += int64(len(b)) }
return total <= shared.MaxTotalContextSize
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- map has too many paths: %d
- map input %s is too large: %d
- map is too large: %d
- too many contexts to update (found %d, limit is %d)
- connection to plan stream timed out due to missing heartbeat
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/181faa7da3110190.
Report an issue: GitHub.