[PR #1045] [CLOSED] serve: the vision markers inside a message's text stay text and no longer take a picture's place (#150 for the whole marker) #2989

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

📋 Pull Request Information

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

Base: main ← Head: pr/image-markers


📝 Commits (1)

  • 1273345 serve: the vision markers inside a message's text stay text and no longer take a picture's place (#150 follow-up)

📊 Changes

3 files changed (+70 additions, -5 deletions)

View changed files

📝 serve/frontend.py (+11 -4)
📝 serve/server.py (+4 -1)
📝 serve/test_server.py (+55 -0)

📄 Description

Replaces #554. GitHub closed it on 2026-10-05, when my fork was made private by mistake: that took the fork out of the network for good, so it can no longer open pull requests. This is the same branch and commit (1273345), opened from a new fork; the discussion and the measurements are in #554.


Service.prepare() renders the chat template and tokenizes the whole prompt with parse_special=True. The template writes <|vision_start|><|image_pad|><|vision_end|> for each image item, and the #150 guard turns only an <|image_pad|> not preceded by <|vision_start|> back into text.

Message text that contains the whole marker pair becomes the same special ids as a real image. That happens with an agent reading serve/chat_template.jinja, these docs, or a tool result quoting them. If such text comes before a real picture:

  • picture 1's embedding rows go to the text's marker;
  • every later picture moves up one;
  • the last real marker becomes text.

The counts still match, so nothing reports it. With Claude Code reading a repository and a screenshot in one conversation, this is an ordinary case.

Fix (serve/server.py, Service.prompt_ids()):

  • The vision markers inside the messages' and tools' strings are swapped for a unique placeholder before rendering.
  • After rendering, each placeholder becomes its marker's literal (parse_special=False) tokens. The pieces between placeholders are tokenized as before, since a special token split the text there anyway.
  • A prompt without such text takes the old path: byte-identical ids, checked on the real tokenizer too.
  • count_tokens uses the same ids.
  • If text still yields more marker pairs than there are pictures (a marker cut between two text parts), that is now a 400 instead of a silent shift.

Test test_the_whole_marker_in_text_before_images: each picture's rows follow its own marker, and the text keeps its literal tokens. Without the fix it finds 3 vision_start where 2 belong. The #150 test is unchanged. Serve tests: 173 OK (7 skipped).

This touches the first lines of prepare(), as #529 does; whichever goes in second needs a one-line rebase.

🤖 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/1045 **Author:** [@sergqwer](https://github.com/sergqwer) **Created:** 10/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/image-markers` --- ### 📝 Commits (1) - [`1273345`](https://github.com/Niko1221/Strata/commit/1273345e9222daf666e814d7e665006c57509480) serve: the vision markers inside a message's text stay text and no longer take a picture's place (#150 follow-up) ### 📊 Changes **3 files changed** (+70 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+11 -4) 📝 `serve/server.py` (+4 -1) 📝 `serve/test_server.py` (+55 -0) </details> ### 📄 Description Replaces #554. GitHub closed it on 2026-10-05, when my fork was made private by mistake: that took the fork out of the network for good, so it can no longer open pull requests. This is the same branch and commit (`1273345`), opened from a new fork; the discussion and the measurements are in #554. --- `Service.prepare()` renders the chat template and tokenizes the whole prompt with `parse_special=True`. The template writes `<|vision_start|><|image_pad|><|vision_end|>` for each image item, and the #150 guard turns only an `<|image_pad|>` **not** preceded by `<|vision_start|>` back into text. Message text that contains the whole marker pair becomes the same special ids as a real image. That happens with an agent reading `serve/chat_template.jinja`, these docs, or a tool result quoting them. If such text comes before a real picture: - picture 1's embedding rows go to the text's marker; - every later picture moves up one; - the last real marker becomes text. The counts still match, so nothing reports it. With Claude Code reading a repository and a screenshot in one conversation, this is an ordinary case. **Fix** (`serve/server.py`, `Service.prompt_ids()`): - The vision markers inside the messages' and tools' strings are swapped for a unique placeholder before rendering. - After rendering, each placeholder becomes its marker's literal (`parse_special=False`) tokens. The pieces between placeholders are tokenized as before, since a special token split the text there anyway. - A prompt without such text takes the old path: byte-identical ids, checked on the real tokenizer too. - `count_tokens` uses the same ids. - If text still yields more marker pairs than there are pictures (a marker cut between two text parts), that is now a 400 instead of a silent shift. Test `test_the_whole_marker_in_text_before_images`: each picture's rows follow its own marker, and the text keeps its literal tokens. Without the fix it finds 3 `vision_start` where 2 belong. The #150 test is unchanged. Serve tests: 173 OK (7 skipped). This touches the first lines of `prepare()`, as #529 does; whichever goes in second needs a one-line rebase. 🤖 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:04:43 +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#2989
No description provided.