plandex-ai/plandex · error

Map file %s exceeds size limit (size %d, limit %d)

Error message

Map file %s exceeds size limit (size %d, limit %d)

What it means

A per-file sanity check on map contexts: each individual MapBodies entry (a single mapped file's body) must be no larger than shared.MaxContextMapSingleInputSize. If any single mapped file body is bigger, the load is rejected with HTTP 400 before any LLM/db work happens.

Source

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

	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
		}

		fileSize := int64(len(context.Body))
		if fileSize > shared.MaxContextBodySize {
			log.Printf("Error: Context %s exceeds size limit (size %.2f MB, limit %d MB)\n", context.Name, float64(fileSize)/1024/1024, int(shared.MaxContextBodySize)/1024/1024)
			http.Error(w, fmt.Sprintf("Context %s exceeds size limit (size %.2f MB, limit %d MB)", context.Name, float64(fileSize)/1024/1024, int(shared.MaxContextBodySize)/1024/1024), http.StatusBadRequest)
			return nil, nil
		}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Exclude the oversized file from the map (ignore patterns) or map it as regular context after trimming
  2. Split or shrink the offending file
  3. Verify client and server agree on MaxContextMapSingleInputSize (version mismatch)

Example fix

// before
mapBodies[path] = readFile(path) // one file over MaxContextMapSingleInputSize
// after
body := readFile(path)
if len(body) > shared.MaxContextMapSingleInputSize {
    continue // skip or truncate oversized file before building map
}
mapBodies[path] = body
Defensive patterns

Strategy: validation

Validate before calling

for path, body := range mapBodies {
    if len(body) > shared.MaxContextMapSingleInputSize {
        return fmt.Errorf("%s exceeds map single-input limit (%d > %d)", path, len(body), shared.MaxContextMapSingleInputSize)
    }
}

Prevention

When it happens

Trigger: Loading a ContextMapType context where at least one body in context.MapBodies has len(body) > shared.MaxContextMapSingleInputSize — typically one huge file inside the mapped tree.

Common situations: A generated file, lockfile, vendored dependency, or minified bundle accidentally included in a mapped directory; binary-ish or concatenated data inflating one file's body.

Related errors


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