Repository navigation
fix(media): decouple image decode and output pixel budgets - #286
convyusboy merged 5 commits into
Conversation
Rastermill's shared image processor used the same pixel budget for input decode and final output, so any source image above 25 megapixels was rejected outright before any resize could run. Split the two budgets so a large source can be decoded and then downscaled instead. Also: graceful handling (instead of a raw crash) for a source still too large even under the raised ceiling, in both the image and image_generate tools; restored the managed-image-attachments gateway path's original fail-fast behavior for oversized sources now that the shared decode ceiling is higher; and a targeted info log for the oversized-source-now-downscaling case. Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
cubic analysis
All reported issues were addressed across 8 files
Linked issue analysis
| Status | Acceptance criteria | Notes |
|---|---|---|
| ✅ | Downscale images above the pixel limit | The decode cap is raised to 100M while the final-image cap stays at 25M, allowing the existing resize ladders to process these sources. |
| Preserve aspect ratio during resizing | The PR says existing resize ladders handle downscaling, but the diff does not show or test aspect-ratio preservation. | |
| ✅ | Log a warning when an oversized image is resized | web-media logs an informational message when source dimensions exceed the output pixel cap before image processing. |
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
…yfleet-openclaw-fleet-xv-oversized-drawing-sheet-images
|
RE the linked-issue checklist in review #5502649831 (addressed in 82b9fcce2b6): aspect-ratio preservation during resize is guaranteed by Rastermill itself, not something this PR's code needs to implement. None of the resize calls here (or anywhere else in the touched files) pass |
There was a problem hiding this comment.
Code Review Summary
Approve covers commit a6340143 specifically.
Verdict: APPROVED
The PR cleanly decouples image decode and output pixel budgets, resolving Sentry fleet crashes where high-resolution drawing sheets (e.g. 9072x6480 = ~58.8 MP) failed upfront before downscaling could execute.
Best-Fix Analysis
- Root Cause Resolution: Rastermill previously validated both decode and output budgets against the single
MAX_IMAGE_INPUT_PIXELS(25 MP) limit. By introducingMAX_IMAGE_DECODE_PIXELS(100 MP) forlimits.inputPixelswhile maintainingMAX_IMAGE_INPUT_PIXELS(25 MP) forlimits.outputPixels, source images up to 100 MP can be opened and downscaled to fit model and SDK limits. - Contract Preservation: The public SDK constant
MAX_IMAGE_INPUT_PIXELSremains 25 MP, preserving downstream model payload guarantees and API compatibility. - Fail-Fast Guards on Non-Resize Paths: Non-resize pathways (
convertHeicToJpeginsrc/media/input-files.ts:346and outbound attachments insrc/gateway/managed-image-attachments.ts:940) now perform cheap header pre-checks againstMAX_IMAGE_INPUT_PIXELS, avoiding expensive in-process 100 MP decodes for images that would ultimately be rejected on output budgets. - Sanitized Tool Error Handling: Both
src/agents/tools/image-tool.ts:1040andsrc/agents/tools/image-generate-tool.ts:650handleisImageTooLargeToDecodeErrorgracefully with actionable guidance, replacing raw base64 data URLs with a generic reference placeholder to prevent bloating prompts and logs. - Reference Image Parity:
src/agents/tools/image-generate-tool.ts:625now routes data URL references throughoptimizeImageBufferForWebMedia, closing a prior gap where data URLs bypassed downscaling.
Evidence Map
- Changed Surfaces:
src/media/image-ops.ts:57: IntroducedMAX_IMAGE_DECODE_PIXELS(100 MP) andisImageTooLargeToDecodeError.src/media/web-media.ts:777: Added info log on downscaling oversized images.src/gateway/managed-image-attachments.ts:940: Pre-decode pixel check for managed outgoing attachments.src/media/input-files.ts:346: Pre-decode pixel check for HEIC/HEIF normalization.src/agents/tools/image-tool.ts:1040: Graceful error response and data URL sanitization.src/agents/tools/image-generate-tool.ts:625: Data URL optimization pipeline and error handling.
- Sibling Surfaces:
src/agents/utils/image-resize.ts: Benefits from 100 MP decode headroom during LLM base64 payload resizing.src/cli/capability-cli.ts: Verified as debug CLI surface.
- CI & Local Verification:
- Remote CI: 30/30 check suites passing on commit
a6340143. - Local Vitest runs verified in worktree:
src/media/image-ops.rastermill-adapter.test.ts(passed)src/media/input-files.heic-pixel-limit.test.ts(passed)src/media/web-media.test.ts(passed)src/gateway/managed-image-attachments.test.ts(passed)src/agents/tools/image-generate-tool.test.ts(passed)src/agents/tools/image-tool.test.ts(too large to decode cases passed)src/media-understanding/*.test.ts,src/media/input-files.fetch-guard.test.ts(passed)
- Remote CI: 30/30 check suites passing on commit
- image_generate's data: URL reference path had no pixel/size guard at all (unlike the image tool's equivalent path); route it through the same optimization pipeline so an oversized reference gets downscaled instead of reaching the provider untouched. - Never echo a data: URL's full base64 payload back into a tool message/details field for the "too large to decode" case, in both the image and image_generate tools. - managed-image-attachments.ts's oversized-source rejection now names the actual pixel limit instead of reusing a message that can claim the wrong constraint (width/height) was the cause. - The oversized-source log in web-media.ts now fires after a successful resize, not before, so a decode/encode failure can't be misreported as a successful downscale. - HEIC conversion in input-files.ts had no pixel guard at all before a full in-process decode; added the same cheap header check as the other non-resize encode paths in this change, confirmed necessary by reading Rastermill's own resize/output-budget source directly (its output cap is still correctly enforced for pass-through encodes, but only after paying for a decode that a header check can skip). Co-Authored-By: Claude Opus 5 <[email protected]>
Removing decodeDataUrl's raw shape from the media union (since every branch now produces a WebMediaResult via optimizeImageBufferForWebMedia) left a dead 'mimeType' in media branch that no longer type-checked. Simplify to media.contentType directly. Co-Authored-By: Claude Opus 5 <[email protected]>
input-files.ts's HEIC conversion now calls readImageMetadataFromHeader before convertHeicToJpeg; these three suites replace media-services.js with a partial mock that was missing it, so the real (unmocked) input-files.ts code threw calling an undefined export. Co-Authored-By: Claude Opus 5 <[email protected]>
a634014 to
b1d998e
Compare
Cut the fork release that ships the six commits on boon since v2026.6.34-boon.6: - #286: decouple Rastermill's image decode and output pixel budgets so a source image above 25 megapixels downscales instead of being rejected outright; plus HEIC/data-URL pixel-guard and error-detail fixes. - #283 (ENG-21233): classify a caller's external timeout abort as a clean interruption instead of leaking DOMException's TimeoutError code as "Turn budget exceeded | 23" on agent_end. - #284 (ENG-21229): re-derive the memory-flush write guard's allowed path at execute time so a flush crossing midnight no longer rejects the correct current-date path. - #282 (ENG-21225): web_fetch 403/404/429 no longer page Sentry as unhandled exceptions; 429 now retries with bounded backoff honoring Retry-After. - #285: remove a duplicate simple-git/proxy-addr/source-map-js overrides block that crashed pnpm store path on every PR against boon. - #275: bump music-metadata 11.12.3 -> 11.16.0. Bump root package.json and npm-shrinkwrap.json, all 136 plugin manifests, and the version/peer floor in every extension npm-shrinkwrap.json via pnpm release:prep. The npm-shrinkwrap generator can't regenerate cleanly on this fork (pre-existing, unrelated @sentry/node nested @opentelemetry/resources / sdk-trace-base registry-resolution drift, verified present on unmodified origin boon); hand-patched the affected shrinkwrap version/peer-floor fields instead, verified against test/package-manager-config.test.ts (12/12 passing). Add the 2026.6.34-boon.7 CHANGELOG.md section and the generated extensions/matrix/CHANGELOG.md entry. No config schema, plugin-SDK surface, or plugin source/dependency change in slack/msteams/diagnostics-prometheus; this is a gateway-only roll. Co-authored-by: Claude Sonnet 5 <[email protected]>
What Problem This Solves
Vision tool calls crash when a customer uploads a high-resolution construction/architectural drawing sheet. Sentry fleet telemetry showed 16 occurrences across 3 customer accounts with:
This is not an Anthropic API error — it never reaches the model. Rastermill's shared image processor (
createImageProcessor()insrc/media/image-ops.ts) used the same pixel value for both its input-decode budget and its final-output budget. Rastermill validates the input budget from the image header before any decode or resize ever runs, so a source image above 25 megapixels was rejected outright — there was no code path that could ever downscale it.Why This Change Was Made
Split the single shared pixel budget into two: a raised input/decode cap (
MAX_IMAGE_DECODE_PIXELS, 100M) so a large source can actually be opened, and the existing output cap (MAX_IMAGE_INPUT_PIXELS, 25M, unchanged value/name — it's re-exported through the plugin SDK) that still bounds the final image everywhere. This lets the resize/compression ladders that already exist inweb-media.tsandtool-images.tsdo their job instead of being short-circuited before they ever run.A review pass surfaced two follow-on gaps from the initial fix and both are included here:
image_generate's reference-image loader shares the exact same code path and had no handling for a still-too-large source — it now degrades gracefully the same way theimagetool does.managed-image-attachments.ts(an outbound gateway path that never needs to accept drawing-sheet-sized input) — it now rejects oversized sources before paying for a full in-process decode, matching its pre-existing behavior.A targeted, non-verbose info log was added for the specific case of an oversized source now succeeding instead of crashing (narrower than logging on every routine resize, which would add log noise to high-volume channel traffic).
User Impact
imagetool or as animage_generatereference image now gets it downscaled and analyzed instead of a hard crash.MAX_IMAGE_INPUT_PIXELSoutput cap is unchanged).Evidence
rastermill's own source (node_modules/rastermill/dist/index.js,assertHeaderPixelBudget/validatePixelBudget): the input-pixel check runs from header metadata before any decode or resize./code-review highrun against the full diff; all findings addressed (sibling-path gap, resource-cost scoping, a factually incorrect error message, logging noise, comment-length convention).src/media/image-ops.rastermill-adapter.test.ts+src/media/web-media.test.ts: 84/84src/agents/tools/image-tool.test.ts: 188/190 (2 pre-existing, unrelated flaky tests excluded — confirmed to hang identically on unmodified code via git-stash isolation)src/agents/tools/image-generate-tool.test.ts: 48/48 (includes a new regression test)src/gateway/managed-image-attachments.test.ts: 144/144Known gap:
tsgotypecheck and a Testbox/Crabbox run were not completed — this worktree has no localnode_modules/.bin(sotsgo/oxlintbinaries aren't present), and neither Crabbox provider CLI (az,blacksmith) is installed on this machine. A manual type-correctness review was done in place oftsgo. Recommend a Testbox pass before merge.🤖 Generated with Claude Code
Summary by cubic
Fixes vision tool crashes on oversized construction drawing uploads by giving Rastermill separate decode and output pixel budgets. Previously both shared the same 25MP limit, so a source above that (e.g. 9072x6480) was rejected before any resize could run—the tool crashed instead of downscaling. The decode budget is now 100MP, while the 25MP output cap on final images consumers receive is unchanged.
Also converts the previously-unhandled error into a clear tool message for sources still too large even under the raised ceiling.
Follow-on changes
imageandimage_generatetool paths, never echoingdata:URL payloads in error messages.image_generatedata:URL references through the same downscale pipeline as other references.input-files.ts, plus the matching mock updates in affected test suites.contentTypenow that everyimage_generatereference branch produces aWebMediaResult.Written for commit b1d998e. Summary will update on new commits.