zeroclaw-labs/zeroclaw · error

Too many generated image redirects (max {MAX_IMAGE_REDIRECTS

Error message

Too many generated image redirects (max {MAX_IMAGE_REDIRECTS})

What it means

Thrown by ZeroClaw's image generation tool when downloading the generated image from fal.ai follows more than 10 HTTP redirects. The downloader builds its reqwest client with redirect Policy::none() and walks Location headers manually, re-running the NAT64/domain guard on every hop; the loop at crates/zeroclaw-tools/src/image_gen.rs:260 is bounded by MAX_IMAGE_REDIRECTS = 10. Seeing this error means the 11th response in the chain was still a 3xx.

Source

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

    async fn download_generated_image(
        image_url: &str,
        nat64_prefixes: &[domain_guard::Nat64Prefix],
    ) -> anyhow::Result<Vec<u8>> {
        let mut current_url =
            reqwest::Url::parse(image_url).context("Invalid generated image URL")?;

        for redirect_count in 0..=MAX_IMAGE_REDIRECTS {
            let (target, client) =
                prepare_generated_image_target(current_url.as_str(), nat64_prefixes).await?;
            let response = client
                .get(target.url.clone())
                .send()
                .await
                .context("Failed to download generated image")?;

            if response.status().is_redirection() {
                if redirect_count == MAX_IMAGE_REDIRECTS {
                    anyhow::bail!("Too many generated image redirects (max {MAX_IMAGE_REDIRECTS})");
                }
                let location = response
                    .headers()
                    .get(LOCATION)
                    .ok_or_else(|| anyhow::Error::msg("Generated image redirect omitted Location"))?
                    .to_str()
                    .context("Generated image redirect Location is not valid text")?;
                current_url = resolve_redirect_url(&target.url, location)?;
                continue;
            }

            if !response.status().is_success() {
                anyhow::bail!(
                    "Generated image download failed with HTTP {}",
                    response.status()
                );
            }

View on GitHub (pinned to 88bb9c8533)

Solutions

  1. Take the image URL from the surrounding error context and follow it manually with curl -I to see the Location chain and where it loops or stalls
  2. Retry the whole generation call - a fresh image URL usually avoids the bad chain
  3. Bypass or allowlist the fal.ai media hosts on any redirect-injecting proxy or captive portal in front of the agent
  4. Only if the chain legitimately exceeds 10 hops, raise MAX_IMAGE_REDIRECTS (crates/zeroclaw-tools/src/image_gen.rs:16) and rebuild
Defensive patterns

Strategy: fallback

Type guard

fn is_redirect_overflow(err: &anyhow::Error) -> bool {
    err.to_string()
        .starts_with("Too many generated image redirects")
}

Try / catch

match image_gen.execute(args).await {
    Ok(result) => result,
    Err(e) if is_redirect_overflow(&e) => {
        // deterministic loop: never retry the same URL;
        // fall back to regenerating the image for a fresh URL
        regenerate_or_report(e)
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: The image URL returned by the fal.ai generation call never terminates in a 2xx within 10 hops: a circular redirect (host A redirects to B and back), a CDN/shortener chain longer than 10 links, or a misbehaving endpoint that always answers 301/302. Because resolve_redirect_url re-resolves every Location, alternating redirect targets also produce the loop.

Common situations: fal.ai changing its media CDN layout; a corporate proxy or captive portal injecting extra redirects in front of the agent; dual-stack/NAT64 environments where a host alternates between two redirect targets; a stale zeroclaw-tools build pointing at a deprecated fal.ai storage domain.

Related errors


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