wavetermdev/waveterm · error

file %s exceeds maximum size of %s for %s files

Error message

file %s exceeds maximum size of %s for %s files

What it means

`wsh ai` enforces per-type size limits via getMaxFileSize: 5MB for PDFs, 7MB for images, 200KB for everything else (plain text and directory listings). Files are base64-encoded into one RPC payload, so oversized attachments are rejected before the RPC is sent. fileName is the absolute path or "stdin"; sizeStr names the limit.

Source

Thrown at cmd/wsh/cmd/wshcmd-ai.go:152

				fileName = absPath
				mimeType = detectMimeType(data)
			}
		}

		isPDF := mimeType == "application/pdf"
		isImage := strings.HasPrefix(mimeType, "image/")
		isDirectory := mimeType == "directory"

		if !isPDF && !isImage && !isDirectory {
			mimeType = "text/plain"
			if utilfn.ContainsBinaryData(data) {
				return fmt.Errorf("file %s contains binary data and cannot be uploaded as text", fileName)
			}
		}

		maxSize, sizeStr := getMaxFileSize(mimeType)
		if len(data) > maxSize {
			return fmt.Errorf("file %s exceeds maximum size of %s for %s files", fileName, sizeStr, mimeType)
		}

		allFiles = append(allFiles, wshrpc.AIAttachedFile{
			Name:   fileName,
			Type:   mimeType,
			Size:   len(data),
			Data64: base64.StdEncoding.EncodeToString(data),
		})
	}

	tabId := os.Getenv("WAVETERM_TABID")
	if tabId == "" {
		return fmt.Errorf("WAVETERM_TABID environment variable not set")
	}

	route := wshutil.MakeTabRouteId(tabId)

	if aiNewBlockFlag {

View on GitHub (pinned to a4447c1563)

Solutions

  1. Trim the file to the relevant portion: `tail -n 500 build.log > recent.log` (or head/grep) and attach the smaller file.
  2. Compress text with relevance filtering: `grep -i error build.log | wsh ai -` or pipe through `| head -c 200000 | wsh ai -`.
  3. For images, downscale/re-encode below 7MB (e.g. `convert img.png -resize 50% img.png`) or use JPEG.
  4. For PDFs, split or compress below 5MB (e.g. `qpdf --split-pages` or ghostscript compression).
  5. For directory listings exceeding 200KB of JSON, attach a narrower subdirectory or specific files instead.

Example fix

// before
$ wsh ai build.log
// error: file /path/build.log exceeds maximum size of 200KB for text/plain files
// after
$ grep -iE 'error|fail' build.log | wsh ai - --message "why did the build fail?"
Defensive patterns

Strategy: validation

Validate before calling

limit() { case "$1" in *.pdf) echo 5242880 ;; *.png|*.jpg|*.jpeg|*.gif|*.webp) echo 7340032 ;; *) echo 204800 ;; esac; }
for f in "$@"; do
  [ "$f" = "-" ] && continue
  max=$(limit "$f")
  size=$(stat -c%s "$f")
  if [ "$size" -gt "$max" ]; then
    echo "too large: $f ($size > $max bytes); trim or compress first" >&2
    exit 1
  fi
done

Try / catch

if err := runAI(args); err != nil {
    if strings.Contains(err.Error(), "exceeds maximum size") {
        return fmt.Errorf("trim/compress the file (tail -n 500, image resize, pdf split) below the per-type cap")
    }
    return err
}

Prevention

When it happens

Trigger: Attaching any file whose byte length exceeds the applicable cap: a text/log/source file over 200KB (e.g. big logs, minified JS, large JSON), a PDF over 5MB, an image over 7MB, or a stdin stream over its type's cap. Note directories always use the 200KB cap for their JSON listing (max 500 entries).

Common situations: `wsh ai build.log` from a long CI run (often >200KB); attaching high-resolution screenshots >7MB; large generated/minified source files; big dataset excerpts.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/06a5f66711f529af. Report an issue: GitHub.