{"record":{"id":"5796abbd2d497015","repo":"can1357/oh-my-pi","slug":"image-file-too-large-sizestr-exceeds-maxstr","errorCode":null,"errorMessage":"Image file too large: ${sizeStr} exceeds ${maxStr} limit.","messagePattern":"Image file too large: (.+?) exceeds (.+?) limit\\.","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/read.ts","lineNumber":848,"sourceCode":"\t\t\t\t`- Bytes: ${fileSize} (${formatBytes(fileSize)})`,\n\t\t\t\timageMetadata?.width !== undefined && imageMetadata.height !== undefined\n\t\t\t\t\t? `- Dimensions: ${imageMetadata.width}x${imageMetadata.height}`\n\t\t\t\t\t: \"- Dimensions: unknown\",\n\t\t\t\timageMetadata?.channels !== undefined ? `- Channels: ${imageMetadata.channels}` : \"- Channels: unknown\",\n\t\t\t\timageMetadata?.hasAlpha === true\n\t\t\t\t\t? \"- Alpha: yes\"\n\t\t\t\t\t: imageMetadata?.hasAlpha === false\n\t\t\t\t\t\t? \"- Alpha: no\"\n\t\t\t\t\t\t: \"- Alpha: unknown\",\n\t\t\t\t\"\",\n\t\t\t\t`If you want to analyze the image, call inspect_image with path=\"${inspectImagePath}\" and a question describing what to inspect and the desired output format.`,\n\t\t\t];\n\t\t\treturn { content: [{ type: \"text\", text: metadataLines.join(\"\\n\") }], details: {}, sourcePath: absolutePath };\n\t\t}\n\t\tif (fileSize > MAX_IMAGE_SIZE) {\n\t\t\tconst sizeStr = formatBytes(fileSize);\n\t\t\tconst maxStr = formatBytes(MAX_IMAGE_SIZE);\n\t\t\tthrow new ToolError(`Image file too large: ${sizeStr} exceeds ${maxStr} limit.`);\n\t\t}\n\t\ttry {\n\t\t\tconst imageLoadOptions = {\n\t\t\t\tpath: readPath,\n\t\t\t\tcwd: this.session.cwd,\n\t\t\t\tautoResize: this.#autoResizeImages,\n\t\t\t\tmaxBytes: MAX_IMAGE_SIZE,\n\t\t\t\tresolvedPath: absolutePath,\n\t\t\t\texcludeWebP: webpExclusionForModel(this.session.getActiveModel?.()),\n\t\t\t};\n\t\t\tconst imageInput =\n\t\t\t\timageKind === \"svg\"\n\t\t\t\t\t? await loadSvgImageInput(imageLoadOptions)\n\t\t\t\t\t: await loadImageInput({ ...imageLoadOptions, detectedMimeType: mimeType });\n\t\t\tif (!imageInput) {\n\t\t\t\tthrow new ToolError(\n\t\t\t\t\timageKind === \"svg\"\n\t\t\t\t\t\t? \"The ':img' selector only supports .svg and .svgz files.\"","sourceCodeStart":830,"sourceCodeEnd":866,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/read.ts#L830-L866","documentation":"The Read tool caps image payloads at MAX_IMAGE_SIZE before decoding/attaching them. When the file's byte size exceeds the cap, it throws a ToolError naming the actual size and the limit, so oversized binaries never enter the model transcript. The check runs in #loadImageContent before loadImageInput/loadSvgImageInput.","triggerScenarios":"Reading any image file (png/jpg/webp/svg, plain path, local:// image, or :img selector) whose fileSize > MAX_IMAGE_SIZE; the pre-check at read.ts:845 fires before decode.","commonSituations":"High-resolution photos or screenshots from DSLR/screencapture; scans saved at 600dpi; uncompressed PNG exports; reading camera originals instead of resized copies.","solutions":["Downscale or recompress the image (e.g. convert to a resized JPEG/WebP) and read that.","Crop to the region of interest to cut bytes.","Use inspect_image metadata mode, which reports MIME/dimensions without attaching pixels (and bypasses the size cap by design).","If the pipeline controls capture, lower screenshot quality/scale at capture time."],"exampleFix":"// before\nread('/photos/IMG_4821.HEIC-converted.png') // 28 MB\n// after\n$ `magick /photos/IMG_4821.png -resize 1600x -quality 80 /tmp/img.png`\nread('/tmp/img.png') // ~400 KB, under MAX_IMAGE_SIZE","handlingStrategy":"validation","validationCode":"import { statSync } from 'node:fs';\nconst MAX_IMAGE_SIZE = 10 * 1024 * 1024; // match tool limit\nconst size = statSync(imgPath).size;\nif (size > MAX_IMAGE_SIZE) {\n  await $`magick ${imgPath} -resize 1600x -quality 80 ${imgPath}.small.jpg`;\n  imgPath = `${imgPath}.small.jpg`;\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await readTool.execute({ path: imgPath });\n} catch (e) {\n  if (e instanceof ToolError && e.message.startsWith('Image file too large')) {\n    const shrunk = await shrinkImage(imgPath);\n    return await readTool.execute({ path: shrunk });\n  }\n  throw e;\n}","preventionTips":["Stat image files and pre-shrink anything above the documented MAX_IMAGE_SIZE.","Capture screenshots at reduced scale/quality when generating them yourself.","Use inspect_image (metadata mode) when you only need dimensions/MIME, not pixels.","Keep working copies of large photos (resized JPEG) separate from originals."],"tags":["image","file-size","limit"],"backgroundTag":"image-file-too-large","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}