Repository navigation
Studio: convert pasted images when tools are turned on - #10094
Conversation
|
Confirmed the gap in studio/backend/routes/inference.py, where |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
https://github.com/unslothai/unsloth/blob/ea36bb7586dad817944440f2069fcd0c0bc45df6/studio/backend/routes/inference.py#L27055
Preserve the requested image detail during conversion
When a data-URL image specifies detail: "low", "high", or "original", replacing the entire image_url object discards that setting. Because this commit now runs the normalizer on the tools/response-format passthrough path, requests that previously forwarded an explicit detail level silently fall back to llama-server's default, potentially changing image token usage or visual accuracy. Rewrite only the url member while retaining the other fields.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Before/after on a live Studio, plus a note that changes how I'd describe the impact. The condition that decides thisllama.cpp #ifdef MTMD_VIDEO
// stb_image does not support webp; decode it with ffmpeg as a single frame
if (!result && is_webp_file(buf, len)) {
result = decode_webp_with_ffmpeg(ctx, buf, len, placeholder, opt.video_params);Unsloth does not install Live before/after,
|
| fact | BEFORE 2da377132 |
AFTER 22779f4f5 |
|---|---|---|
control_tools_off_http_status |
200 | 200 |
control_tools_off_reads_word |
true | true |
tools_on_http_status |
400 | 200 |
tools_on_reads_word |
false | true |
tools_on_finish_reason |
— | length |
BEFORE returns llama-server's own refusal:
{"error":{"code":400,"message":"Failed to load image or audio file","type":"invalid_request_error"}}The control is the part that makes this comparable: tools-off already went through _openai_messages_for_gguf_chat, which converted to PNG even on merge base, so each side proves on its own server that images decode and only the WebP-with-tools turn fails.
BEFORE: a red /chat/completions row carrying the 400, above a green tools-off row answering UNSLOTH. AFTER: both rows green.
With ffmpeg on PATH
Same two installs, unmodified PATH: tools_on_http_status 200 on both sides, both read the word. A null result, recorded rather than dropped. So the user-visible failure needs ffmpeg to be missing; what the PR always changes is that the two endpoints stop disagreeing, and the WebP path no longer depends on an ffmpeg subprocess.
Request-body A/B on Actions
Building the real passthrough body for a WebP + tools-on turn, identical workflow and probe, only the implementation differs:
- merge base — run 33513282080:
llama_server_receives_format: WEBP,stb_image_can_decode: false— fails at the intended assertion - head — run 33513287144:
PNG,stb_image_can_decode: true,detail_forwarded: "high"— passes
Review fixes in this PR
detailis no longer dropped: only theurlmember is rewritten, sodetail: "high"survives the conversion.- The re-encode is scoped to llama-server bodies. It was also reaching the safetensors/MLX client-tools path, where a payloadless
data:URL — input extraction deliberately ignores with a warning — turned into a 400 on a path that used to answer. - Removed a duplicate test import that was failing Lint CI.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
The WebP fix addresses a real gap in the tools and response-format paths. Review coverage includes 902 passing existing tests plus A/B checks through the request handlers and llama.cpp’s image decoder. One improvement before merge: preserve 16-bit grayscale PNG precision. The new conversion clips these images to nearly all white. The A/B decoder comparison shows 1 white pixel before versus 255 after in a 256-pixel grayscale ramp. A sandbox fix passes across Windows and current and older Pillow versions. Native macOS, browser clipboard flows and GPU inference remain unverified. |
|
Good catch on the 16-bit grayscale clipping — reproduced and fixed in
Worth noting this was not confined to the paths this PR adds: One thing the fix needed beyond the straightforward scale: Verified on the two pinned Pillow versions ( Not verified: native macOS paste and browser clipboard flows, and GPU inference. |
|
Closing the platform gap I left open on the 16-bit fix: it is now measured on Windows rather than inferred. Matrix over the two pinned Pillow versions on all three platforms, importing the real
Each job asserts the same four things: the 256-px 16-bit ramp keeps Separately, a correction to my own PR description rather than to the code. It says WebP is "what macOS screenshots ... produce", and that is not right: Still unverified: native macOS paste and browser clipboard flows. GPU is not in this path — the conversion is Pillow in the Studio process and the decode is llama-server's CPU |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Imagineer99
left a comment
There was a problem hiding this comment.
Looks good to merge. Playwright A/B checks confirm the WebP fix and grayscale preservation, with 68 passes, no failures and seven blocked clipboard cases. Trusted paste passes in Chrome and Edge, and current CI is green. Coverage uses a focused Studio code fixture; full Studio and native Safari remain unverified.
For the A/B comparison from 2da3771 to cf44108, WebP with tools reaches the decoder as WebP and fails before, then reaches it as PNG and succeeds after. The current head retains all 256 grayscale levels in plain chat, tools and JSON response format cases.

Studio converts images to PNG before sending them, because llama-server can only read a few image formats. That conversion was missing on the path used when tools or a response format are set, so the image went out in whatever format it arrived in and the request failed.
The odd part for a user is that turning tools on is what breaks it, which is hard to connect to the screenshot you just pasted. WebP is the common case, since that is what macOS screenshots and most browsers produce.
This runs the same conversion on both paths. Remote image links are still passed through untouched, and images sent through the older
image_base64field are not converted twice.Worth saying plainly: Claude Code sends its images down the path that already converted them, so the gap is the OpenAI compatible endpoints with tools switched on. This is a consistency fix, not a widespread outage.
How to check: send a WebP image with and without tools enabled and compare what reaches llama-server.