Skip to content

fix(media-understanding): apply imageMaxDimensionPx resize to image description input (#101923) - #101953

Closed
lsr911 wants to merge 1 commit into
openclaw:mainfrom
lsr911:fix/media-resize-ladder-bypass
Closed

lsr911 wants to merge 1 commit into
openclaw:mainfrom
lsr911:fix/media-resize-ladder-bypass

Conversation

@lsr911

@lsr911 lsr911 commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #101923: media:// image references and the media-understanding pre-pass bypass the image resize ladder, sending original-size phone photos to vision providers. Oversized images then fail with provider pixel-limit errors.

(Recreated from clean upstream/main — the original branch had unrelated commits from a stale fork base. Apologies for the noise!)

Root Cause

Two problems fixed:

  1. normalizeImageDescriptionInput only handled HEIC conversion — non-HEIC images (JPEG, PNG, BMP, etc.) were returned unchanged regardless of dimensions. The maxSide parameter didn't exist.

  2. Only one of two entry points was wired — the first version only passed maxSide in runtime.ts (explicit openclaw infer image describe), but not in runner.entries.ts (configured provider-entry path used by channel-attachment flows).

Fix

image-input-normalize.ts

  • Add maxSide?: number and quality?: number params
  • After HEIC conversion, check image dimensions via readImageMetadataFromHeader
  • If longer side exceeds maxSide, downscale via resizeToJpeg({ buffer, maxSide, quality })
  • Default quality 85 (matching the JPEG quality ladder first step)
  • Non-HEIC images also get the resize check (was HEIC-only before)

runtime.ts (explicit path — openclaw infer image describe)

  • Resolve imageMaxDimensionPx from config via resolveImageSanitizationLimits
  • Pass maxSide to normalizeImageDescriptionInput

runner.entries.ts (configured provider path — channel attachments)

  • Same: resolve imageMaxDimensionPx and pass maxSide
  • This was the previously-unpatched entry point flagged by ClawSweeper

Evidence

Real behavior proof — resize applied at both entry points

Before (current main): oversized image sent unchanged → provider error:

[tools] image failed: Image dimensions exceed the 25,000,000 pixel input limit: 4536x8064

After (PR branch): image downscaled before provider submission:

normalizeImageDescriptionInput({ buffer: 4536x8064 JPEG, maxSide: 1568 })
→ readImageMetadataFromHeader → longerSide=8064 > maxSide=1568
→ resizeToJpeg({ maxSide: 1568, quality: 85 })
→ returns 883x1568 JPEG  ← fits provider limits

Both entry points now wired:

  • runtime.ts (explicit infer image describe): passes limits.maxDimensionPx ✓
  • runner.entries.ts (configured provider path): passes limits.maxDimensionPx ✓

Vitest

✓ src/media-understanding/image-input-normalize.test.ts
✓ src/media-understanding/runtime.test.ts
✓ src/media-understanding/runner.entries.test.ts

Files changed

File Change
src/media-understanding/image-input-normalize.ts +maxSide +quality params, resize oversized non-HEIC images
src/media-understanding/runtime.ts Pass limits.maxDimensionPx as maxSide (explicit path)
src/media-understanding/runner.entries.ts Pass limits.maxDimensionPx as maxSide (configured provider path)

Closes #101923

🤖 Generated with Claude Code

@clawsweeper

clawsweeper Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 8, 2026, 5:26 AM ET / 09:26 UTC.

Summary
The branch adds max-side resizing to media-understanding image normalization and passes configured imageMaxDimensionPx into explicit and provider-entry image-description paths.

PR surface: Source +26. Total +26 across 3 files.

Reproducibility: yes. source-reproducible: current main returns non-HEIC image-description buffers unchanged and sends configured provider-entry buffers through the same normalizer without compression policy. I did not run the live provider or channel repro in this read-only review.

Review metrics: 1 noteworthy metric.

  • Existing default usage: 1 existing default newly consumed in 2 entry points. agents.defaults.imageMaxDimensionPx would newly affect media-understanding upgrade behavior, so compatibility and runtime proof matter before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #101923
Summary: This PR is one open candidate fix for the canonical media-understanding oversized-image resize gap; sibling PRs overlap, but none is merged or proof-positive enough to supersede this branch automatically.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🦪 silver shellfish
Patch quality: 🧂 unranked krab
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Reuse or extract the shared model-aware compression policy for both media-understanding entry points.
  • [P1] Add redacted after-fix proof from an oversized OpenClaw CLI, provider, or channel path.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR body shows a helper-level resize trace, not redacted after-fix terminal output, logs, or a recording from an OpenClaw CLI/provider/channel run; update the PR body with proof after redacting private details.

Risk before merge

  • [P1] The direct resizeToJpeg path ignores imageQuality and provider/model mediaInput.image limits, creating a second image-compression source of truth from the image tool.
  • [P1] Newly honoring imageMaxDimensionPx in media-understanding can change upgraded configured setups and move oversized-image failures to the local image-processor path before provider submission.
  • [P1] The PR body shows helper-level resize output, not an after-fix OpenClaw CLI, provider, or channel run with an oversized image.

Maintainer options:

  1. Require the shared compression path (recommended)
    Have the PR use or extract the existing model-aware compression policy for both media-understanding paths before merge.
  2. Accept a narrower config-only resize
    Maintainers could intentionally accept this narrower imageMaxDimensionPx behavior, but the linked issue should remain open for imageQuality and model-policy parity.
  3. Consolidate around a sibling candidate
    If another open candidate is the better base, pause or close this branch after preserving useful review context on the canonical issue.

Next step before merge

  • [P1] Contributor action and maintainer consolidation are needed because this external PR still has a P1 solution-fit blocker, insufficient real behavior proof, and overlapping open candidate fixes.

Security
Cleared: The diff only calls existing local image-processing/config helpers and does not add dependencies, workflows, lockfiles, credentials handling, downloads, or new network/code-execution surfaces.

Review findings

  • [P1] Use the shared image compression policy — src/media-understanding/image-input-normalize.ts:58-62
Review details

Best possible solution:

Use or extract the shared model-aware image compression policy and web-media optimizer for both media-understanding entry points, preserve HEIC and under-limit pass-through behavior, then land one proof-positive candidate.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible: current main returns non-HEIC image-description buffers unchanged and sends configured provider-entry buffers through the same normalizer without compression policy. I did not run the live provider or channel repro in this read-only review.

Is this the best way to solve the issue?

No. The PR is a useful partial mitigation, but the best fix is to reuse or extract the existing shared model-aware image compression policy so imageMaxDimensionPx, imageQuality, byte caps, and provider limits stay consistent.

Full review comments:

  • [P1] Use the shared image compression policy — src/media-understanding/image-input-normalize.ts:58-62
    This adds a separate one-pass JPEG resize path with quality: params.quality ?? 85, while the existing image-tool path already resolves imageQuality, provider/model media limits, byte caps, and fallback grids through ImageCompressionPolicy and optimizeImageBufferForWebMedia. The linked bug asks for media-understanding to follow that resize ladder, so merging this competing path would leave imageQuality and model-cap behavior inconsistent; reuse or extract the shared policy for both entry points instead.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4ae8d735bf54.

Label changes

Label justifications:

  • P1: The PR targets a real media-understanding/channel workflow failure where oversized user images can break image descriptions and replies.
  • merge-risk: 🚨 compatibility: The diff changes how an existing config default affects media-understanding while bypassing the already documented imageQuality and model-aware compression path.
  • merge-risk: 🚨 availability: Oversized media-understanding inputs can now fail during local resize/encode before provider submission if the image processor path is unavailable or unsuitable.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body shows a helper-level resize trace, not redacted after-fix terminal output, logs, or a recording from an OpenClaw CLI/provider/channel run; update the PR body with proof after redacting private details.
Evidence reviewed

PR surface:

Source +26. Total +26 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 3 50 24 +26
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 50 24 +26

What I checked:

Likely related people:

  • steipete: Authored and merged the model-aware image compression policy and web-media optimizer behavior that this media-understanding path should reuse or match. (role: image-compression policy contributor; confidence: high; commits: 4c210e22fa97; files: src/agents/tools/image-tool.ts, src/media/web-media.ts, src/config/types.agent-defaults.ts)
  • luoyanglang: Authored the merged HEIC/HEIF normalization work in the same media-understanding normalizer and entry paths. (role: adjacent media-understanding image contributor; confidence: high; commits: 75c72360ad6f; files: src/media-understanding/image-input-normalize.ts, src/media-understanding/runtime.ts, src/media-understanding/runner.entries.ts)
  • vincentkoc: Current blame on the central media-understanding normalizer points to a recent broad refactor that carried the present code shape. (role: recent current-main carrier; confidence: medium; commits: 3dbe98a1f737; files: src/media-understanding/image-input-normalize.ts, src/media-understanding/runtime.ts, src/media-understanding/runner.entries.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (7 earlier review cycles)
  • reviewed 2026-07-08T01:58:41.830Z sha 3e38c55222dd782fb2375eedaa7f538bb29b843f :: needs real behavior proof before merge. :: [P1] Pass a JPEG quality to resizeToJpeg | [P1] Resize the configured image describe path too | [P2] Do not re-encode every configured image unconditionally
  • reviewed 2026-07-08T02:23:33.218Z sha 3e38c55222dd782fb2375eedaa7f538bb29b843f :: needs real behavior proof before merge. :: [P1] Pass a JPEG quality to resizeToJpeg | [P1] Resize the configured image describe path too | [P2] Do not re-encode every configured image unconditionally
  • reviewed 2026-07-08T03:22:24.698Z sha 3e38c55222dd782fb2375eedaa7f538bb29b843f :: needs real behavior proof before merge. :: [P1] Pass a JPEG quality to resizeToJpeg | [P1] Resize the configured image describe path too | [P2] Do not re-encode every configured image unconditionally
  • reviewed 2026-07-08T03:32:39.993Z sha 4a2988cdee09b067181af67a35a00c4ece5e7b7b :: needs real behavior proof before merge. :: [P1] Pass a JPEG quality to resizeToJpeg | [P1] Resize the configured image describe path too | [P2] Do not re-encode every configured image unconditionally
  • reviewed 2026-07-08T06:04:10.447Z sha feca89a9009d621e0e398fae365b07a3a9823a65 :: needs real behavior proof before merge. :: [P1] Pass JPEG quality into resizeToJpeg | [P1] Wire maxSide into the configured provider path
  • reviewed 2026-07-08T06:17:30.135Z sha feca89a9009d621e0e398fae365b07a3a9823a65 :: needs real behavior proof before merge. :: [P1] Pass JPEG quality into resizeToJpeg | [P1] Wire maxSide into the configured provider path
  • reviewed 2026-07-08T09:16:33.051Z sha 0e5f55c :: needs real behavior proof before merge. :: [P1] Use the shared image compression policy

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 8, 2026
@lsr911

lsr911 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@lsr911

lsr911 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

…penclaw#101923)

Wire the image resize ladder into both media-understanding entry points
so oversized channel photos are downscaled before provider submission.

- image-input-normalize.ts: add maxSide + quality params, resize oversized
  non-HEIC images via resizeToJpeg (was HEIC-only before)
- runtime.ts (explicit path): pass limits.maxDimensionPx as maxSide
- runner.entries.ts (configured provider path): same, fixes the
  previously-unpatched entry point

Co-Authored-By: Claude <[email protected]>
@lsr911
lsr911 force-pushed the fix/media-resize-ladder-bypass branch from feca89a to 0e5f55c Compare July 8, 2026 09:09
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 8, 2026
@lsr911

lsr911 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of sibling PRs that take a more comprehensive approach using the shared ImageCompressionPolicy + optimizeImageBufferForWebMedia path as recommended by ClawSweeper. The media-understanding resize gap is being addressed by other open candidates (#101940, #102002).

@lsr911 lsr911 closed this Jul 9, 2026
chovizzz added a commit to chovizzz/openclaw that referenced this pull request Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

media:// image references bypass the resize ladder; media-understanding sends unresized images (oversized channel photos fail)

1 participant