Skip to content

fix(media-understanding): apply image compression policy to media:// references - #101940

Closed
LiuwqGit wants to merge 6 commits into
openclaw:mainfrom
LiuwqGit:feat/issue-101923-media-image-resize
Closed

LiuwqGit wants to merge 6 commits into
openclaw:mainfrom
LiuwqGit:feat/issue-101923-media-image-resize

Conversation

@LiuwqGit

@LiuwqGit LiuwqGit commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: media:// image references, explicit model calls, and CLI infer image describe all bypassed image compression policy, causing oversized photos to fail with provider dimension limit errors
  • Solution: Resolve image compression policy from two sources — configured model metadata (openclaw.json) + bundled static catalog — and apply it via optimizeImageBufferForWebMedia before provider execution. Covers all three entry points: channel-triggered media:// references, runtime API describeImageFileWithModel, and CLI infer image describe --model.
  • What changed: 6 files (+110/-100 relative to original PR head, +126/-14 net vs main at time of original PR)
    • runner.entries.ts: resolveImageCompressionPolicyFromConfig now merges configured model limits (cfg.models.providers.*.models[].mediaInput.image) with bundled static catalog limits. Configured takes priority; catalog fills gaps.
    • runtime.ts: imports the shared helper from runner.entries; passes provider/model through prepareImageDescriptionInput to resolve model-aware policy
    • capability-cli.ts: passes activeModel.provider/model into prepareImageDescriptionInput so catalog/config limits are resolved for CLI image describe
    • runner.test-mocks.ts: add applySecretRefHeaderSentinels to model-auth mock (upstream compat)
    • runner.vision-skip.test.ts: add media-services.js + provider-secret-egress mocks (upstream compat)
    • apply.test.ts: add createImageProcessor/readImageProbe mocks and adapt HEIC test expectations (upstream compat)
  • What did NOT change: image tool (resolveCompressionModelPolicy unchanged), HEIC normalization boundary, web-media helpers, config surface

Fixes #101923

Root Cause

  • resolveImageCompressionPolicyFromConfig only read agents.defaults (preferredSidePx), producing a policy without hard maxSidePx/maxPixels. optimizeImageBufferForWebMedia preserves originals when no hard constraints exist, so provider-specific dimension caps (e.g. Anthropic 2576px maxSidePx) were bypassed.
  • The CLI --model path also called preparation before provider/model were known, so the model-catalog lookup could not resolve.
  • Missing detection: no test verifying media-understanding applies the same model-aware policy as the image tool.

Real behavior proof

  • Behavior or issue addressed: Oversized images reaching media-understanding providers without compression, bypassing provider dimension caps
  • Real environment tested: Linux Node 22, pnpm install + pnpm build, worktree isolation
  • Exact steps or command run after this patch:
# Generate oversized test image
convert -size 4096x4096 xc:red /tmp/test-oversized-4096.png
# Run integrated pipeline with model-aware policy
  • Evidence after fix:
BEFORE: /tmp/test-oversized-4096.png PNG 4096x4096
POLICY: {"quality":"balanced","models":[{"preferredSidePx":2048},{"maxSidePx":2576,"preferredSidePx":2576}]}
AFTER: /tmp/test-optimized.png JPEG 2048x2048
VERDICT: 4096x4096 → 2048x2048 ✅
  • Observed result after fix: 4096x4096 PNG compressed to 2048x2048 JPEG. Policy merges agents.defaults (preferredSidePx:2048) with bundled static catalog mediaInput.image (maxSidePx:2576 from anthropic/claude-sonnet-5) and configured model metadata when present. All three code paths now pass provider/model into compression resolution.
  • What was not tested: Live provider execution (no API keys). Image processing pipeline and policy resolution validated through unit tests; the compression path reuses the same web-media helpers and catalog lookup the image tool already exercises in live calls.

Regression Test Plan

  • Coverage level: Unit tests across media-understanding test files
  • Test files and pass counts:
    • runtime.test.ts: 21/21 — image normalization, HEIC bypass, remote references
    • runner.vision-skip.test.ts: 18/18 — provider routing, native vision skip, MiniMax VLM fallback
    • runner.entries.guards.test.ts: 12/12 — entry guard invariants
    • apply.test.ts: 54/54 — attachment transcription, local binary probing, HEIC images
    • image-tool.test.ts: 94/94 — sibling image-tool compression policy contract
    • Total: 199/199 passing
  • Upstream compat fixes: pre-existing test failures from upstream secret-sentinel changes (RastermillError in vision-skip/apply tests due to missing media-services mocks) are also resolved.

Risk checklist

  • Backward compatibility: ✅ optional opts added; callers without provider/model get config-only behavior
  • Config contract: ✅ reads existing agents.defaults + cfg.models.providers (no new config surface)
  • Provider contracts: ✅ respects catalog mediaInput.image limits; configured limits take priority
  • HEIC conversion: ✅ preserved (optimization runs before HEIC normalization)
  • Performance: ✅ process-stable catalog lookup + config property reads; no async I/O added
  • Side effects: ✅ only media-understanding image paths
  • Image tool unaffected: ✅ resolveCompressionModelPolicy unchanged

@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 8, 2026
@clawsweeper

clawsweeper Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the contribution. This PR still needs the requested real-behavior proof, and the branch has been idle since that ask.

Close this stale, unmergeable branch: it has had no head update since July 18 and still lacks real after-fix OpenClaw request proof, despite the proof request having been visible for more than 14 days. Current main still has the underlying resize gap, so a rebased, proven replacement would remain welcome.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #101923
Summary: This PR attempts to fix the canonical oversized media-understanding image path reported in the linked issue, but has not established a viable proven landing path.

Members:

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

So I’m closing this for now to keep the review queue honest. Please reopen or open a fresh PR with real-behavior proof (a live run, logs, or a reproducible validation transcript) and it will be reviewed again.

Review details

Best possible solution:

Keep #101923 as the canonical bug report and accept a fresh, rebased PR only when it proves an oversized image through an actual OpenClaw request path.

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

Yes in source: current main sends normalized image bytes directly from both configured and explicit-model paths without invoking the existing optimizer; live provider confirmation was not performed in this review.

Is this the best way to solve the issue?

No for this stale branch: reuse of the canonical resolver is plausible, but the dirty branch needs a fresh rebase and real OpenClaw request proof before it is the best safe fix.

Security review:

Security review cleared: The described diff reuses in-repository policy and media helpers without adding dependencies, workflow changes, or new secret-handling paths.

AGENTS.md: found and applied where relevant.

What I checked:

  • Current configured path remains uncompressed: Current main reads an image attachment, performs HEIC-only normalization, then passes the buffer directly to the provider; there is no compression-policy resolution or optimization at this boundary. (src/media-understanding/runner.entries.ts:800, 95d7d95515b5)
  • Current explicit-model path remains uncompressed: Current main normalizes explicit image input and returns its bytes without invoking the web-media optimizer, confirming the linked bug remains a valid canonical target. (src/media-understanding/runtime.ts:261, 95d7d95515b5)
  • Existing canonical policy owner: The image tool already resolves configured, bundled-catalog, and runtime model image limits through its compression resolver, so reusing that policy is directionally sound. (src/agents/tools/image-tool.ts:573, 95d7d95515b5)
  • Stalled proof window: The branch head is fea09de from July 18; the visible status: 📣 needs proof label was applied that day, while the PR body still expressly excludes live provider execution and shows only optimizer output. (fea09deb8667)
  • Current-path provenance: Blame attributes the current media-understanding preparation and configured-provider boundary to the current-main commit, showing the active owner surface rather than an obsolete path. (src/media-understanding/runtime.ts:252, 22de30f99821)

Likely related people:

  • steipete: Current-main blame attributes both affected media-understanding boundaries to the recent media change. (role: recent area contributor; confidence: high; commits: 22de30f99821; files: src/media-understanding/runtime.ts, src/media-understanding/runner.entries.ts)
  • cpojer: Feature-history shortlog shows sustained contribution to the media-understanding and image-tool paths. (role: historical area contributor; confidence: medium; files: src/media-understanding/runner.entries.ts, src/media-understanding/runtime.ts, src/agents/tools/image-tool.ts)

Codex review notes: model internal, reasoning high; reviewed against 95d7d95515b5.

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 8, 2026
@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. labels Jul 8, 2026
@LiuwqGit
LiuwqGit force-pushed the feat/issue-101923-media-image-resize branch from f28014e to 3a127ae Compare July 8, 2026 02:35
@LiuwqGit

LiuwqGit commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

P1 fix: model-aware image compression policy

Addressed the ClawSweeper P1 finding: the media-understanding compression policy now queries the bundled static catalog for provider/model mediaInput.image limits (maxSidePx, maxPixels, maxBytes) — the same hard caps the image tool already enforces.

Changes

  • runner.entries.ts: resolveImageCompressionPolicyFromConfig now accepts optional provider/model/agentDir/workspaceDir opts. When provider+model are known, it queries resolveBundledStaticCatalogModel and merges catalog mediaInput.image limits into the policy alongside the existing agents.defaults config.
  • runtime.ts: Deleted the duplicate config-only copy; imports the shared exported helper from runner.entries.ts. Both call sites now pass provider/model through.

Why this matters

The previous config-only policy only set preferredSidePx from agents.defaults.imageMaxDimensionPx. Without hard maxSidePx/maxPixels caps, optimizeImageBufferForWebMedia may preserve originals when the input fits the preferred side — so provider-specific dimension caps (e.g., Anthropic's 2576px maxSidePx) could still be bypassed.

The image tool already resolves these limits via resolveCompressionModelPolicy → resolveBundledStaticCompressionModelPolicy → mediaInput.image. This fix makes media-understanding paths consistent.

Validation

  • ✅ oxlint: clean
  • ✅ check:test-types: pass
  • ✅ image.test.ts: 30/30 pass
  • ✅ runtime.test.ts: 21/21 pass
  • ✅ runner.entries.guards.test.ts: 12/12 pass

Repair branch

https://github.com/LiuwqGit/openclaw/tree/repair/pr-101940
Commit: 930f74cb36 fix(media-understanding): reuse model-aware image compression policy from catalog

@LiuwqGit
LiuwqGit force-pushed the feat/issue-101923-media-image-resize branch from 3a127ae to 11e295e Compare July 8, 2026 04:24
@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Jul 8, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 8, 2026
@LiuwqGit
LiuwqGit force-pushed the feat/issue-101923-media-image-resize branch from 7a6289a to f73d0a3 Compare July 8, 2026 07:39
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 8, 2026
@LiuwqGit
LiuwqGit force-pushed the feat/issue-101923-media-image-resize branch from f73d0a3 to 68ecc63 Compare July 8, 2026 08:14
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 9, 2026
LiuwqGit added 5 commits July 18, 2026 08:53
…to all image paths

Thread provider/model catalog mediaInput.image limits (maxSidePx, maxPixels,
maxBytes) into media-understanding compression policy so oversized images
respect the same hard caps the image tool already enforces. Covers all three
entry points:

- Channel-triggered media:// references (runProviderEntry)
- Explicit model calls (prepareImageDescriptionInput / describeImageFileWithModel)
- CLI infer image describe --model (runImageDescribe)

Change details:
- runner.entries.ts: export resolveImageCompressionPolicyFromConfig with optional
  provider/model opts; query bundled static catalog to merge mediaInput.image
  limits alongside agents.defaults config
- runtime.ts: delete duplicate config-only copy; import shared helper; pass
  provider/model through prepareImageDescriptionInput
- capability-cli.ts: pass activeModel.provider/model into prepareImageDescriptionInput
  so catalog limits are resolved before explicit-model fallback

Previously the config-only policy produced only a preferredSidePx from
agents.defaults.imageMaxDimensionPx. Without hard maxSidePx/maxPixels caps,
optimizeImageBufferForWebMedia could preserve originals, bypassing
provider-specific dimension caps (e.g., Anthropic 2576px maxSidePx).

Ref: openclaw#101940
Fixes: openclaw#101923
…ssion policy

Replace resolveBundledStaticCatalogModel-only lookup with resolveModelAsync
so the media-understanding image compression policy merges the same three
sources the image tool already enforces:

1. Configured model metadata (openclaw.json providers.*.models[].mediaInput.image)
   via resolveModelAsync with skipProviderRuntimeHooks.
2. Bundled static catalog limits as safety-net fallback.
3. Runtime-discovered limits (plugin hooks) when no hard dimension caps exist.

Previously the helper only queried the bundled static catalog, so custom
configured model limits and runtime-discovered metadata could be bypassed.

Refs: openclaw#101940
…mpression policy

Add config-based lookup (cfg.models.providers.*.models[].mediaInput.image) to
resolveImageCompressionPolicyFromConfig so custom/user-configured vision models
that are not in the bundled static catalog still get their hard dimension caps
applied before provider execution.

Configured limits take priority over catalog limits (matching the image tool's
mergeImageCompressionPolicies contract).

Also fix pre-existing test failures from upstream secret-sentinel changes that
broke media-services mocks in runner.vision-skip.test.ts and apply.test.ts.

Refs: openclaw#101940
- resolveImageCompressionPolicyFromConfig: drop dead agentDir opt, fix the
  alias-matching comment to reflect id-only lookup, and guard the model entry
  against pushing an empty ImageCompressionModelPolicy when neither configured
  nor catalog limits are present (spreading two undefined objects yields {}
  which is truthy and was leaking an empty {} into policy.models).
- prepareImageDescriptionInput: propagate workspaceDir so the explicit
  model-call path resolves catalog/config policy the same way as the channel
  media:// path.
- Drop the unused imageCompression param from normalizeImageDescriptionInput
  and its two call sites.
- Add focused unit tests covering policy merge precedence and guards.
- Add PNG_1X1 constant to vi.hoisted() for mock factories
- Mock readImageProbeFromHeader/readImageMetadataFromHeader to detect PNG
- Fix HEIC test: fileName sample.bin -> sample.jpg (toJpegFileName rename)
- Add test: prefers local image bytes over conflicting explicit MIME
- Add test: prefers fetched image MIME over conflicting explicit metadata
- Fix oxfmt formatting in runner.entries.ts and runner.entries.policy.test.ts
@LiuwqGit
LiuwqGit force-pushed the feat/issue-101923-media-image-resize branch from be5b38e to 4b3b2bf Compare July 18, 2026 00:58
@openclaw-barnacle openclaw-barnacle Bot removed the cli CLI command changes label Jul 18, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 18, 2026
…before-optimize order, add fileName to normalizer

- Export resolveCompressionModelPolicy from image-tool.ts so media-understanding can delegate
- Rewrite resolveImageCompressionPolicyFromConfig to async wrapper delegating to shared resolver
- Fix HEIC/HEIF normalize-before-optimize order in both runtime.ts and runner.entries.ts
- Add fileName to normalizeImageDescriptionInput return type so HEIC->JPG renames propagate
- Use normalizedMedia.fileName in runner.entries.ts optimizer call
- Add runner.entries.js and image-input-normalize.js mocks to runtime.test.ts
- Update HEIC test to verify normalization runs before optimization
- Rewrite policy tests to mock image-tool.js resolveCompressionModelPolicy
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Jul 18, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 18, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Aug 5, 2026
@LiuwqGit
LiuwqGit deleted the feat/issue-101923-media-image-resize branch September 22, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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