plandex-ai/plandex · error

Too many map files to load (found %d, limit is %d)

Error message

Too many map files to load (found %d, limit is %d)

What it means

loadContexts is a server-side sanity check on context map loads. When a map-type context arrives with more MapBodies (individual mapped file paths) than shared.MaxContextMapPaths allows, the server refuses the load and returns HTTP 400. The client is expected to enforce this limit before sending, so hitting it means an oversized map was built or sent by an outdated/nonstandard client.

Source

Thrown at app/server/handlers/context_helper.go:55

	branchName := params.branchName
	cachedMapsByPath := params.cachedMapsByPath
	autoLoaded := params.autoLoaded

	log.Printf("[ContextHelper] Starting loadContexts with %d contexts, cachedMapsByPath: %v, autoLoaded: %v", len(*loadReq), cachedMapsByPath != nil, autoLoaded)

	// check file count and size limits
	// this is all a sanity check - we should have already checked these limits in the client
	totalFiles := 0
	mapFilesCount := 0
	for _, context := range *loadReq {
		totalFiles++
		if context.ContextType == shared.ContextMapType {
			mapFilesCount++
			log.Printf("[ContextHelper] Found map file: %s with %d map bodies", context.FilePath, len(context.MapBodies))

			if len(context.MapBodies) > shared.MaxContextMapPaths {
				log.Printf("Error: Too many map files to load (found %d, limit is %d)\n", len(context.MapBodies), shared.MaxContextMapPaths)
				http.Error(w, fmt.Sprintf("Too many map files to load (found %d, limit is %d)", len(context.MapBodies), shared.MaxContextMapPaths), http.StatusBadRequest)
				return nil, nil
			}

			// these are already mapped, so they shouldn't be anywhere close to the input limit, but we'll use it for the sanity check
			for _, body := range context.MapBodies {
				if len(body) > shared.MaxContextMapSingleInputSize {
					log.Printf("Error: Map file %s exceeds size limit (size %d, limit %d)\n", context.FilePath, len(body), shared.MaxContextMapSingleInputSize)
					http.Error(w, fmt.Sprintf("Map file %s exceeds size limit (size %d, limit %d)", context.FilePath, len(body), shared.MaxContextMapSingleInputSize), http.StatusBadRequest)
					return nil, nil
				}
			}
		}

		if totalFiles > shared.MaxContextCount {
			log.Printf("Error: Too many contexts to load (found %d, limit is %d)\n", totalFiles, shared.MaxContextCount)
			http.Error(w, fmt.Sprintf("Too many contexts to load (found %d, limit is %d)", totalFiles, shared.MaxContextCount), http.StatusBadRequest)
			return nil, nil
		}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Reduce the number of files being mapped (map subdirectories individually or add ignores)
  2. Upgrade the Plandex client so it enforces the same MaxContextMapPaths limit before sending
  3. Check the shared.MaxContextMapPaths value in the deployed server version and stay under it

Example fix

// before
contexts = append(contexts, shared.LoadContextParams{ContextType: shared.ContextMapType, MapBodies: allBodies}) // may exceed limit
// after
if len(allBodies) > shared.MaxContextMapPaths {
    allBodies = allBodies[:shared.MaxContextMapPaths] // or split into multiple map contexts
}
contexts = append(contexts, shared.LoadContextParams{ContextType: shared.ContextMapType, MapBodies: allBodies})
Defensive patterns

Strategy: validation

Validate before calling

if len(mapParams.MapBodies) > shared.MaxContextMapPaths {
    return fmt.Errorf("too many map paths: %d (limit %d)", len(mapParams.MapBodies), shared.MaxContextMapPaths)
}

Prevention

When it happens

Trigger: Calling LoadContexts / AutoLoadContext (or the cached-map and missing-file handlers) with a ContextMapType context whose MapBodies slice exceeds shared.MaxContextMapPaths — e.g. mapping a huge directory tree.

Common situations: Mapping a very large monorepo or node_modules-like directory; an old client version with a lower local limit than the server; scripts that add maps programmatically without pre-checking the path count.

Related errors


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