GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||
GeezerVison is showing github.com — fix(provider): add universal empty-content guard to message pipeline by jpvelasco · Pull Request #23259 · anomalyco/opencode Conversation
|
| Pass | Code location | Can produce |
|---|---|---|
| Pass 1 (Anthropic/Bedrock empty text filter) | transform.ts:55-73 |
guarded locally -- but only for two providers |
Pass 3 (Anthropic tool reorder flatMap) |
transform.ts:115-126 |
content: [] if the non-tool split half was all-empty |
| Pass 5 (interleaved reasoning filter) | transform.ts:178-211 |
content: [] when message was reasoning-only |
unsupportedParts() |
transform.ts:267-303 |
content: [] if all parts were unsupported modality |
Bedrock's ConverseAPI rejects empty content with a fatal ValidationException that permanently breaks the active session. Other providers fail in their own ways.
This architectural gap has surfaced in multiple independent reports:
ValidationException: messages: text content blocks must be non-emptycontent: [] (also targeted by fix(provider): drop empty content messages after interleaved reasoning filter #17712)Add a single O(n) filter at the very end of message(), after all transformation passes and before return msgs:
msgs = msgs.filter((msg) => { if (typeof msg.content === "string") return msg.content !== "" if (Array.isArray(msg.content)) return msg.content.length > 0 return true })
This is additive -- existing pass-local guards (Pass 1) remain in place as defense-in-depth. Any future transformation pass that produces empty content is automatically caught without needing its own guard.
Added a new describe("ProviderTransform.message - universal empty-content guard") block to test/provider/transform.test.ts with 12 test cases:
content: "" and content: [] at assistant/user/tool/system roles (non-Anthropic)content: [{text:""}] is preserved (not our job to touch array internals outside Pass 1)content:[{type:"reasoning"}]) is droppedAlso updated one existing test that was asserting the previous pass-through behavior for empty-string content on non-Anthropic providers -- the description now accurately reflects that empty-string is dropped universally by the guard.
dev and includes a comprehensive regression suite.cd packages/opencode
bun test test/provider/transform.test.ts
# 145 pass, 0 fail
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Multiple transformation passes (Pass 3 Anthropic tool reorder, Pass 5 interleaved reasoning filter, unsupportedParts stripping) can each produce messages with content:[] or content:"" that providers reject with hard validation errors. Bedrock's ConverseAPI crashes the session with a ValidationException on empty content. Adds a single O(n) filter at the end of message() that drops any message with empty string or empty array content, regardless of which pass produced it. This is additive -- existing pass-local guards remain as defense-in-depth. Relates to: anomalyco#15715, anomalyco#16332, anomalyco#22364, anomalyco#17705
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate PRs FoundThe following open/related PRs address the same or overlapping issues:
Why they're related: All address the same root problem of empty content ( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
bug: message pipeline has no final empty-content guard, causing ValidationException on Bedrock and hard failures on other providers
There was an error while loading. Please reload this page.