openclaw - ✅(Solved) Fix image tool: 'Failed to optimize image' error in preprocessing pipeline [1 pull requests, 2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#73424Fetched 2026-04-29 06:20:05
View on GitHub
Comments
2
Participants
3
Timeline
6
Reactions
0
Author
Timeline (top)
cross-referenced ×3commented ×2subscribed ×1

The built-in image tool fails with "Failed to optimize image" when analyzing JPEG images, even though the configured VLM model (nvidia/google/gemma-4-31b-it) works correctly via direct API calls.

Error Message

[tools] image failed: Failed to optimize image
raw_params={"image":"/tmp/openclaw/line-media-...","prompt":"图片内容是什么?..."}

Root Cause

The built-in image tool fails with "Failed to optimize image" when analyzing JPEG images, even though the configured VLM model (nvidia/google/gemma-4-31b-it) works correctly via direct API calls.

Fix Action

Fixed

PR fix notes

PR #73451: fix(media): fallback to original buffer when image optimization fails

Description (problem / solution / changelog)

Problem

optimizeImageToJpeg() throws "Failed to optimize image" when all resize/quality combinations fail, blocking image analysis entirely.\n\n## Solution\nReturn the original buffer as fallback instead of throwing. This allows images to reach VLM models even when optimization fails.\n\n## Changes\n- Replace throw new Error("Failed to optimize image") with return of original buffer\n- Set resizeSide: 0 and quality: 0 to indicate no optimization was applied\n\n## Testing\n- Images that fail optimization now pass through to VLM models\n- Backward compatible: successful optimizations still return optimized data\n\nFixes #73424

Changed files

  • src/media/web-media.ts (modified, +7/-1)

Code Example

{
     "provider": "nvidia",
     "model": "google/gemma-4-31b-it",
     "capabilities": ["image"]
   }

---

[tools] image failed: Failed to optimize image
raw_params={"image":"/tmp/openclaw/line-media-...","prompt":"图片内容是什么?..."}

---

{
  "tools": {
    "media": {
      "image": {
        "enabled": true,
        "models": [{
          "type": "provider",
          "provider": "nvidia",
          "model": "google/gemma-4-31b-it",
          "capabilities": ["image"],
          "maxChars": 500,
          "maxBytes": 10485760,
          "timeoutSeconds": 60
        }]
      }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Bug Report: "Failed to optimize image" error in media understanding pipeline

Description

The built-in image tool fails with "Failed to optimize image" when analyzing JPEG images, even though the configured VLM model (nvidia/google/gemma-4-31b-it) works correctly via direct API calls.

Reproduction Steps

  1. Configure tools.media.image with:
    {
      "provider": "nvidia",
      "model": "google/gemma-4-31b-it",
      "capabilities": ["image"]
    }
  2. Send a JPEG image via LINE channel
  3. Observe error: [tools] image failed: Failed to optimize image

Expected Behavior

Image should be processed and analyzed successfully by the configured VLM model.

Actual Behavior

Error "Failed to optimize image" occurs before the model API call is made.

Verification

Direct API call to nvidia/google/gemma-4-31b-it succeeds:

Test file: ~/.openclaw/media/inbound/line-media-1777358526151-94814333-4e08-4609-ad73-cbe7f629de77.jpg

  • Format: JPEG
  • Size: 279KB (285,590 bytes)
  • Dimensions: 959x1705
  • Result: ✅ Analysis successful (tested via direct Python API call)

This proves the model itself works correctly; the issue is in OpenClaw's internal image preprocessing layer.

Environment

  • OpenClaw Version: 2026.4.25 (aa36ee6)
  • OS: Linux ARM64 (Ubuntu 22.04)
  • Node.js: v24.15.0
  • Configured Model: nvidia/google/gemma-4-31b-it
  • Error Location: Image optimization/preprocessing stage (before model API call)

Logs

[tools] image failed: Failed to optimize image
raw_params={"image":"/tmp/openclaw/line-media-...","prompt":"图片内容是什么?..."}

Additional Context

  • Logger indicates error at: subsystem-BI-xRI3F.js:154
  • The error appears to occur during image resize/format conversion
  • Similar images work fine with other tools (e.g., direct API calls)

Related Configuration

{
  "tools": {
    "media": {
      "image": {
        "enabled": true,
        "models": [{
          "type": "provider",
          "provider": "nvidia",
          "model": "google/gemma-4-31b-it",
          "capabilities": ["image"],
          "maxChars": 500,
          "maxBytes": 10485760,
          "timeoutSeconds": 60
        }]
      }
    }
  }
}

extent analysis

TL;DR

The "Failed to optimize image" error in the media understanding pipeline may be resolved by adjusting the image preprocessing configuration or handling in OpenClaw.

Guidance

  • Verify that the image dimensions and size are within the configured limits (maxBytes and implicit dimension limits) to ensure the issue isn't due to exceeding these boundaries.
  • Check the OpenClaw documentation for any specific requirements or recommendations for image preprocessing, especially regarding JPEG images and the nvidia/google/gemma-4-31b-it model.
  • Consider temporarily modifying the maxBytes or other relevant configuration settings to see if the error persists, which could help isolate the cause.
  • Review the code at subsystem-BI-xRI3F.js:154 for any potential issues with image resize or format conversion that might be causing the failure.

Example

No specific code example can be provided without more details on the OpenClaw API or the exact requirements of the nvidia/google/gemma-4-31b-it model. However, ensuring that images are preprocessed correctly before being passed to the model is crucial.

Notes

The issue seems to be specific to the OpenClaw internal image preprocessing layer, given that direct API calls to the model succeed. This suggests that the problem might be related to how OpenClaw handles image optimization or resizing before passing the image to the model for analysis.

Recommendation

Apply a workaround by adjusting the image preprocessing configuration in OpenClaw, as the root cause appears to be related to how OpenClaw handles images before they are analyzed by the model. This might involve tweaking settings related to image size, format, or the preprocessing pipeline itself.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix image tool: 'Failed to optimize image' error in preprocessing pipeline [1 pull requests, 2 comments, 3 participants]