Repository navigation
fix(provider): Bedrock, Gemini, Vertex drop empty messages before merging - #370
Conversation
…ging An assistant turn that errored with no content (on Gemini also one with only thinking, which is not replayed) went out as content: [] / parts: [], which both APIs reject. merge_same_role now drops a message whose array is empty before merging, so the user turns around it go back as one. Closes #369. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG
… messages too Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG
|
Review (code-reviewer): no critical issues; traced that no tool call or tool result can become empty, so nothing gets unpaired; the dropped-turn shape is the one #223 already produces. Fixed in e6c3400: two existing test doc comments my insertion had split (bedrock.rs, google.rs), and the CHANGELOG now says empty user messages are dropped too. |
- Tests: Bedrock and Gemini builder tests also use the loop's error message (one empty text block); helper tests cover an empty message first and an empty user message; a Vertex builder test; a Bedrock run through the loop where a failed prompt is followed by another — the second request carries one user message, the history keeps the error. - Docs: drop covers errored, refused and cancelled turns and unreplayable thinking on all three providers, either role; a dropped first message can leave an assistant turn first. bedrock.md: Anthropic redacted blocks are logged at debug, not warned. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG
|
Test + comment reviews addressed in 6f0268a: tests use the loop's real error shape (one empty text block) as well as no content; an empty message first and an empty user message; a Vertex builder test; and a Bedrock end-to-end test — a failed prompt then another, the second request carries one user message (fails without the fix), history keeps the errored turn. Docs widened to errored/refused/cancelled turns and unreplayable thinking on all three providers; bedrock.md now says Anthropic redacted blocks are logged at debug. |
Closes #369 (follow-up to #368 / #223).
Bug. An assistant turn that errored with no content — or, on Gemini/Vertex, one with only thinking, which is not replayed — was sent as
content: []/parts: []. Both APIs reject an empty message. The Anthropic builder already skipped such a turn; these three could not without putting two user turns side by side, which #368's merge now handles.Fix.
provider::merge_same_roledrops any message whosekeyarray is empty before merging, so the user turns around a dropped one merge into one. All three builders go through it; a message without the key is still kept as it is.Tests (each fails without the fix — checked by disabling the drop):
merge_same_role_tests::empty_messages_are_dropped_and_their_neighbours_merge— an empty model turn between two user turns, and a trailing empty one.bedrock::tests::an_empty_assistant_turn_is_not_sent—[user, assistant(no content, Error), user]→ one user message.google::tests::an_empty_model_turn_is_not_sent— a thinking-only model turn is dropped and the user turns merge.Checks:
--all-featurestest / clippy / doc / fmt clean. Not run against a live endpoint.🤖 Generated with Claude Code
https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG