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.LoadContextParams

View on GitHub (pinned to e2d772072e)

Solutions

  1. Reduce the number and/or size of contexts in the single LoadContexts call and split it into multiple smaller calls.
  2. Remove generated artifacts, binaries, or large data files from the context list before loading.
  3. Check for client bugs that duplicate the same body across multiple context params.
  4. 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

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


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/181faa7da3110190. Report an issue: GitHub.