← Back to Pull requests

Estimate the uploaded image of /v1/images/edits requests #4054

Closed
unknown closed this pull request without merging on Nov 11, 2026 19:23 UTC
View on GitHub
unknown unknown commented on Nov 06, 2026 17:16 UTC
Author

What type of PR is this?
/kind feature

What this PR does / why we need it:

The images-edits parser discarded the uploaded image file part, so the request's image-to-image conditioning input carried zero estimated tokens: an edit with a 4K input image weighed the same as one with a thumbnail, and only the prompt text reached the in-flight token load.

The parser now captures the image part as UploadedMedia — byte size, leading bytes for header sniffing, content type, and a content hash — without retaining the body, which is forwarded byte-for-byte. The estimate backend decodes the image's dimensions from the retained head (image.DecodeConfig; PNG/JPEG/GIF already registered for the chat path) and appends the same image multimodal feature chat image_url parts produce: wh/factor placeholder tokens behind the conditioning text, falling back to the default resolution for undecodable headers. Requests without an image part (/v1/images/generations shares the typed body) estimate the text alone, exactly as before.

Note on overlap with #3964: this PR introduces UploadedMedia, parseMultipartForm, readUploadedMedia, and appendMMAssetHash verbatim from the transcriptions PR, because it is based on main rather than stacked. Whichever PR merges first, the other's overlapping hunks become no-ops on rebase.

Which issue(s) this PR fixes:

Fixes #4053

Release note _(write NONE if no user-facing change)_:
``release-note
The token-producer estimates the input cost of /v1/images/edits requests from the uploaded image: pixel dimensions decoded from the image header produce placeholder tokens (w
h/1024 by default, configurable through the existing estimate.image config), falling back to the default resolution for undecodable headers. The uploaded body is not retained and is forwarded unchanged; /v1/images/generations requests are unaffected.
`

Test plan:

  • An edits request's image part is captured: size, bounded head, content type, and a hash of the full stream

  • A file part under any other name (mask) is ignored, and a request without an image part leaves the captured media at its zero value

  • A decodable PNG head yields wh/factor placeholder tokens as an image feature behind the conditioning text, counted in the request's tokens with the content hash

  • An undecodable head falls back to the default resolution, so the request still carries image weight

  • A request without an image part (generations) estimates the text alone and reports no features, unchanged from before
  • make presubmit passes (fmt, lint, security, govulncheck, boilerplate, telemetry, latest-tags). verify-review-playbook fails identically on clean main (unrouted pkg/common/grpc/ files, pre-existing); go test ./pkg/epp/...` is green.

    Diff: 352 lines (+264 / -88) across 4 files Reviewer: ahg-g Review duration: 7326m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 352 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.351
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4054"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.5% (MEDIUM) · Higher = larger blast radius
    42.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.8% · Safe to merge
    16.8%