Skip to content

fix(media): decouple image decode and output pixel budgets - #286

Merged
convyusboy merged 5 commits into
boonfrom
ridho/eng-21232-sentryfleet-openclaw-fleet-xv-oversized-drawing-sheet-images
Oct 13, 2026
Merged

convyusboy merged 5 commits into
boonfrom
ridho/eng-21232-sentryfleet-openclaw-fleet-xv-oversized-drawing-sheet-images

Conversation

@convyusboy

@convyusboy convyusboy commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

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:

Error: Image dimensions exceed the 25,000,000 pixel input limit: 9072x6480 (58786560 pixels)

This is not an Anthropic API error — it never reaches the model. Rastermill's shared image processor (createImageProcessor() in src/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 in web-media.ts and tool-images.ts do 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 the image tool does.
  • Raising the shared decode budget also widened the resource cost for 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

  • A customer attaching a large drawing-sheet scan (up to 100 megapixels) to the image tool or as an image_generate reference image now gets it downscaled and analyzed instead of a hard crash.
  • A source still too large even under the raised ceiling gets a clear, actionable tool message instead of an unhandled error.
  • No change to the final image size/quality any consumer receives (MAX_IMAGE_INPUT_PIXELS output cap is unchanged).
  • No behavior change for the gateway's outbound image-attachment path (restored to its original fail-fast behavior for oversized sources).

Evidence

  • Root cause traced directly in 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 high run against the full diff; all findings addressed (sibling-path gap, resource-cost scoping, a factually incorrect error message, logging noise, comment-length convention).
  • Tests, all passing after a clean rebase onto the current base branch tip:
    • src/media/image-ops.rastermill-adapter.test.ts + src/media/web-media.test.ts: 84/84
    • src/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/144

Known gap: tsgo typecheck and a Testbox/Crabbox run were not completed — this worktree has no local node_modules/.bin (so tsgo/oxlint binaries aren't present), and neither Crabbox provider CLI (az, blacksmith) is installed on this machine. A manual type-correctness review was done in place of tsgo. 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

  • Adds graceful oversized-source handling to both image and image_generate tool paths, never echoing data: URL payloads in error messages.
  • Routes image_generate data: URL references through the same downscale pipeline as other references.
  • Restores the gateway's outbound image-attachment path to rejecting oversized sources before decode.
  • Adds a pre-decode header pixel check to HEIC/HEIF conversion in input-files.ts, plus the matching mock updates in affected test suites.
  • Simplifies the media type to contentType now that every image_generate reference branch produces a WebMediaResult.
  • Logs an info message only after successfully downscaling an oversized source.

Written for commit b1d998e. Summary will update on new commits.

View guided diff Turn on auto-fix

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]>
@convyusboy
convyusboy requested a review from a team October 13, 2026 11:08

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic analysis

All reported issues were addressed across 8 files

Linked issue analysis

Linked issue: ENG-21232: [Sentry][Fleet] OPENCLAW-FLEET-XV: Oversized drawing sheet images (>25M pixels) fail model vision input limit without downscaling

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

Comment thread src/agents/tools/image-generate-tool.ts Resolved
Comment thread src/media/image-ops.ts Resolved
Comment thread src/media/web-media.ts Resolved
Comment thread src/agents/tools/image-tool.ts Resolved
…yfleet-openclaw-fleet-xv-oversized-drawing-sheet-images
@convyusboy

Copy link
Copy Markdown
Collaborator Author

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 fit: "cover" or fit: "fill"; with no fit specified, Rastermill defaults to fit: "inside" (confirmed in its source: normalizeResizeOptions, const fit = resize.fit ?? "inside";), which scales to fit within the target box without cropping or stretching. This is an existing, already-relied-upon dependency contract, not new behavior from this PR — no test added for it here since it would just be testing Rastermill's own resize mode, not our code.

@boon-hermes-bot boon-hermes-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 introducing MAX_IMAGE_DECODE_PIXELS (100 MP) for limits.inputPixels while maintaining MAX_IMAGE_INPUT_PIXELS (25 MP) for limits.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_PIXELS remains 25 MP, preserving downstream model payload guarantees and API compatibility.
  • Fail-Fast Guards on Non-Resize Paths: Non-resize pathways (convertHeicToJpeg in src/media/input-files.ts:346 and outbound attachments in src/gateway/managed-image-attachments.ts:940) now perform cheap header pre-checks against MAX_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:1040 and src/agents/tools/image-generate-tool.ts:650 handle isImageTooLargeToDecodeError gracefully 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:625 now routes data URL references through optimizeImageBufferForWebMedia, closing a prior gap where data URLs bypassed downscaling.

Evidence Map

  • Changed Surfaces:
    • src/media/image-ops.ts:57: Introduced MAX_IMAGE_DECODE_PIXELS (100 MP) and isImageTooLargeToDecodeError.
    • 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)

convyusboy and others added 3 commits October 13, 2026 19:54
- 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]>
@convyusboy
convyusboy force-pushed the ridho/eng-21232-sentryfleet-openclaw-fleet-xv-oversized-drawing-sheet-images branch from a634014 to b1d998e Compare October 13, 2026 12:57
@convyusboy
convyusboy merged commit c19d1c9 into boon Oct 13, 2026
144 checks passed
@convyusboy
convyusboy deleted the ridho/eng-21232-sentryfleet-openclaw-fleet-xv-oversized-drawing-sheet-images branch October 13, 2026 13:50
convyusboy added a commit that referenced this pull request Oct 13, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants