[PR #529] [CLOSED] serve: an image in an Anthropic tool_result reaches the encoder (Claude Code's Read of a picture) #2678

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/529
Author: @sergqwer
Created: 10/2/2026
Status: ❌ Closed

Base: main ← Head: pr/tool-result-images


📝 Commits (2)

  • 8a9b474 serve: an image in an Anthropic tool_result reaches the encoder (Claude Code's Read of a picture)
  • 8ef230b serve: a tool's picture the server cannot read becomes a note, not a 400

📊 Changes

3 files changed (+91 additions, -4 deletions)

View changed files

📝 serve/frontend.py (+10 -4)
📝 serve/server.py (+24 -0)
📝 serve/test_server.py (+57 -0)

📄 Description

Claude Code returns a picture it opens with Read (a screenshot, a diagram) as an image block inside a tool_result. anthropic_to_messages turned every tool_result into its text (_text_of), so the image never reached the encoder and the model described a picture it had not seen. A user's own pasted image (an image block at the top level of a user message) already worked; only the tool path lost it.

Fix (serve/frontend.py, anthropic_to_messages):

  • a tool_result's content goes through _parts_of, as the OpenAI path's tool messages already do; the chat template renders the image item inside <tool_response> (its render_content handles images in any role);
  • an image block sent beside tool results in the same user turn is kept too (it used to be dropped by the same branch);
  • a text-only tool result is still one string, so every text prompt renders exactly as before.

Test: ImageMarkers.test_anthropic_tool_result_image: an image alone, after text, beside a text tool result, and in both places; it counts the image tokens and checks where they land. It fails on main (0 image tokens instead of 3) and passes here. All serve tests: 159 OK (7 skipped), on 0.1.36.

End to end (Windows, RTX 5090, Flash-Next with the CPU encoder, Claude Code asked to Read a PNG with known text and shapes):

  • before: the request carrying the tool result added 35 tokens; the answer was invented ("Hello Vision Test", a red circle);
  • after: it added 391 tokens (the image's ~360); both texts with their colours and both shapes with their positions were right, and a dark-theme code screenshot was transcribed verbatim.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio


🔄 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/529 **Author:** [@sergqwer](https://github.com/sergqwer) **Created:** 10/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/tool-result-images` --- ### 📝 Commits (2) - [`8a9b474`](https://github.com/Niko1221/Strata/commit/8a9b474ca682dd1c5fbe7e13d4cf305221a5d1af) serve: an image in an Anthropic tool_result reaches the encoder (Claude Code's Read of a picture) - [`8ef230b`](https://github.com/Niko1221/Strata/commit/8ef230b470820a68751347fc7110f43e15d2812f) serve: a tool's picture the server cannot read becomes a note, not a 400 ### 📊 Changes **3 files changed** (+91 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+10 -4) 📝 `serve/server.py` (+24 -0) 📝 `serve/test_server.py` (+57 -0) </details> ### 📄 Description Claude Code returns a picture it opens with `Read` (a screenshot, a diagram) as an image block **inside a `tool_result`**. `anthropic_to_messages` turned every `tool_result` into its text (`_text_of`), so the image never reached the encoder and the model described a picture it had not seen. A user's own pasted image (an image block at the top level of a user message) already worked; only the tool path lost it. **Fix** (`serve/frontend.py`, `anthropic_to_messages`): - a `tool_result`'s content goes through `_parts_of`, as the OpenAI path's `tool` messages already do; the chat template renders the image item inside `<tool_response>` (its `render_content` handles images in any role); - an image block sent beside tool results in the same user turn is kept too (it used to be dropped by the same branch); - a text-only tool result is still one string, so every text prompt renders exactly as before. **Test:** `ImageMarkers.test_anthropic_tool_result_image`: an image alone, after text, beside a text tool result, and in both places; it counts the image tokens and checks where they land. It fails on main (0 image tokens instead of 3) and passes here. All serve tests: 159 OK (7 skipped), on 0.1.36. **End to end** (Windows, RTX 5090, Flash-Next with the CPU encoder, Claude Code asked to `Read` a PNG with known text and shapes): - before: the request carrying the tool result added 35 tokens; the answer was invented ("Hello Vision Test", a red circle); - after: it added 391 tokens (the image's ~360); both texts with their colours and both shapes with their positions were right, and a dark-theme code screenshot was transcribed verbatim. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio --- <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:18 +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#2678
No description provided.