plandex-ai/plandex · error

total context body size exceeds limit (size %.2f MB, limit %

Error message

total context body size exceeds limit (size %.2f MB, limit %d MB)

What it means

UpdateContexts accumulates the net body size for the update (new bodies count fully; existing contexts contribute size minus their stored BodySize) and returns this error if totalBodySize exceeds shared.MaxContextBodySize (25MB). The message reports both the observed size and limit in MB.

Source

Thrown at app/server/db/context_helpers_update.go:127

		if size > shared.MaxContextBodySize {
			return nil, fmt.Errorf("context body is too large: %d", size)
		}

		if context, ok := contextsById[id]; ok {
			totalBodySize += size - context.BodySize
		} else {
			totalContextCount++
			totalBodySize += size
		}
	}

	if totalContextCount > shared.MaxContextCount {
		return nil, fmt.Errorf("too many contexts to update (found %d, limit is %d)", totalContextCount, shared.MaxContextCount)
	}

	if totalBodySize > shared.MaxContextBodySize {
		return nil, fmt.Errorf("total context body size exceeds limit (size %.2f MB, limit %d MB)", float64(totalBodySize)/1024/1024, int(shared.MaxContextBodySize)/1024/1024)
	}

	var updatedContexts []*shared.Context

	numFiles := 0
	numUrls := 0
	numTrees := 0
	numMaps := 0

	var mu sync.Mutex
	errCh := make(chan error, len(*req))

	for id, params := range *req {
		go func(id string, params *shared.UpdateContextParams) {
			defer func() {
				if r := recover(); r != nil {
					log.Printf("panic in UpdateContexts: %v\n%s", r, debug.Stack())
					errCh <- fmt.Errorf("panic in UpdateContexts: %v\n%s", r, debug.Stack())

View on GitHub (pinned to e2d772072e)

Solutions

  1. Split the update into multiple calls each staying under the 25MB aggregate budget.
  2. Shrink bodies (truncate, summarize, drop binaries) before updating.
  3. Delete stale contexts in the same flow to offset the net size.
  4. Mirror the net-size calculation client-side to pre-batch requests.

Example fix

// before
UpdateContexts(orgId, planId, branch, allChangedFiles) // 40MB net
// after
for _, batch := range splitByNetSize(allChangedFiles, shared.MaxContextBodySize) {
    UpdateContexts(orgId, planId, branch, batch)
}
Defensive patterns

Strategy: validation

Validate before calling

var net int64
for id, p := range req {
    if c, ok := existingById[id]; ok { net += int64(len(p.Body)) - c.BodySize } else { net += int64(len(p.Body)) }
}
if net > shared.MaxContextBodySize {
    return fmt.Errorf("net body size %d exceeds %d; split the update", net, shared.MaxContextBodySize)
}

Type guard

func netSizeWithinLimit(req map[string]*shared.UpdateContextParams, existingById map[string]*shared.Context) bool {
    var net int64
    for id, p := range req {
        if c, ok := existingById[id]; ok { net += int64(len(p.Body)) - c.BodySize } else { net += int64(len(p.Body)) }
    }
    return net <= shared.MaxContextBodySize
}

Try / catch

_, err := UpdateContexts(orgId, planId, branch, &req)
if err != nil && strings.Contains(err.Error(), "total context body size exceeds limit") {
    // split req by cumulative net size and retry in batches
}

Prevention

When it happens

Trigger: Calling UpdateContexts where the summed (net) body sizes of the request — including deltas against existing contexts — exceed 25MB, even though each individual body is under the per-body limit.

Common situations: Updating many medium-sized files in one call whose combined size crosses 25MB; shrink-wrapping an entire directory into one update; a repeated sync that adds new contexts without removing old ones.

Related errors


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