[PR #582] [CLOSED] Serve tool result images #2706

Closed
opened 2026-11-04 02:02:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/582
Author: @gopinath87607
Created: 10/3/2026
Status: ❌ Closed

Base: main ← Head: serve-tool-result-images


📝 Commits (2)

  • 35f4aae serve (vision): an image inside a tool_result reached the model as an empty result
  • 07ec590 serve (vision): an image source that fails is a 400, not an empty reply

📊 Changes

3 files changed (+118 additions, -9 deletions)

View changed files

📝 serve/frontend.py (+16 -3)
📝 serve/server.py (+16 -4)
📝 serve/test_server.py (+86 -2)

📄 Description

What this is

The Anthropic dialect flattened a tool's result through _text_of(), which keeps the text parts
only, so an image a tool returned — Claude Code's Read on a picture, a screenshot tool, a browser
tool — was dropped with no error, no log line and no refusal. The model received an empty tool
result and answered anyway: a confident description of a picture it had never been given.

This is the shape Claude Code uses for every image its Read tool returns, which is why images
could work in one client and come back wrong in another.

Measured, before the fix

4-way IQ3_S rig, one image, three request shapes:

request shape prompt tokens answer
Anthropic, image inside tool_result 380 "B — blue shape on a white background" — wrong
Anthropic, plain user image block 890 correct
OpenAI, image in the "tool" message 956 correct

The image contributes ~576 tokens, so 380 is the proof that it never arrived.

The fix

_parts_of() keeps it, and the pack's chat template already renders one image item per image for a
message of any role (chat_template.jinja:8), so the rows land inside <tool_response> where the
picture belongs. A message holding an image beside a tool_result was dropped the same way and now
keeps it too.

A text-only result is unchanged: _parts_of() returns a plain string when there is no image.

After: 959 prompt tokens and "The letter Q inside a green circle on a purple background."

A bad image source, folded in

The second commit is the same API surface: Vision.load let OSError out of every fetch — a 404
(HTTPError), a refused connection or an unknown host (URLError) are all OSError — and a data:
URL with no comma raised IndexError. The dispatcher maps only ValueError to a status, so all of
those closed the client's connection with no reply at all (curl: (52) Empty reply from server)
instead of a 400. Every branch of load now raises ValueError saying what went wrong, like the last
line already did. It sat in the Monitor's commit on the old branch; it is an image-API fix, so it is
here rather than there.

Testing

serve/test_server.py's ToolResultImages: the image survives and images_of() finds it, a
text-only result is unchanged, an image beside a tool result survives, and the rendered prompt gets
the encoder's rows. BadImageSource pins the 400: a 404, a refused connection, an unknown host, a
data: URL that is not base64, and a file that cannot be read all raise ValueError, and a readable
source still loads. serve's 126 tests pass on v0.1.38 (python3 -m unittest serve.test_server).

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/582 **Author:** [@gopinath87607](https://github.com/gopinath87607) **Created:** 10/3/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `serve-tool-result-images` --- ### 📝 Commits (2) - [`35f4aae`](https://github.com/Niko1221/Strata/commit/35f4aaec4cf9b1c37c568b6e1ab362a468462192) serve (vision): an image inside a tool_result reached the model as an empty result - [`07ec590`](https://github.com/Niko1221/Strata/commit/07ec590bebb4f5941477a465fd625a565488e5d2) serve (vision): an image source that fails is a 400, not an empty reply ### 📊 Changes **3 files changed** (+118 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+16 -3) 📝 `serve/server.py` (+16 -4) 📝 `serve/test_server.py` (+86 -2) </details> ### 📄 Description ## What this is The Anthropic dialect flattened a tool's result through `_text_of()`, which keeps the text parts only, so an image a tool returned — Claude Code's `Read` on a picture, a screenshot tool, a browser tool — was dropped with no error, no log line and no refusal. The model received an empty tool result and answered anyway: **a confident description of a picture it had never been given.** This is the shape Claude Code uses for every image its `Read` tool returns, which is why images could work in one client and come back wrong in another. ## Measured, before the fix 4-way IQ3_S rig, one image, three request shapes: | request shape | prompt tokens | answer | |---|---|---| | Anthropic, image inside `tool_result` | 380 | "B — blue shape on a white background" — **wrong** | | Anthropic, plain user image block | 890 | correct | | OpenAI, image in the `"tool"` message | 956 | correct | The image contributes ~576 tokens, so 380 is the proof that it never arrived. ## The fix `_parts_of()` keeps it, and the pack's chat template already renders one image item per image for a message of any role (`chat_template.jinja:8`), so the rows land inside `<tool_response>` where the picture belongs. A message holding an image beside a `tool_result` was dropped the same way and now keeps it too. A text-only result is unchanged: `_parts_of()` returns a plain string when there is no image. **After:** 959 prompt tokens and "The letter Q inside a green circle on a purple background." ## A bad image source, folded in The second commit is the same API surface: `Vision.load` let `OSError` out of every fetch — a 404 (`HTTPError`), a refused connection or an unknown host (`URLError`) are all `OSError` — and a `data:` URL with no comma raised `IndexError`. The dispatcher maps only `ValueError` to a status, so all of those closed the client's connection with **no reply at all** (`curl: (52) Empty reply from server`) instead of a 400. Every branch of `load` now raises `ValueError` saying what went wrong, like the last line already did. It sat in the Monitor's commit on the old branch; it is an image-API fix, so it is here rather than there. ## Testing `serve/test_server.py`'s `ToolResultImages`: the image survives and `images_of()` finds it, a text-only result is unchanged, an image beside a tool result survives, and the rendered prompt gets the encoder's rows. `BadImageSource` pins the 400: a 404, a refused connection, an unknown host, a `data:` URL that is not base64, and a file that cannot be read all raise `ValueError`, and a readable source still loads. `serve`'s 126 tests pass on `v0.1.38` (`python3 -m unittest serve.test_server`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:02:31 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2706
No description provided.