openclaw - ✅(Solved) Fix BUG: media-understanding-core cannot resolve staged sharp dependency for image processing [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#74111Fetched 2026-04-30 06:28:24
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
0
Author
Timeline (top)
cross-referenced ×4labeled ×2closed ×1commented ×1

Image processing failed with Failed to optimize image because media-understanding-core could not resolve its required sharp dependency. The package declares sharp and stageRuntimeDependencies, but the staged dependency path was not usable by the ESM import("sharp") in image ops in this install state.

Root Cause

Image processing failed with Failed to optimize image because media-understanding-core could not resolve its required sharp dependency. The package declares sharp and stageRuntimeDependencies, but the staged dependency path was not usable by the ESM import("sharp") in image ops in this install state.

Fix Action

Fixed

PR fix notes

PR #74243: media: keep sendable images when optimization fails

Description (problem / solution / changelog)

Summary

  • fall back to the original image when optimization fails but the original is already under the channel/media cap
  • preserve the original MIME/content type when returning original bytes instead of labeling non-JPEG fallbacks as JPEG
  • fail closed for HEIC conversion, pixel-limit, and unsafe/unknown-dimension guard errors
  • preserve the underlying optimizer failure as the thrown error cause with attempt/failure diagnostics
  • add regression coverage for optimizer backend failures and byte-small pixel-oversized images

Why

Shared media loading can fail before Telegram/WhatsApp/Discord/image-tool delivery when the image optimizer throws, even for images that are already safe to send under the channel cap. In that case, failing the whole send is worse than sending the original file — but only if the original image is still valid under the resource guards.

This PR is intended as the conservative consolidation path for the current optimizer failure family:

  • keep the useful under-cap fallback from #73451 / #74170
  • keep MIME preservation by doing fallback at loadWebMedia/optimizeAndClampImage, not by returning original bytes from optimizeImageToJpeg as JPEG
  • keep pixel/dimension guard failures fail-closed, preserving the security boundary added by #58226
  • include optimizer diagnostics/cause from #73217 / #74228 so production logs are no longer opaque
  • remain compatible with the runtime dependency packaging fixes in #74216 / #74172; those fix missing sharp, while this keeps media handling robust when optimization still fails

Close / supersede plan if this lands

This PR should close the active shared-preprocessing bug reports:

Closes #73424. Closes #73148.

This PR should make these open implementation PRs redundant/superseded, assuming maintainers accept this consolidated policy:

Supersedes #73451. Supersedes #74170. Supersedes #74228. Supersedes #73217.

This PR also resolves the shared-media failure described by these already-closed duplicate/evidence issues, but they do not need auto-closing:

Resolves duplicate evidence from #73473, #73591, #73665, #73224, #74111, #74248, and #7375.

This PR intentionally does not claim to close:

  • #74216 — packaging/runtime-dependency staging for library extensions. This is complementary: it fixes missing sharp at install/update time, while this PR fixes shared media behavior when optimization fails or cannot produce output.
  • #74172 — closed narrow sharp dependency fix. Same root family, but already closed and complementary.
  • #38260 — native libvips SIGILL crash. A JavaScript fallback can handle thrown optimizer failures, but it cannot catch a hard native process crash after libvips terminates the gateway. That issue still needs reproduction/backtrace and crash-isolation or runtime-dependency work.
  • #41769 — older macOS ARM64 sharp load issue that appears mostly superseded by runtime architecture changes; referenced only as historical context.

Related issues / PRs checked

Canonical / direct duplicates

  • #73424 — canonical open Failed to optimize image preprocessing bug
  • #73473 — closed duplicate: webchat/Feishu image tool broken after 2026.4.26
  • #73591 — closed duplicate/additional evidence: WhatsApp media sends fail with same error
  • #73665 — closed duplicate/additional evidence: MiniMax image understanding fails after 2026.4.26

Same root family: missing/broken optimizer dependency

  • #73148 — opaque failure when sharp is missing; this PR now preserves the underlying cause and keeps under-cap originals usable
  • #73224 — media-understanding-core/sharp not installed after upgrade
  • #74111 — staged sharp runtime dependency resolution failure
  • #74248 — Discord image attachments fail when sharp is missing from package runtime
  • #7375 — older Ubuntu/Slack PNG optimizer failure report
  • #41769 — older macOS ARM64 sharp load issue; mostly superseded by runtime architecture changes, but same failure class

Adjacent but not closed by this PR

  • #74216 — install/runtime-deps staging for library extensions; complementary packaging fix
  • #38260 — native libvips SIGILL crash; requires separate crash-level investigation/isolation

Related PRs compared

  • #73451 — fallback in optimizeImageToJpeg; useful policy, but risks MIME mismatch and overly broad fallback
  • #74170 — similar fallback fork; this PR keeps the behavior but adds MIME preservation and guard boundaries
  • #74228 — diagnostic cause/counter reporting; folded into this PR
  • #73217 — earlier diagnostic cause PR for #73148; folded into this PR's error cause behavior
  • #74216 — packaging/runtime-deps fix for library extensions; complementary, not replaced by this PR
  • #74172 — closed narrow sharp dependency fix; complementary/root-cause packaging path
  • #58226 — merged decoded pixel-area guard; this PR explicitly preserves its fail-closed behavior

Test plan

  • corepack pnpm exec oxfmt --write --threads=1 src/media/web-media.ts src/media/web-media.test.ts src/media/web-media.optimizer-fallback.test.ts src/media/image-ops.input-guard.test.ts
  • corepack pnpm exec oxlint --tsconfig tsconfig.oxlint.core.json src/media/web-media.ts src/media/web-media.optimizer-fallback.test.ts
  • corepack pnpm vitest run src/media/web-media.optimizer-fallback.test.ts src/media/web-media.test.ts src/media/image-ops.input-guard.test.ts
  • git diff --check

Changed files

  • src/media/web-media.optimizer-fallback.test.ts (added, +80/-0)
  • src/media/web-media.test.ts (modified, +16/-0)
  • src/media/web-media.ts (modified, +45/-3)

Code Example

Observed errors:

[tools] image failed: Failed to optimize image
Optional dependency sharp is required for image attachment processing
ERR_MODULE_NOT_FOUND: Cannot find package 'sharp' imported from .../dist/extensions/media-understanding-core/image-ops.js

Package evidence:
"dependencies": { "sharp": "^0.34.5" },
"openclaw": { "bundle": { "stageRuntimeDependencies": true } }

Repair verification:
Installing sharp@0.34.5 only into the staged runtime-deps root did not make the ESM import in image ops resolve sharp.

Installing sharp@0.34.5 under the package-local dist/extensions/media-understanding-core/node_modules made image metadata extraction and image description succeed on the same valid local images.
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

Image processing failed with Failed to optimize image because media-understanding-core could not resolve its required sharp dependency. The package declares sharp and stageRuntimeDependencies, but the staged dependency path was not usable by the ESM import("sharp") in image ops in this install state.

Steps to reproduce

  1. Use OpenClaw 2026.4.26 from the npm/global packaged install.
  2. Ensure media-understanding-core does not have a package-local node_modules/sharp directory.
  3. Invoke image understanding on a valid local PNG/JPG.
  4. Observe image processing fail before model analysis.
  5. Installing [email protected] directly under the media-understanding-core package-local node_modules makes the same image operation succeed.

Expected behavior

A valid local PNG/JPG should be optimized/read successfully and passed to the configured image-capable model.

Actual behavior

The image tool failed with Failed to optimize image. Direct reproduction of the image ops path showed Optional dependency sharp is required for image attachment processing, caused by ERR_MODULE_NOT_FOUND: Cannot find package 'sharp' imported from the media-understanding-core image ops module.

OpenClaw version

2026.4.26 (be8c246)

Operating system

Ubuntu 26.04 LTS

Install method

npm global package install

Model

Image-capable model configured through OpenClaw image tooling; failure occurred before model analysis.

Provider / routing chain

OpenClaw image tool -> media-understanding-core image optimization/metadata path -> configured image model

Additional provider/model setup details

N/A

Logs, screenshots, and evidence

Observed errors:

[tools] image failed: Failed to optimize image
Optional dependency sharp is required for image attachment processing
ERR_MODULE_NOT_FOUND: Cannot find package 'sharp' imported from .../dist/extensions/media-understanding-core/image-ops.js

Package evidence:
"dependencies": { "sharp": "^0.34.5" },
"openclaw": { "bundle": { "stageRuntimeDependencies": true } }

Repair verification:
Installing [email protected] only into the staged runtime-deps root did not make the ESM import in image ops resolve sharp.

Installing [email protected] under the package-local dist/extensions/media-understanding-core/node_modules made image metadata extraction and image description succeed on the same valid local images.

Impact and severity

Image/screenshot understanding is unavailable for valid local images in this install state. This blocks screenshot-based troubleshooting and any workflow that depends on image attachments.

Additional information

This report intentionally avoids claiming whether the issue is unique to 2026.4.26 or whether it can occur after specific update/restart sequences. The grounded observation is that, in a 2026.4.26 packaged install, the media-understanding-core runtime dependency was not resolvable from the staged location by the ESM image ops import, while package-local installation fixed the failure.

extent analysis

TL;DR

Installing [email protected] directly under the media-understanding-core package-local node_modules resolves the image processing failure.

Guidance

  • Verify that the sharp dependency is correctly declared in the media-understanding-core package dependencies and that the version matches the required ^0.34.5.
  • Check the openclaw configuration to ensure that stageRuntimeDependencies is properly set up to allow the ESM import to resolve the sharp dependency.
  • Try installing [email protected] under the package-local node_modules directory to confirm that this resolves the issue, as observed in the provided evidence.
  • Investigate why the staged runtime dependency is not resolvable by the ESM import, considering the openclaw version and configuration.

Example

No code snippet is provided as the issue is related to dependency resolution and configuration.

Notes

The issue seems to be specific to the openclaw version 2026.4.26 and the media-understanding-core package configuration. The provided evidence suggests that installing sharp locally resolves the issue, but the root cause of the staged dependency resolution failure is still unclear.

Recommendation

Apply the workaround by installing [email protected] under the media-understanding-core package-local node_modules directory, as this has been shown to resolve the image processing failure.

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

A valid local PNG/JPG should be optimized/read successfully and passed to the configured image-capable model.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING