Skip to content

fix(provider): Bedrock, Gemini, Vertex drop empty messages before merging - #370

Merged
yuanhao merged 3 commits into
mainfrom
fix/drop-empty-messages
Oct 22, 2026
Merged

yuanhao merged 3 commits into
mainfrom
fix/drop-empty-messages

Conversation

@yuanhao

@yuanhao yuanhao commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

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_role drops any message whose key array 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-features test / clippy / doc / fmt clean. Not run against a live endpoint.

🤖 Generated with Claude Code

https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG

yuanhao and others added 2 commits October 22, 2026 00:28
…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
@yuanhao

yuanhao commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator Author

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
@yuanhao

yuanhao commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@yuanhao
yuanhao merged commit 82e3ecb into main Oct 22, 2026
16 checks passed
@yuanhao
yuanhao deleted the fix/drop-empty-messages branch October 22, 2026 08:12
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.

Bedrock/Gemini/Vertex: drop empty messages before merging (an errored assistant turn sends content: [])

1 participant