{"record":{"id":"581285043e520081","repo":"zeroclaw-labs/zeroclaw","slug":"generated-image-exceeds-the-mib-size-limit","errorCode":null,"errorMessage":"Generated image exceeds the {} MiB size limit","messagePattern":"Generated image exceeds the (.+?) MiB size limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-tools/src/image_gen.rs","lineNumber":185,"sourceCode":"        .context(\"Failed to read fal.ai response\")?;\n    if body.overflowed {\n        anyhow::bail!(\"fal.ai response exceeds the 1 MiB size limit\");\n    }\n    Ok(body.bytes)\n}\n\nasync fn read_fal_error_text(response: reqwest::Response) -> anyhow::Result<String> {\n    response_body::read_text(response, Some(FAL_ERROR_LIMIT_BYTES))\n        .await\n        .map(|(text, _)| text)\n}\n\nasync fn read_generated_image_body(response: reqwest::Response) -> anyhow::Result<Vec<u8>> {\n    let body = response_body::read_bounded(response, Some(GENERATED_IMAGE_LIMIT_BYTES))\n        .await\n        .context(\"Failed to read generated image bytes\")?;\n    if body.overflowed {\n        anyhow::bail!(\n            \"Generated image exceeds the {} MiB size limit\",\n            GENERATED_IMAGE_LIMIT_BYTES / (1024 * 1024)\n        );\n    }\n    Ok(body.bytes)\n}\n\npub struct ImageGenTool {\n    security: Arc<SecurityPolicy>,\n    workspace_dir: PathBuf,\n    default_model: String,\n    api_key_env: String,\n    persistent_writes: bool,\n    nat64_prefixes: Vec<domain_guard::Nat64Prefix>,\n}\n\nimpl ImageGenTool {\n    pub fn new(","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-tools/src/image_gen.rs#L167-L203","documentation":"download_generated_image reads the image bytes through response_body::read_bounded with GENERATED_IMAGE_LIMIT_BYTES = 20 MiB. If the downloaded image exceeds 20 MiB the reader sets overflowed and this error (with the limit interpolated as '20') aborts the download. The cap bounds agent memory usage and disk writes; oversized outputs are rejected rather than buffered.","triggerScenarios":"Requesting generation parameters that produce very large files: high-resolution lossless PNG, uncompressed TIFF, or animated WebP whose downloaded bytes exceed 20 MiB. The pinned test generated_image_body_rejects_oversized_chunked_chunked_response-style case (generated_image_body_rejects_oversized_chunked_response) fixes the threshold behavior.","commonSituations":"Bumping fal.ai width/height toward model maximums, choosing png/tiff output formats for photos, long animated outputs, and storage providers serving uncompressed originals.","solutions":["Regenerate with smaller dimensions or a compressed format: request jpeg/webp and/or lower quality so the file stays under 20 MiB.","If the asset genuinely must exceed 20 MiB, fetch it outside the tool with an explicit user-approved path; the limit is the internal constant GENERATED_IMAGE_LIMIT_BYTES in crates/zeroclaw-tools/src/image_gen.rs, not a runtime setting.","Check whether the URL points at the compressed derivative rather than the lossless original."],"exampleFix":"# before (fal request)\n{\"prompt\":\"...\",\"image_size\":\"{\\\"width\\\":4096,\\\"height\\\":4096}\",\"format\":\"png\"}  # >20 MiB -> rejected\n\n# after\n{\"prompt\":\"...\",\"image_size\":\"{\\\"width\\\":2048,\\\"height\\\":2048}\",\"format\":\"jpeg\"}          # accepted","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"match download_generated_image(target).await {\n    Err(e) if e.to_string().contains(\"MiB size limit\") => {\n        // shrink the ask: jpeg/webp + smaller dimensions, then retry once\n        regenerate_compressed(request).await\n    }\n    other => other,\n}","preventionTips":["Default generation requests to jpeg/webp and moderate dimensions; avoid lossless png/tiff at model-max resolutions.","Budget ~20 MiB as the hard ceiling for any single generated image in this tool.","If an asset legitimately exceeds the cap, download it through an explicit user-approved path outside the agent tool."],"tags":["size-limit","image-gen","download","response-body","rust"],"backgroundTag":"response-size-limit-exceeded","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}