fix(agent): empty multimodal content becomes None - #2679
Open
1688mengdie wants to merge 1 commit into
Open
Conversation
The Multimodal arm of `impl From<Message> for AIMessage` built content by
starting from the text value and only appending attached-image markers when
images were present, then always wrapped the result in `Some(content)`. A
message with empty text and no images therefore produced `Some("")` — a bare
empty string sent straight to the provider, where a strict API rejects it
(400) and a permissive gateway silently bills an empty round.
The Text and Mixed arms both guard empty content (Mixed returns None for
empty text), so the Multimodal arm was the only one without defence. The
`user_multimodal` constructor returns `Self` and cannot reject, and serde
deserialization rebuilds the fields directly, so the conversion arm is the
correct choke point to defend.
After building content, return None when it trims to empty. Non-empty
multimodal content (text, images, or both) is unaffected, and an image-only
message keeps its image markers. The constructor is left unchanged.
Test: added 4 behavioral cases (empty text+images to None, non-empty text
preserved, image-only kept, constructor-fed conversion) in message.rs;
agentic::core::message::tests pass.
AI: generated with review; verified with `cargo test -p bitfun-core
--features agent-runtime --jobs 4` (message.rs tests green; one unrelated
pre-existing coordinator test still fails on the clean baseline).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An empty multimodal message (no text and no images) is converted through
impl From<Message> for AIMessageintocontent: Some("")- a bare emptystring sent straight to the provider, where a strict API rejects it (400) and
a permissive gateway silently bills an empty round.
Root cause
The Multimodal conversion arm has no empty-content guard. It starts content
from the text value, only appends attached-image markers when images are
present, then always wraps the result in
Some(content). The Text and Mixedarms both guard empty content (the Mixed arm returns
Nonefor empty text),so the Multimodal arm is the only one without defence.
Fix
After building content, return
Nonewhen it trims to empty. Non-emptymultimodal content (text, images, or both) is unaffected, and an image-only
message keeps its image markers. The
user_multimodalconstructor is leftunchanged: it returns
Selfand cannot reject, and serde deserializationrebuilds the fields directly, so the conversion arm is the correct chokepoint
to defend. No new helper or configuration is introduced.
Testing
message.rs: empty text+images becomesNone;non-empty text preserved; image-only kept; constructor-fed conversion.
cargo test -p bitfun-core --features agent-runtime --jobs 4-message::testsgreen (9 passed); one unrelated pre-existing coordinator test still fails on
the clean baseline.
Closes #2676
Commit list:
d6f774179fix(agent): empty multimodal content becomes None- message.rsMultimodal arm content -> None; adds 4 behavioral tests.