openclaw - ✅(Solved) Fix [Bug]: Discord image attachments fail when sharp is missing from package runtime [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#74248Fetched 2026-04-30 06:26:44
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
2
Author
Timeline (top)
cross-referenced ×2closed ×1commented ×1

Discord outbound image attachments fail with Failed to optimize image when sharp is not installed, because the Discord media send path always optimizes image MEDIA: attachments and the published OpenClaw package does not declare sharp as a runtime dependency.

Error Message

OpenClaw 2026.4.26 (be8c246) Linux 6.17.0-20-generic #20~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 01:28:37 UTC 2 x86_64 GNU/Linux

Gateway log: 2026-04-29T16:25:31.661+08:00 [discord] final reply failed (target=channel:1492582924527075568 session=agent:main:discord:channel:1492582924527075568): Error: Failed to optimize image

Direct repro against bundled media loader on generated image files: ERR /home/openclaw/.openclaw/workspace/exports/shoe_mockup_illustration.png Error: Failed to optimize image at optimizeImageToJpeg (.../openclaw/dist/web-media-9UYLzIiN.js:413:8) at async optimizeImageWithFallback (.../openclaw/dist/web-media-9UYLzIiN.js:221:6) at async optimizeAndClampImage (.../openclaw/dist/web-media-9UYLzIiN.js:237:21) at async clampAndFinalize (.../openclaw/dist/web-media-9UYLzIiN.js:269:16) at async loadWebMediaInternal (.../openclaw/dist/web-media-9UYLzIiN.js:343:9)

Underlying image-op error: resize error Error: Optional dependency sharp is required for image attachment processing at .../openclaw/dist/extensions/media-understanding-core/image-ops.js:23:9 at async loadSharp (.../openclaw/dist/extensions/media-understanding-core/image-ops.js:25:9) at async Object.resizeToJpeg (.../openclaw/dist/extensions/media-understanding-core/image-ops.js:51:18) at async resizeToJpeg (.../openclaw/dist/image-ops-B5o_jjbN.js:380:9)

Dependency check: $ npm ls sharp --prefix /home/openclaw/.npm-global/lib/node_modules/openclaw [email protected] /home/openclaw/.npm-global/lib/node_modules/openclaw └── (empty)

Package check: openclaw/package.json showed no dependencies.sharp or optionalDependencies.sharp entry.

Root Cause

Discord outbound image attachments fail with Failed to optimize image when sharp is not installed, because the Discord media send path always optimizes image MEDIA: attachments and the published OpenClaw package does not declare sharp as a runtime dependency.

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

OpenClaw 2026.4.26 (be8c246)
Linux 6.17.0-20-generic #20~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 01:28:37 UTC 2 x86_64 GNU/Linux

Gateway log:
2026-04-29T16:25:31.661+08:00 [discord] final reply failed (target=channel:1492582924527075568 session=agent:main:discord:channel:1492582924527075568): Error: Failed to optimize image

Direct repro against bundled media loader on generated image files:
ERR /home/openclaw/.openclaw/workspace/exports/shoe_mockup_illustration.png Error: Failed to optimize image
    at optimizeImageToJpeg (.../openclaw/dist/web-media-9UYLzIiN.js:413:8)
    at async optimizeImageWithFallback (.../openclaw/dist/web-media-9UYLzIiN.js:221:6)
    at async optimizeAndClampImage (.../openclaw/dist/web-media-9UYLzIiN.js:237:21)
    at async clampAndFinalize (.../openclaw/dist/web-media-9UYLzIiN.js:269:16)
    at async loadWebMediaInternal (.../openclaw/dist/web-media-9UYLzIiN.js:343:9)

Underlying image-op error:
resize error Error: Optional dependency sharp is required for image attachment processing
    at .../openclaw/dist/extensions/media-understanding-core/image-ops.js:23:9
    at async loadSharp (.../openclaw/dist/extensions/media-understanding-core/image-ops.js:25:9)
    at async Object.resizeToJpeg (.../openclaw/dist/extensions/media-understanding-core/image-ops.js:51:18)
    at async resizeToJpeg (.../openclaw/dist/image-ops-B5o_jjbN.js:380:9)

Dependency check:
$ npm ls sharp --prefix /home/openclaw/.npm-global/lib/node_modules/openclaw
openclaw@2026.4.26 /home/openclaw/.npm-global/lib/node_modules/openclaw
└── (empty)

Package check:
openclaw/package.json showed no dependencies.sharp or optionalDependencies.sharp entry.
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

Discord outbound image attachments fail with Failed to optimize image when sharp is not installed, because the Discord media send path always optimizes image MEDIA: attachments and the published OpenClaw package does not declare sharp as a runtime dependency.

Steps to reproduce

  1. Run OpenClaw 2026.4.26 from the npm/global package on Linux without sharp installed under the OpenClaw package.
  2. Produce or locate a local image file, then send it to a Discord channel via an assistant reply containing MEDIA:/path/to/image.png or by returning an image-generation result.
  3. Observe the Discord final reply fail before upload.
  4. Reproduce directly by importing OpenClaw's bundled loadWebMedia(...) and calling it on the same image path with Discord-like options; it throws Failed to optimize image, and resizeToJpeg(...) reveals Optional dependency sharp is required for image attachment processing.

Expected behavior

Discord should upload valid image MEDIA: attachments, or at minimum gracefully skip optimization when the file already fits channel limits and surface an actionable dependency error if optimization is unavailable.

Actual behavior

Discord does not receive the image attachment. The gateway logs final reply failed ... Error: Failed to optimize image. Direct repro shows the underlying cause is the missing sharp package required by extensions/media-understanding-core/image-ops.js.

OpenClaw version

OpenClaw 2026.4.26 (be8c246)

Operating system

Ubuntu 24.04 / Linux 6.17.0-20-generic x86_64

Install method

npm global package under ~/.npm-global/lib/node_modules/openclaw; gateway supervised by systemd/native service on Linux

Model

openai-codex/gpt-5.5 for the assistant session; image generation output was already saved locally before the Discord outbound attachment failure

Provider / routing chain

OpenClaw Discord channel adapter -> outbound MEDIA parser -> Discord send media path -> loadWebMedia/image optimizer -> media-understanding-core image-ops -> dynamic import('sharp')

Additional provider/model setup details

Discord channel adapter is enabled. The failure is in outbound attachment preprocessing before Discord upload; it is not provider/model specific. npm ls sharp --prefix /home/openclaw/.npm-global/lib/node_modules/openclaw returns empty, and openclaw/package.json has no dependencies.sharp or optionalDependencies.sharp entry in this install.

Logs, screenshots, and evidence

OpenClaw 2026.4.26 (be8c246)
Linux 6.17.0-20-generic #20~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 01:28:37 UTC 2 x86_64 GNU/Linux

Gateway log:
2026-04-29T16:25:31.661+08:00 [discord] final reply failed (target=channel:1492582924527075568 session=agent:main:discord:channel:1492582924527075568): Error: Failed to optimize image

Direct repro against bundled media loader on generated image files:
ERR /home/openclaw/.openclaw/workspace/exports/shoe_mockup_illustration.png Error: Failed to optimize image
    at optimizeImageToJpeg (.../openclaw/dist/web-media-9UYLzIiN.js:413:8)
    at async optimizeImageWithFallback (.../openclaw/dist/web-media-9UYLzIiN.js:221:6)
    at async optimizeAndClampImage (.../openclaw/dist/web-media-9UYLzIiN.js:237:21)
    at async clampAndFinalize (.../openclaw/dist/web-media-9UYLzIiN.js:269:16)
    at async loadWebMediaInternal (.../openclaw/dist/web-media-9UYLzIiN.js:343:9)

Underlying image-op error:
resize error Error: Optional dependency sharp is required for image attachment processing
    at .../openclaw/dist/extensions/media-understanding-core/image-ops.js:23:9
    at async loadSharp (.../openclaw/dist/extensions/media-understanding-core/image-ops.js:25:9)
    at async Object.resizeToJpeg (.../openclaw/dist/extensions/media-understanding-core/image-ops.js:51:18)
    at async resizeToJpeg (.../openclaw/dist/image-ops-B5o_jjbN.js:380:9)

Dependency check:
$ npm ls sharp --prefix /home/openclaw/.npm-global/lib/node_modules/openclaw
[email protected] /home/openclaw/.npm-global/lib/node_modules/openclaw
└── (empty)

Package check:
openclaw/package.json showed no dependencies.sharp or optionalDependencies.sharp entry.

Impact and severity

Affected: Discord channels using generated images or local image MEDIA: attachments on installs without sharp. Severity: High for Discord/image workflows because generated images are saved locally but cannot be delivered to the user. Frequency: Observed consistently for multiple local PNG/JPG files while sharp is absent. Consequence: User-visible replies fail to send images over Discord; troubleshooting requires reading bundled JS to discover the missing dependency.

Additional information

Related existing issue: #73148 covers the same missing-sharp class for the image tool and opaque errors. This report adds a separate observed failure path: Discord outbound MEDIA: delivery fails after image generation, before upload, because the send adapter uses the same optimizer dependency. Suggested fixes: declare/stage sharp reliably as a package/plugin runtime dependency, preserve and surface the underlying sharp import error, and consider falling back to raw upload when the image is already within Discord/channel size limits.

extent analysis

TL;DR

Install the sharp package as a runtime dependency for OpenClaw to fix the Discord image attachment optimization issue.

Guidance

  • Verify that sharp is not installed by running npm ls sharp --prefix /home/openclaw/.npm-global/lib/node_modules/openclaw and checking for an empty output.
  • Install sharp as a runtime dependency by adding it to openclaw/package.json under dependencies or optionalDependencies.
  • Consider adding a fallback to upload images without optimization when they are already within Discord channel size limits.
  • Preserve and surface the underlying sharp import error to improve troubleshooting.

Example

No code snippet is provided as the issue is related to package dependencies rather than code implementation.

Notes

The issue is specific to OpenClaw version 2026.4.26 and may not apply to other versions. The suggested fix assumes that installing sharp as a runtime dependency will resolve the issue.

Recommendation

Apply the workaround by installing sharp as a runtime dependency, as this is a direct solution to the identified problem.

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

Discord should upload valid image MEDIA: attachments, or at minimum gracefully skip optimization when the file already fits channel limits and surface an actionable dependency error if optimization is unavailable.

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]: Discord image attachments fail when sharp is missing from package runtime [1 pull requests, 1 comments, 2 participants]