Skip to content

Studio: stop chats with images from blocking other chats on GGUF models - #12236

Merged
Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:randomly-getting-invalid-base64-value
Sep 29, 2026
Merged

Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:randomly-getting-invalid-base64-value

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

With a vision GGUF model, every request in a chat that holds an image (an MCP screenshot or an attached picture) logs "Invalid base64 value" from llama-server. The image is still read correctly, but other chats wait until that chat finishes, then take over its slot, so its next turn reprocesses its history. This came in with #10794.

Before a request starts, Studio counts its prompt tokens with llama-server, and for that count it replaced each image with the text "[image]", which llama-server rejects. A failed count reserves the whole shared cache for that one request. Images are now left out of the count, like the other prompt counts already do, and each image still gets its usual flat token allowance on top.

#12080 changes how MCP image data is decoded, a different path that does not touch this count.

Fixes #12058

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Codex review has converged on this PR.

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review + reproduction evidence

Pinned review: 45faa5ff6201d29d6c83d155eb7f2c872f6e2714. No blocking findings.

I reproduced two chats at once on a vision GGUF on fresh upstream main (Modal L4, unsloth/Qwen3-VL-2B-Instruct-GGUF Q4_K_M, 4 slots, 175104 ctx, Chromium 1440x900). Chat A has an image attached and asks for a long reply; chat B is plain text and is sent a few seconds later in a second tab.

  • main 501b15f / fix reverted (run): chat B shows only "Generating..." 10 s after sending and still has no reply 7 minutes later while A keeps decoding. The llama-server log (Settings > Logs) has one got exception: {"error":{"code":500,"message":"Invalid base64 value"}} per image request (5 of 5). Over /v1/chat/completions, B's time to first token is 10.48 / 7.93 / 10.13 s when A has an image, 2.26 s when A is text only. In CI the new test fails with assert 30000 == (20 + 4224): the count falls back to the whole pool.
  • PR head (run): chat B is fully answered while A is still streaming. The llama-server log has 0 exception lines. B's time to first token is 0.99 / 1.09 / 1.01 s with an image in A. test_gguf_admission_token_count.py: 29 passed (on main the new test is the only failure, 28 passed).

PR 12236 before/after

  • Unchanged paths: a single text chat (45 prompt tokens) and a single image chat (308 prompt tokens) give byte-identical replies at temperature 0 on both sides, and the image answer still reads the picture ("SLOTH 42", red square, blue circle). Two concurrent text chats stream together on both sides.
  • Cost: an image request now makes two local calls (/apply-template then /tokenize) where main made one failing call. Single image chat time to first token is 1.39 s on both sides.
  • The only red job on the CI head arm, test_every_playwright_driver_is_invoked_by_ci (playwright_user_message_time.py not wired into CI), fails the same way on the reverted arm and comes from main.

Conclusion: the issue is real on main and this fixes it. Chats with images no longer take the whole shared cache, and nothing else changes. Not covered by hand: the MCP screenshot tool loop and audio/video parts. Code tracing shows they take the same stripped path.

Replace the mock llama-server test with a direct assertion on what the admission count forwards: the contract is that no media part reaches llama-server's count, not that one placeholder fails one imitated base64 check.
@Lyxot

Lyxot commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Pushed one small test-only commit on top (62026e4); the production fix is unchanged.

  • Replaced the mock-llama-server test with a direct assertion in the existing media test (now test_media_is_charged_by_allowance_and_not_sent_to_the_count): only text parts reach the admission count. That is the actual contract. The mock only rejected a placeholder that fails one imitated base64 check, so a decodable placeholder would have slipped past it. The assertion fails exactly when the fix is reverted.

Also confirmed on a live llama-server (Qwen3.5-0.8B GGUF + mmproj, 16k ctx): before the fix the image chat's count fell back to the whole 16384-token pool and logged "Invalid base64 value"; with it the count is 17 text tokens + the 4224 image allowance, and a max-resolution 2048x2048 image really costs 4115 tokens, so images are not undercounted.

@Lyxot

Lyxot commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Codex review and CI converged on the current head 62026e4a35.

The earlier Repo tests (CPU, studio) / workflow-trigger lint failures were test_every_playwright_driver_is_invoked_by_ci flagging playwright_user_message_time.py. That came from a main snapshot taken between #12173 and #12255, and it passes once #12255 is in the base; it is unrelated to this PR.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Root cause confirmed against llama-server's media parsing and reproduced live; the count now excludes media and keeps the per-image allowance. Codex converged and CI passed on the current head.

@Lyxot
Lyxot merged commit 6aac263 into unslothai:main Sep 29, 2026
56 of 58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Randomly Getting "Invalid base64 value" When Valid MCP Image Returns

2 participants