zeroclaw-labs/zeroclaw · error

Generated image exceeds the {} MiB size limit

Error message

Generated image exceeds the {} MiB size limit

What it means

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.

Source

Thrown at crates/zeroclaw-tools/src/image_gen.rs:185

        .context("Failed to read fal.ai response")?;
    if body.overflowed {
        anyhow::bail!("fal.ai response exceeds the 1 MiB size limit");
    }
    Ok(body.bytes)
}

async fn read_fal_error_text(response: reqwest::Response) -> anyhow::Result<String> {
    response_body::read_text(response, Some(FAL_ERROR_LIMIT_BYTES))
        .await
        .map(|(text, _)| text)
}

async fn read_generated_image_body(response: reqwest::Response) -> anyhow::Result<Vec<u8>> {
    let body = response_body::read_bounded(response, Some(GENERATED_IMAGE_LIMIT_BYTES))
        .await
        .context("Failed to read generated image bytes")?;
    if body.overflowed {
        anyhow::bail!(
            "Generated image exceeds the {} MiB size limit",
            GENERATED_IMAGE_LIMIT_BYTES / (1024 * 1024)
        );
    }
    Ok(body.bytes)
}

pub struct ImageGenTool {
    security: Arc<SecurityPolicy>,
    workspace_dir: PathBuf,
    default_model: String,
    api_key_env: String,
    persistent_writes: bool,
    nat64_prefixes: Vec<domain_guard::Nat64Prefix>,
}

impl ImageGenTool {
    pub fn new(

View on GitHub (pinned to 88bb9c8533)

Solutions

  1. Regenerate with smaller dimensions or a compressed format: request jpeg/webp and/or lower quality so the file stays under 20 MiB.
  2. 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.
  3. Check whether the URL points at the compressed derivative rather than the lossless original.

Example fix

# before (fal request)
{"prompt":"...","image_size":"{\"width\":4096,\"height\":4096}","format":"png"}  # >20 MiB -> rejected

# after
{"prompt":"...","image_size":"{\"width\":2048,\"height\":2048}","format":"jpeg"}          # accepted
Defensive patterns

Strategy: fallback

Try / catch

match download_generated_image(target).await {
    Err(e) if e.to_string().contains("MiB size limit") => {
        // shrink the ask: jpeg/webp + smaller dimensions, then retry once
        regenerate_compressed(request).await
    }
    other => other,
}

Prevention

When it happens

Trigger: 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.

Common situations: Bumping fal.ai width/height toward model maximums, choosing png/tiff output formats for photos, long animated outputs, and storage providers serving uncompressed originals.

Related errors


AI-assisted analysis of zeroclaw-labs/zeroclaw@88bb9c8533 (2026-08-23). Data as JSON: /api/errors/581285043e520081. Report an issue: GitHub.