fix: add final empty-content guard in message() pipeline#33647
fix: add final empty-content guard in message() pipeline#33647Oxygen56 wants to merge 2 commits into
Conversation
Adds a provider-agnostic safety net at the end of the message() function that filters out messages with empty string content or empty array content before they reach any provider API. Previously only Anthropic and Bedrock had local guards; providers like DeepSeek would receive messages with empty content and fail with "messages.N: all messages must have non-empty content". Fixes anomalyco#23260
Covers empty string content, empty array content, all-empty text parts, mixed valid/invalid messages, and provider-agnostic behavior. Ref anomalyco#23260
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found several potentially related PRs that address similar issues with empty content or message transformation: Potentially Related PRs:
These PRs are in the same |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Closes #23260
Closes #26320
Type of change
What does this PR do?
Adds a provider-agnostic empty-content guard at the end of the
message()function inpackages/opencode/src/provider/transform.ts. The guard filters out messages with empty content (empty string, empty array, or all-empty text/reasoning parts) before they reach any provider API.Previously only Anthropic and Bedrock had provider-specific guards; every other provider — including DeepSeek — could receive messages with empty content and fail with hard errors that permanently break the active session (e.g. DeepSeek returns
400 Bad Request: messages.N: all messages must have non-empty content).The fix is a single O(n) filter (~15 lines) placed at the end of
message(), provider-agnostic by design, catching all current and future empty-content sources (unsupportedParts, normalizeMessages, interleaved reasoning filter, etc.).How did you verify your code works?
packages/opencode/test/provider/transform.test.tscovering: empty string content, empty array content, all-empty text parts, mixed valid/invalid messages, and provider-agnostic behavior (verified with both DeepSeek and OpenAI models)messages.N: all messages must have non-empty content) is documented in bug: message pipeline has no final empty-content guard, causing ValidationException on Bedrock and hard failures on other providers #23260 (comment)Screenshots / recordings
N/A (not a UI change)
Checklist