{"record":{"id":"06a5f66711f529af","repo":"wavetermdev/waveterm","slug":"file-s-exceeds-maximum-size-of-s-for-s-files","errorCode":null,"errorMessage":"file %s exceeds maximum size of %s for %s files","messagePattern":"file (.+?) exceeds maximum size of (.+?) for (.+?) files","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-ai.go","lineNumber":152,"sourceCode":"\t\t\t\tfileName = absPath\n\t\t\t\tmimeType = detectMimeType(data)\n\t\t\t}\n\t\t}\n\n\t\tisPDF := mimeType == \"application/pdf\"\n\t\tisImage := strings.HasPrefix(mimeType, \"image/\")\n\t\tisDirectory := mimeType == \"directory\"\n\n\t\tif !isPDF && !isImage && !isDirectory {\n\t\t\tmimeType = \"text/plain\"\n\t\t\tif utilfn.ContainsBinaryData(data) {\n\t\t\t\treturn fmt.Errorf(\"file %s contains binary data and cannot be uploaded as text\", fileName)\n\t\t\t}\n\t\t}\n\n\t\tmaxSize, sizeStr := getMaxFileSize(mimeType)\n\t\tif len(data) > maxSize {\n\t\t\treturn fmt.Errorf(\"file %s exceeds maximum size of %s for %s files\", fileName, sizeStr, mimeType)\n\t\t}\n\n\t\tallFiles = append(allFiles, wshrpc.AIAttachedFile{\n\t\t\tName:   fileName,\n\t\t\tType:   mimeType,\n\t\t\tSize:   len(data),\n\t\t\tData64: base64.StdEncoding.EncodeToString(data),\n\t\t})\n\t}\n\n\ttabId := os.Getenv(\"WAVETERM_TABID\")\n\tif tabId == \"\" {\n\t\treturn fmt.Errorf(\"WAVETERM_TABID environment variable not set\")\n\t}\n\n\troute := wshutil.MakeTabRouteId(tabId)\n\n\tif aiNewBlockFlag {","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-ai.go#L134-L170","documentation":"`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.","triggerScenarios":"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).","commonSituations":"`wsh ai build.log` from a long CI run (often >200KB); attaching high-resolution screenshots >7MB; large generated/minified source files; big dataset excerpts.","solutions":["Trim the file to the relevant portion: `tail -n 500 build.log > recent.log` (or head/grep) and attach the smaller file.","Compress text with relevance filtering: `grep -i error build.log | wsh ai -` or pipe through `| head -c 200000 | wsh ai -`.","For images, downscale/re-encode below 7MB (e.g. `convert img.png -resize 50% img.png`) or use JPEG.","For PDFs, split or compress below 5MB (e.g. `qpdf --split-pages` or ghostscript compression).","For directory listings exceeding 200KB of JSON, attach a narrower subdirectory or specific files instead."],"exampleFix":"// before\n$ wsh ai build.log\n// error: file /path/build.log exceeds maximum size of 200KB for text/plain files\n// after\n$ grep -iE 'error|fail' build.log | wsh ai - --message \"why did the build fail?\"","handlingStrategy":"validation","validationCode":"limit() { case \"$1\" in *.pdf) echo 5242880 ;; *.png|*.jpg|*.jpeg|*.gif|*.webp) echo 7340032 ;; *) echo 204800 ;; esac; }\nfor f in \"$@\"; do\n  [ \"$f\" = \"-\" ] && continue\n  max=$(limit \"$f\")\n  size=$(stat -c%s \"$f\")\n  if [ \"$size\" -gt \"$max\" ]; then\n    echo \"too large: $f ($size > $max bytes); trim or compress first\" >&2\n    exit 1\n  fi\ndone","typeGuard":null,"tryCatchPattern":"if err := runAI(args); err != nil {\n    if strings.Contains(err.Error(), \"exceeds maximum size\") {\n        return fmt.Errorf(\"trim/compress the file (tail -n 500, image resize, pdf split) below the per-type cap\")\n    }\n    return err\n}","preventionTips":["Remember the caps: 200KB text, 5MB PDF, 7MB image — check with `stat -c%s` (or `ls -l`) before attaching.","Attach filtered excerpts of logs (grep/tail) rather than full multi-MB logs.","Pre-resize images and split/compress large PDFs as a pipeline step.","Account for base64 overhead by keeping inputs well under the limits, and remember directory listings share the 200KB cap."],"tags":["file-size","limit","validation","wsh"],"backgroundTag":"file-exceeds-size-limit","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}