Repository navigation
fix(llm): stop dropping images when string serializer is forced - #5460
Conversation
Models listed in FORCE_STRING_SERIALIZER_MODELS (e.g. DeepSeek, GLM) always used the string serializer, which emits TextContent only. Any message carrying ImageContent was therefore silently reduced to its text parts and the image was discarded before the request was sent, so vision-capable models never received the image. Keep the list format for messages that actually carry an image when vision is active, while text-only messages still use the string form those providers require. Co-authored-by: openhands <openhands@all-hands.dev>
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Assessment
The code change is minimal and behaves as described. preserve_images = vision_enabled and self.contains_image adds one branch that keeps list serialization for image-bearing messages when vision is active, even when force_string_serializer is set; text-only and vision-disabled messages keep the previous string form. I traced the branch against base behavior in openhands-sdk/openhands/sdk/llm/message.py and found no other behavioral change: when vision_enabled is False or the message carries no ImageContent, the new elif is not taken, so those paths serialize exactly as before. The tool-role truncation path in _list_serializer still applies _maybe_truncate_tool_text, so the string serializer's tool-text truncation is preserved. The follow-up about the bare "deepseek" substring entry is correctly left out of scope.
Tests: the 3 new tests in tests/sdk/llm/test_message.py pass, and tests/sdk/llm/ passes 1165 tests. The 2 failures are in tests/sdk/llm/auth/test_credentials.py and are environment artifacts (HOME=/var/openhands has no writable home), unrelated to this diff.
Material finding (blocks merge)
The Validate PR description check fails on the current head 61bab452a9fed5eb340aa88e38756f7acff11310 (mergeStateStatus: BLOCKED). Its annotations report:
- the first visible line of the PR description must be
HUMAN:; - a short human-written note is required between
HUMAN:andAGENT:; - the
AGENT:marker from the PR template must be kept; - an issue must be linked in the
## Issue Numbersection (e.g.Fixes #123).
The current PR body contains none of these. Per AGENTS.md (PR_DESCRIPTION_HUMAN_CHECK), the HUMAN: field is reserved for human contributors and an AI agent must not edit, move, or fill it in. The required action is for the author to update the description in their own words and link the issue this fix addresses. Until that happens the check stays red and the PR cannot merge, so approval is deferred to a human maintainer.
🔄 CHANGES REQUESTED
|
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Assessment
Re-reviewed at head 381ce31653b8b2c02d8aaa16ea0cfc9545b02bf0 (a merge of main; the fix itself is unchanged from the earlier revision).
The change is minimal and matches the reported root cause. In openhands-sdk/openhands/sdk/llm/message.py, preserve_images = vision_enabled and self.contains_image adds one branch that keeps list serialization for image-bearing messages when vision is active, even when force_string_serializer is set. I traced the branch against base behavior:
vision_enabled=Falseor noImageContent→ the newelifis not taken, so serialization is byte-for-byte the same as before; text-only messages still get the string form forced providers require.- The
role="tool"truncation path in_list_serializerstill applies_maybe_truncate_tool_text, so the string serializer's tool-text truncation is preserved on the image path. - No other call sites or public surfaces are affected;
to_chat_dictalready accepted these parameters.
The linked issue #5360 is open and carries the ready-for-dev label, and the PR now links it via Fixes #5360. The HUMAN:/AGENT: markers are present and the Validate PR description check passes on this head (it failed on the prior revision only because the description was missing them).
Verification: the 3 new tests in tests/sdk/llm/test_message.py pass (33 passed), and no changed behavior is untested for the paths the branch touches.
CI: Validate PR description, pre-commit, build, sdk-tests prerequisites and the other completed checks are green on this head; a few long-running jobs (sdk-tests, cross-tests, integration-test, build-binary-and-test) were still in progress at review time. This is a model-capability/serialization change, so it can plausibly alter agent behavior; I found no required eval evidence missing for this specific fix, and the in-progress checks should be confirmed before merge.
No material correctness, security, compatibility, or acceptance-criterion defect found.
✅ APPROVED
Generated by OpenHands AI agent on behalf of Graham Neubig. Co-authored-by: openhands <openhands@all-hands.dev>
…forced-string-serializer
HUMAN:
Noting my review intent from my own session: the reporter observed the file editor's image being dropped for a forced-string-serializer model, and text-only messages were unaffected.
AGENT:
Why
Models listed in
FORCE_STRING_SERIALIZER_MODELSalways take the string serializer branch inMessage.to_chat_dict(). That serializer emitsTextContentonly:So any message carrying
ImageContentwas silently reduced to its text parts and the image was discarded before the request was sent. Vision-capable models never received the image at all, with no error or warning.This is observable end-to-end. The file editor attaches images to its tool result, but a DeepSeek/GLM run reported that it could not see the image and fell back to OCR-style reasoning about the file path.
Two conditions combine to cause this:
force_string_serializeris resolved from the model list, wheremodel_matches()is a case-insensitive substring match and the list contains the bare token"deepseek". Any DeepSeek model (including newer multimodal ones) therefore matches.force_string_serializerhas no override path. Unlikesupports_vision, it is not resolved throughcapability_overrides/metadata, so it cannot be corrected from outside.Summary
How to Test
Full suite result:
1167 passed(including 3 new tests intests/sdk/llm/test_message.py).End-to-end evidence (live endpoint, real image)
Ran a red 64x64 PNG through the SDK's own
LLMpath against the OpenHands LLM proxy. A correct answer proves the pixels actually reached the model rather than being dropped:Output:
Before this change the image payload was never built, regardless of the vision override. After it, the image is sent and the model correctly answers
Red.Note the first block:
supports_visionis a separate gate resolved by LiteLLM metadata, and it isFalsefor these newer DeepSeek ids because LiteLLM has no entry for them. That gate is intentionally left tocapability_overrides(its documented purpose) and is not changed here - this PR only fixes the serializer dropping content it was given.Type
Notes
ImageContentand vision active change, and previously those lost the image entirely.role="tool"messages carrying an image, which is thefile_editorpath."deepseek"substring entry should be narrowed now that multimodal DeepSeek models exist. Happy to split that out if preferred.Issue Number
Fixes #5360.
This PR was created by an AI agent (OpenHands) on behalf of @neubig.