Skip to content

fix(media-understanding): downscale configured image descriptions - #102002

Closed
harjothkhara wants to merge 7 commits into
openclaw:mainfrom
harjothkhara:codex/101923-media-understanding-resize
Closed

harjothkhara wants to merge 7 commits into
openclaw:mainfrom
harjothkhara:codex/101923-media-understanding-resize

Conversation

@harjothkhara

@harjothkhara harjothkhara commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #101923

What Problem This Solves

Fixes media-understanding image-description paths that could still reject or send oversized images even when an image resize policy was available from configured defaults or selected provider/model metadata.

Why This Change Was Made

Media-understanding now reuses the shared model-aware image compression resolver used by the image tool instead of maintaining a config-only policy path. Explicit image descriptions, CLI image describe fallback candidates, and configured provider-entry runs resolve compression before reading/fetching bytes, use a bounded pre-compression source cap, then enforce the final provider maxBytes after optimization.

This also keeps HEIC conversion and GIF preservation on the shared normalization path, and maps post-compression byte-cap failures back to the existing media-understanding maxBytes skip contract instead of reporting them as provider failures.

User Impact

Oversized photos sent through media-understanding image-description flows can be resized consistently with provider/model image limits and user image-quality defaults. Large inputs that still cannot be reduced to the provider cap remain non-fatal skipped attachments rather than failed provider attempts.

AI-assisted: yes. I reviewed the shared compression resolver, media-understanding explicit/provider-entry paths, CLI fallback candidate handoff, cap-ordering behavior, and focused test coverage in this PR. A sanitized local agent transcript was not included because this automation run did not have interactive approval to attach one.

Evidence

  • git diff --check passed.
  • node scripts/run-vitest.mjs src/media-understanding/image-input-normalize.test.ts src/media-understanding/runner.entries.image-cap.test.ts src/media-understanding/runtime.test.ts src/media-understanding/runner.vision-skip.test.ts src/cli/capability-cli.test.ts src/media/web-media.test.ts src/agents/tools/image-tool.test.ts passed: 4 Vitest shards, 321 tests total.
    • media: 75 tests
    • media-understanding: 46 tests
    • CLI: 106 tests
    • agents/image-tool: 94 tests
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main passed clean after the repair commits: no accepted/actionable findings; overall patch correct.
  • Branch rebased onto origin/main at b81666ca6a; current pushed head is da6f13cf83.

Not run: live Anthropic/OpenClaw image-description repro with a real oversized phone photo. Crabbox/Testbox proof was unavailable in this worktree because the Crabbox wrapper failed its basic binary sanity check, so this update proves the source/runtime/CLI fallback behavior and local review gate but does not yet provide live provider proof.

@harjothkhara
harjothkhara marked this pull request as ready for review July 8, 2026 03:48
@clawsweeper

clawsweeper Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 6:29 PM ET / 22:29 UTC.

ClawSweeper review

What this changes

The PR reuses the image tool’s model-aware compression policy so configured attachment descriptions, explicit image descriptions, and CLI image-description fallbacks can downscale oversized images before provider execution.

Merge readiness

⛔ Blocked until real behavior proof is added - 4 items remain

This PR remains necessary: current main still reads media-understanding images at the final provider byte cap and normalizes them without the image tool’s model-aware compression policy. The branch appears to address that gap across provider-entry, explicit runtime, and CLI fallback paths, and the prior local source-cap finding appears addressed, but it is currently dirty against main and still lacks after-fix real-provider behavior proof.

Priority: P1
Reviewed head: 84aa64d788fc2b63939204bdb26475fb914bbf2c

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is a focused reuse of an existing compression contract, but the missing real behavior proof is a merge gate and the branch needs a current-main rebase.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR body explicitly says no after-fix live oversized-image provider or OpenClaw image-description run is attached; tests and autoreview are supplemental, not real behavior proof. Add redacted terminal output, logs, or a recording after rebasing, and update the PR body; if review does not refresh, ask a maintainer to comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body explicitly says no after-fix live oversized-image provider or OpenClaw image-description run is attached; tests and autoreview are supplemental, not real behavior proof. Add redacted terminal output, logs, or a recording after rebasing, and update the PR body; if review does not refresh, ask a maintainer to comment @clawsweeper re-review.
Evidence reviewed 5 items Current-main gap: Current main prepares explicit image descriptions by reading the image and passing it directly to normalization; it does not resolve or pass a model-aware compression policy before the final image byte cap is applied.
Current provider-entry behavior: Current main fetches configured image attachments with maxBytes and calls normalization with no image compression policy, so this path does not share the image tool’s provider/model-aware resize behavior.
Existing shared-policy precedent: The image tool already resolves compression limits from model candidates, configured metadata, static catalog information, and runtime augmentation; the PR extracts that behavior for reuse rather than creating a second policy implementation.
Findings None None.
Security None None.

How this fits together

Media-understanding receives image attachments from channel workflows and file/CLI calls, obtains their bytes, normalizes formats, then sends them to the selected vision provider. This change inserts model-aware compression before that provider request while retaining the final provider byte limit and skipped-attachment behavior.

flowchart LR
  A[Channel attachment or file input] --> B[Media-understanding entry]
  B --> C[Selected provider and model]
  C --> D[Shared image compression policy]
  D --> E[Bounded source read and normalization]
  E --> F[Final provider byte-limit check]
  F --> G[Vision provider request or skipped attachment]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body explicitly says no after-fix live oversized-image provider or OpenClaw image-description run is attached; tests and autoreview are supplemental, not real behavior proof. Add redacted terminal output, logs, or a recording after rebasing, and update the PR body; if review does not refresh, ask a maintainer to comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The PR is dirty against current main; it must be rebased and re-reviewed on the resulting head before merge.
  • Resolve merge risk (P1) - This changes attachment and CLI handling for existing image-description workflows. A real oversized-image provider run is needed to show that compression succeeds and that images still exceeding the final cap remain skipped rather than surfacing as provider failures.
  • Complete next step (P2) - The remaining blockers are contributor-supplied real behavior proof and a rebase of the exact merge head, neither of which an automated repair lane can safely substitute.
Agent review details

Security

None.

PR surface

Source +311, Tests +439. Total +750 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 9 484 173 +311
Tests 6 441 2 +439
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 925 175 +750

Review metrics

None.

Stored data model

Persistent data-model change detected: persistent cache schema: src/media-understanding/runner.vision-skip.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Rebase and prove the changed path (recommended)
    Rebase the branch onto current main, resolve the merge conflict, and add redacted terminal or runtime evidence showing an oversized valid image is reduced before a successful provider description while an irreducible image remains a non-fatal skip.
  2. Pause for a narrower successor
    If the rebase substantially changes the shared image-policy boundary, pause this branch and retain the linked issue as the canonical report while a narrower current-main fix is prepared.

Technical review

Best possible solution:

Rebase onto current main, preserve the shared resolver and final-cap skip contract, then attach redacted real-provider proof using an oversized valid image through at least one affected media-understanding path.

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

Yes from source: current main has a clear path where media-understanding reads images at the final cap and normalizes them without the image tool’s model-aware policy. A live current-main provider run was not performed in this read-only review.

Is this the best way to solve the issue?

Yes in principle: reusing the established shared compression resolver is preferable to maintaining a separate media-understanding policy, provided the rebased branch preserves the final-cap skip contract and supplies real-provider proof.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0073862e232b.

Labels

Label justifications:

  • P1: Oversized inbound images can prevent the normal image-understanding channel workflow from reaching the vision provider.
  • merge-risk: 🚨 compatibility: The PR newly applies existing image-quality and model-metadata policy to media-understanding and CLI paths that previously sent original inputs.
  • merge-risk: 🚨 availability: The altered fetch, normalization, and byte-cap ordering determines whether image-description requests proceed, skip safely, or fail.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body explicitly says no after-fix live oversized-image provider or OpenClaw image-description run is attached; tests and autoreview are supplemental, not real behavior proof. Add redacted terminal output, logs, or a recording after rebasing, and update the PR body; if review does not refresh, ask a maintainer to comment @clawsweeper re-review.

Evidence

What I checked:

  • Current-main gap: Current main prepares explicit image descriptions by reading the image and passing it directly to normalization; it does not resolve or pass a model-aware compression policy before the final image byte cap is applied. (src/media-understanding/runtime.ts:253, 0073862e232b)
  • Current provider-entry behavior: Current main fetches configured image attachments with maxBytes and calls normalization with no image compression policy, so this path does not share the image tool’s provider/model-aware resize behavior. (src/media-understanding/runner.entries.ts:837, 0073862e232b)
  • Existing shared-policy precedent: The image tool already resolves compression limits from model candidates, configured metadata, static catalog information, and runtime augmentation; the PR extracts that behavior for reuse rather than creating a second policy implementation. (src/agents/tools/image-tool.ts:403, 4c210e22fa97)
  • Prior blocker addressed at current PR head: The latest branch introduces a 50 MB pre-compression source ceiling and passes it to both configured provider-entry and explicit image-description reads, addressing the prior repeated finding that local source reads were not capped before compression. (src/media-understanding/image-compression-policy.ts:8, 84aa64d788fc)
  • Proof and merge state: The contributor explicitly states that no live oversized-image provider run is attached; the current PR metadata also reports a dirty merge state against main, so the exact merge result still needs refresh before landing. (84aa64d788fc)

Likely related people:

  • steipete: Merged the earlier model-aware image-compression work that established the resolver and configuration contract this PR reuses. (role: introduced shared compression behavior; confidence: high; commits: 4c210e22fa97; files: src/agents/tools/image-tool.ts, src/media/web-media.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main and resolve the dirty merge state.
  • Attach redacted real-provider evidence with a valid oversized image showing the successful after-fix description and safe final-cap behavior.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (7 earlier review cycles)
  • reviewed 2026-07-08T03:57:22.849Z sha 59b061c85490a0d471cee0de153362d441e7354b :: needs real behavior proof before merge. :: [P1] Reuse the model-aware image compression policy
  • reviewed 2026-07-08T19:06:56.227Z sha da6f13cf839c6232b4463c1529529f6492532e0c :: needs real behavior proof before merge. :: [P2] Apply the source cap to local image reads
  • reviewed 2026-07-08T19:14:52.323Z sha da6f13cf839c6232b4463c1529529f6492532e0c :: needs real behavior proof before merge. :: [P1] Break the agent/media import cycle | [P2] Apply the source cap to local image reads | [P2] Bind the mocked getBuffer before asserting
  • reviewed 2026-07-09T02:58:21.025Z sha bf8cbbe38c232940e09f8a86979a70e374db2fed :: needs real behavior proof before merge. :: [P2] Cap local image reads before compression
  • reviewed 2026-07-09T03:34:05.131Z sha 11cf71a5137860c503926418f1718e1ac1cf61d1 :: needs real behavior proof before merge. :: [P2] Cap local image reads before compression
  • reviewed 2026-07-12T21:54:23.768Z sha 8a09f8e :: needs real behavior proof before merge. :: [P2] Cap local image reads before compression
  • reviewed 2026-07-12T22:04:27.156Z sha 8a09f8e :: needs real behavior proof before merge. :: [P2] Cap local image reads before compression

@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. labels Jul 8, 2026
@harjothkhara
harjothkhara force-pushed the codex/101923-media-understanding-resize branch from 59b061c to da6f13c Compare July 8, 2026 18:59
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes agents Agent runtime and tooling size: XL and removed size: S labels Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated this PR at da6f13cf83 to reuse the shared model-aware image compression policy, resolve compression before explicit/provider-entry image reads, cover CLI fallback model candidates, preserve HEIC/GIF behavior, and keep post-compression maxBytes failures as skipped attachments instead of provider failures.

Evidence is now in the PR body: git diff --check, focused Vitest coverage across media/media-understanding/CLI/agents image-tool paths (321 tests), and clean autoreview. Known remaining gap: live provider proof is still not attached because Crabbox/Testbox was unavailable in this worktree due the wrapper binary sanity check failure.

@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.

@harjothkhara
harjothkhara force-pushed the codex/101923-media-understanding-resize branch from da6f13c to bf8cbbe Compare July 9, 2026 02:49
harjothkhara and others added 6 commits July 12, 2026 14:41
…x test lint

Extract ImageCompressionModelCandidate into a leaf .types module so
media-understanding/runtime-types no longer imports the agents model
runtime through agents/image-compression-policy. On current main that
back-edge closed a madge import cycle (check:architecture). Also hoist
the getBuffer mock in the image-cap test to satisfy
typescript(unbound-method).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
After rebasing onto current main, apply.test.ts failed: its synthetic image
buffers now flow through the PR's new model-aware compression path, and the
real optimizer rejects non-image bytes, dropping the attachment. These
integration tests cover apply/HEIC/workspace routing, not the compression
resolver (unit-tested in image-compression-policy and image-input-normalize
tests), so mock the resolver to the pre-compression passthrough. No runtime
change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@harjothkhara
harjothkhara force-pushed the codex/101923-media-understanding-resize branch from 11cf71a to 8a09f8e Compare July 12, 2026 21:48
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 12, 2026
@clawsweeper

clawsweeper Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

@harjothkhara thanks for the PR. ClawSweeper is still waiting on real behavior proof before this can move forward.

Useful proof can be a screenshot, short video, terminal output, copied live output, linked artifact, or redacted logs that show the changed behavior after the fix. Please redact private tokens, phone numbers, private endpoints, customer data, and anything else sensitive.

Once proof is added to the PR body or a comment, ClawSweeper or a maintainer can re-check it.

@harjothkhara

Copy link
Copy Markdown
Contributor Author

Closing this branch as stale. #101923 stays open — I am not claiming the underlying behavior is fixed.

What changed underneath it: main has since built its own image-compression-policy machinery inside src/agents/tools/image-tool.ts (imageCompressionPolicyHasDimensionLimit, mergeImageCompressionPolicies, resolveBundledStaticCompressionModelPolicy, plus the plugin capability-provider layer), which is a different shape from this PR's resolveModelAwareImageCompressionPolicy. src/cli/capability-cli.ts was also rewritten — the conflict region there spans about 2,044 lines.

So this is a re-implementation against a restructured area, not a rebase, and a fresh 2-3 file PR would be smaller and easier to review than salvaging this one. Leaving #101923 open for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes 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: XL 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