fix(session): never send an empty-content user message (Bedrock 400)#1731
Closed
wqymi wants to merge 0 commit into
Closed
fix(session): never send an empty-content user message (Bedrock 400)#1731wqymi wants to merge 0 commit into
wqymi wants to merge 0 commit into
Conversation
ad1869f to
f17e98b
Compare
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.
Summary
toModelMessagesEffectinmessage-v2.ts:681pushed a UIMessage withparts: []into the result array before the loop populated parts. If all DB parts were filtered (ignored text, unsupported file types, etc.), the empty user message leaked through toconvertToModelMessages, producing a ModelMessage with empty content that Bedrock/Anthropic reject with 400.normalizeMessagesintransform.ts:64passed through non-string/non-array content (null, undefined) without checking, allowing empty-content user messages to bypass the Anthropic/Bedrock filter.Changes
packages/opencode/src/session/message-v2.tsBuild user message parts into a local
userPartsarray, then only push the UIMessage whenuserParts.length > 0. Eliminates the push-before-populate race where an emptyparts: []message could leak through.packages/opencode/src/provider/transform.tsAdded explicit guard at the top of
normalizeMessages: user messages withnull,undefined, or empty-array content are dropped before reaching the provider. Safety-net backstop for any future code path that might produce empty-content user messages.packages/opencode/test/provider/transform.test.ts3 new regression tests:
Verification
bun typecheckpasses (turbo typecheck: 12/12 packages)