feat(core): normalize tool and attachment images at settlement#37141
Merged
Conversation
e9b142d to
e981876
Compare
Image resizing previously ran only inside the read tool, so plugin, MCP, and codemode tools could persist unbounded inline base64 images that grow every provider request body (see #36552). - ToolRegistry.settleTool now normalizes image file content generically: a missing resizer keeps the original, an unresizable image is dropped and replaced with an omission note, mirroring V1 processor behavior. - SessionV2.prompt normalizes image attachments at admission, resolving the Location-scoped Image service lazily so text-only prompts do not boot location services. - read keeps its internal normalize call to bound the image persisted in its structured output.
Settlement normalization in ToolRegistry is now the single resize call site. read no longer depends on Image; its structured output is slimmed via toStructuredOutput (Schema.toEncoded) so the original unresized base64 is never persisted in the message row. Unresizable images read by the tool are now dropped with an omission note at settlement instead of failing the tool, consistent with every other tool.
Tool progress content is published durably and lowered to providers when a call errors mid-progress, so it now runs through the same settlement image normalization as final output. Dropped images are reported in per-reason notes (could not be decoded vs. could not be resized) instead of one misleading resize message, and the data-URI match accepts RFC 2397 parameters between the mime and base64 marker.
bbc68e0 to
b3f1500
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Image resizing in V2 ran only inside the
readtool. Any other tool returning media (plugin tools, MCP, codemode) persisted unresized inline base64 that is re-sent in every provider request body, and user prompt attachments were never resized at all. Unbounded inline media is how sessions grow past provider/gateway body limits (#36552, related #35013).Changes
ToolRegistry.settleToolnormalizes image file content generically at the settlement boundary — the singleImage.normalizecall site for tool output. It runs once per tool call, beforeToolOutputStore.boundand before the message row is persisted; per-request lowering replays the persisted content, so the resize never re-runs per request. Semantics mirror the V1 processor:[N images omitted: could not be decoded.]/[N images omitted: could not be resized below the image size limit.]Tool.Progresspublish — progress is persisted and lowered to providers when a call errors mid-progress, so it needs the same bounding.;base64marker.readno longer callsImage.normalizeat all. Its structured output is slimmed viatoStructuredOutput(Schema.toEncoded) so the original unresized base64 is never persisted twice — the image reaches the model through content items only. An unresizable image read now drops with the omission note instead of failing the tool, consistent with every other tool.SessionV2.promptnormalizes image attachments at admission (V1 prompt-time parity). The Location-scopedImageservice is resolved lazily so text-only prompt admission does not boot location services; an unresizable attachment fails the prompt withAttachmentError.Known limitations
structuredContentis opaque JSON passed through verbatim; base64 embedded inside it is not normalized.Tests
Imagepassthrough mock wired into suites that buildToolRegistry.nodein isolation.packages/core: 1308 pass / 0 fail; typecheck clean.