plandex-ai/plandex · error

Batch size too large: %d bytes (max %d bytes)

Error message

Batch size too large: %d bytes (max %d bytes)

What it means

GetFileMapHandler also caps per-batch bytes at shared.ContextMapMaxBatchBytes (10MB). If the summed content size of the batch exceeds 10MB it returns HTTP 400 with 'Batch size too large: %d bytes (max %d bytes)'. This is independent of the global 250MB total limit — each individual job must stay under 10MB.

Source

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

			return
		}
		totalSize += len(input)
	}

	// On the client, once the total size limit is exceeded, we send empty file maps for remaining files
	if totalSize > shared.MaxContextMapTotalInputSize+10000 {
		http.Error(w, fmt.Sprintf("Max map size exceeded: %d (max %d)", totalSize, shared.MaxContextMapTotalInputSize), http.StatusBadRequest)
		return
	}

	// Check batch size limits
	if len(req.MapInputs) > shared.ContextMapMaxBatchSize {
		http.Error(w, fmt.Sprintf("Batch contains too many files: %d (max %d)", len(req.MapInputs), shared.ContextMapMaxBatchSize), http.StatusBadRequest)
		return
	}

	if int64(totalSize) > shared.ContextMapMaxBatchBytes {
		http.Error(w, fmt.Sprintf("Batch size too large: %d bytes (max %d bytes)", totalSize, shared.ContextMapMaxBatchBytes), http.StatusBadRequest)
		return
	}

	results := make(chan shared.FileMapBodies, 1)

	err := queueProjectMapJob(projectMapJob{
		inputs:  req.MapInputs,
		ctx:     r.Context(),
		results: results,
	})
	if err != nil {
		log.Println("GetFileMapHandler: map queue is full")
		http.Error(w, "Too many project map jobs, please try again later", http.StatusTooManyRequests)
		return
	}

	select {
	case <-r.Context().Done():

View on GitHub (pinned to e2d772072e)

Solutions

  1. Split the batch by cumulative byte size, chunking when totalSize would exceed 10MB (see the CLI's MustLoadContext batching at app/cli/lib/context_load.go:492)
  2. Trim or truncate large files before adding them to a batch
  3. Track TotalSize() per batch alongside NumFiles()
  4. Send more, smaller requests — the limit is per request, not global

Example fix

// before
batch := files[:500] // 500 x 400KB = 200MB
send(batch)
// after
var batch []File; var sz int
for _, f := range files {
    if len(batch) > 0 && (len(batch)+1 > shared.ContextMapMaxBatchSize || sz+len(f.Data) > shared.ContextMapMaxBatchBytes) {
        send(batch); batch, sz = nil, 0
    }
    batch = append(batch, f); sz += len(f.Data)
}
send(batch)
Defensive patterns

Strategy: validation

Validate before calling

// Client-side byte-size batching before sending
var batch []Entry; var sz int
for _, e := range entries {
    if len(batch) > 0 && (len(batch)+1 > shared.ContextMapMaxBatchSize || sz+len(e.Data) > shared.ContextMapMaxBatchBytes) {
        send(batch); batch, sz = nil, 0
    }
    batch = append(batch, e); sz += len(e.Data)
}
send(batch)

Prevention

When it happens

Trigger: A single request whose MapInputs total content is > 10*1024*1024 bytes while staying within the 500-file and 250MB limits (e.g. 100 files at ~150KB each).

Common situations: Batches of near-max-size (500KB) files: 21 such files already exceed 10MB; batcher that only counts files, not bytes; upstream provider inputs that grew after a client version change.

Related errors


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