plandex-ai/plandex · error

too many contexts to update (found %d, limit is %d)

Error message

too many contexts to update (found %d, limit is %d)

What it means

Server-side limit check in UpdateContexts: after summing new/updated context bodies, totalContextCount exceeds shared.MaxContextCount. Guards the plan's context count per request; a client exceeding it is rejected before any DB writes.

Source

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

	}

	for id, params := range *req {
		size := int64(len(params.Body))

		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) {

View on GitHub (pinned to e2d772072e)

Solutions

  1. Split the update into batches of <=1000 new contexts per call.
  2. Reuse existing context IDs (update instead of create) so entries count as size deltas, not new contexts.
  3. Filter the request to the most relevant files before updating.
  4. Check for client bugs that generate fresh IDs for unchanged contexts.

Example fix

// before
UpdateContexts(orgId, planId, branch, reqForAll5000Files)
// after
for _, batch := range chunkMap(req, shared.MaxContextCount) {
    UpdateContexts(orgId, planId, branch, batch)
}
Defensive patterns

Strategy: validation

Validate before calling

newCount := 0
for id := range req {
    if _, ok := existingById[id]; !ok { newCount++ }
}
if newCount > shared.MaxContextCount {
    return fmt.Errorf("%d new contexts exceeds limit %d; batch the update", newCount, shared.MaxContextCount)
}

Type guard

func withinContextCountLimit(req map[string]*shared.UpdateContextParams, existingById map[string]*shared.Context) bool {
    n := 0
    for id := range req { if _, ok := existingById[id]; !ok { n++ } }
    return n <= shared.MaxContextCount
}

Try / catch

_, err := UpdateContexts(orgId, planId, branch, &req)
if err != nil && strings.Contains(err.Error(), "too many contexts to update") {
    // chunk req into batches of <= MaxContextCount and retry
}

Prevention

When it happens

Trigger: Calling UpdateContexts with a request map containing more than 1000 context IDs that are NOT already in contextsById (i.e., more than 1000 brand-new contexts being created in one update call).

Common situations: Bulk-adding an entire large repo's files as new contexts in a single update; a sync loop re-adding every file each run because IDs don't match existing contexts; batch tooling that ignores the 1000-context limit.

Related errors


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