openclaw - ✅(Solved) Fix [Bug]: Images in context are being repeatedly resized on every message [1 pull requests, 1 comments, 2 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#64418Fetched 2026-04-11 06:15:03
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×2commented ×1cross-referenced ×1

When a session contains images (either from user messages or processed via image tool), OpenClaw's tool-images module appears to re-resize the same image on every subsequent user message, even when the image hasn't changed and was already resized in a previous turn.

Root Cause

When a session contains images (either from user messages or processed via image tool), OpenClaw's tool-images module appears to re-resize the same image on every subsequent user message, even when the image hasn't changed and was already resized in a previous turn.

Fix Action

Fixed

PR fix notes

PR #64514: fix(agents): add resize cache to avoid redundant image reprocessing

Description (problem / solution / changelog)

Summary

Images in session history were being re-processed through resizeImageBase64IfNeeded on every message turn via sanitizeSessionMessagesImages. This caused:

  1. Duplicate Image resized to fit limits log entries on every message
  2. Wasted CPU on redundant getImageMetadata header reads and resize evaluations
  3. Token waste from re-processing already-resized images

Root Cause

sanitizeSessionMessagesImages processes ALL historical messages on every turn. For images, this calls sanitizeContentBlocksImagesresizeImageBase64IfNeeded each time. Even though there is an early-return when an image is already within limits, the expensive getImageMetadata call still happens every turn.

Fix

Added a resize cache (RESIZE_CACHE) in resizeImageBase64IfNeeded:

  • Key: SHA-256 hash of (maxDimensionPx:maxBytes:base64.slice(0,1000))
  • Value: The full result { base64, mimeType, resized, width?, height? }
  • Eviction: Simple LRU at 200 entries (first key in insertion order)

Cache entries are stored after both:

  1. The no-op early return (when image is already within limits)
  2. The successful resize return (when image was resized)

On subsequent turns, identical inputs hit the cache and return instantly without any image processing.

Test

pnpm test -- --run src/agents/tool-images.test.ts passes all 5 tests.

Fixes #64418

Changed files

  • src/agents/tool-images.ts (modified, +54/-3)
  • src/commands/doctor-gateway-health.ts (modified, +2/-4)
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

When a session contains images (either from user messages or processed via image tool), OpenClaw's tool-images module appears to re-resize the same image on every subsequent user message, even when the image hasn't changed and was already resized in a previous turn.

Steps to reproduce

  1. Send an image in a chat session (via Telegram or URL)
  2. Observe in gateway logs: Image resized to fit limits: 1222x286px 89.8KB -> 17.4KB (-80.6%)
  3. Send any text-only message (no new image)
  4. The same resize log appears again
  5. Repeat — the log appears on every single message

Expected behavior

An image should be resized once when first added to context, then cached in its resized form. Subsequent messages should not trigger re-compression unless the context has been compacted or the image was evicted and re-added.

Actual behavior

The same image is resized on every message turn, producing excessive and redundant log entries every single time a user sends a message.

OpenClaw version

2026.03.28

Operating system

Mac OS

Install method

No response

Model

MiniMax M2.7

Provider / routing chain

Openclawo - > MiniMax

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

TL;DR

The issue can be addressed by implementing a caching mechanism for resized images in the tool-images module to prevent redundant resizing on every user message.

Guidance

  • Investigate the tool-images module to identify why the resized image is not being cached or why the cache is not being checked before resizing.
  • Verify that the image resizing logic is correctly checking for existing resized images before attempting to resize again.
  • Consider adding a cache invalidation mechanism to handle cases where the context is compacted or the image is evicted and re-added.
  • Review the logging configuration to suppress redundant log entries for repeated resizing of the same image.

Example

No code snippet can be provided without more information about the tool-images module's implementation.

Notes

The provided information suggests a regression issue, but without more details about the changes made to the tool-images module or the surrounding code, it's difficult to provide a more specific fix.

Recommendation

Apply a workaround by implementing a caching mechanism for resized images in the tool-images module, as this is likely to address the root cause of the issue.

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…

FAQ

Expected behavior

An image should be resized once when first added to context, then cached in its resized form. Subsequent messages should not trigger re-compression unless the context has been compacted or the image was evicted and re-added.

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 [Bug]: Images in context are being repeatedly resized on every message [1 pull requests, 1 comments, 2 participants]