feat(bridge): normalize images to 2048px long edge before vision describe self-call - #10287
Merged
Merged
Conversation
Route the bridge's own fetchRemoteImageAsDataUri() output through normalizeDataUri() (long-edge cap 2048) before handing it to the vision model — matches the resize cap OpenAI/Anthropic already apply, cutting upload bytes/latency. Scoped to the bridge's self-fetched images only, never the user's raw passthrough payload (HR#20 opt-in principle).
Add a 100x4096 PNG case to image-normalize.test.ts alongside the existing width-dominant one, so normalizeImageBuffer's long-edge cap is proven on both axes.
…e-image-normalize
…e-image-normalize
Merged
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.
Summary
PR-B of the OCR/image-to-text migration series (plan:
_tasks/superpowers/plans/2026-08-13-ocr-image-to-text-migration.md; pattern migrated from freellmapi'simage-normalize.ts).open-sse/utils/imageNormalize.ts(new):normalizeImageBuffer/normalizeDataUri— downscale images to a 2048px long edge before they are sent to the vision model. sharp is loaded via dynamic import with a null fallback: if the native binary is unavailable, everything passes through untouched and nothing ever throws (normalizeDataUriis contractually no-throw). Nopackage.jsonchange — sharp^0.35.3is already a regular dependency.fetchRemoteImageAsDataUriinvisionBridgeHelpers.ts): every bridge-initiated remote image fetch is normalized before the describe/reroute self-call. User-inline data URIs never enter this path — passthrough payloads are untouched (verified in review:resolveImageAsDataUriandensureBase64ImagesForClaudeWireshort-circuitdata:URIs before the fetch helper).docs/security/GUARDRAILS.md): OpenAI/Anthropic downscale to ~2048 long edge server-side anyway; sending smaller images cuts tokens and latency with no quality loss for description.Validation (TDD)
image-normalize4/4 (incl. width- and height-dominant resize with real post-resize dimension asserts and garbage-bytes passthrough) ·vision-bridge-image-normalize2/2 (decodes the actual payload sent through the fetch DI spy and asserts ≤2048).guardrails/visionBridge29/29,repro-84303/3,preserve-on-failure-40122/2,vision-bridge-mode4/4,task-aware5/5,describe-cache3/3,cc-no-reroute8/8,env-override15/15,settings-schema2/2.vision-bridge-policy-reroute-6640: red on the loaded devbox and identically red on the pristine base via temp revert — the failure is the[resourcePressure] cgroup_ratio503 guard tripping under load, unrelated to this diff (controller re-verified in isolation). CI runners will exercise it uncontended.typecheck:core0 · prettier/eslint clean ·check:docs-all0.