file type mapping bug fix - #5884
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughAnthropic tool-result conversion preserves nested document blocks and synthesizes filenames for untitled inline files. Chat and Responses file conversions retain ChangesFile content preservation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant AnthropicToolResult
participant GroupedConverter
participant StandardConverter
participant ResponsesFunctionCallOutput
AnthropicToolResult->>GroupedConverter: document content block
AnthropicToolResult->>StandardConverter: document content block
GroupedConverter->>ResponsesFunctionCallOutput: input_file block
StandardConverter->>ResponsesFunctionCallOutput: input_file block with filename
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@core/schemas/mux.go`:
- Around line 620-622: Update the ChatMessageRoleTool branch in
ToResponsesMessages() to propagate block.File.FileURL when constructing the file
input block, preserving URL-only files as complete input_file blocks. Add a
regression test that exercises ToResponsesMessages() with a tool output file
containing only FileURL and verifies the URL is retained.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 7d2f52ae-d2b6-472b-9209-fcb8507e6103
📒 Files selected for processing (4)
core/providers/anthropic/responses.gocore/providers/anthropic/toolresultdocument_test.gocore/schemas/fileurlpreservation_test.gocore/schemas/mux.go
2e661c5 to
fca3cbe
Compare
7192207 to
cf642b7
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
fca3cbe to
aae15b7
Compare
cf642b7 to
a906f5c
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
a906f5c to
fa93a62
Compare
aae15b7 to
05d76fb
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
05d76fb to
ae069a2
Compare
fa93a62 to
647b82b
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
647b82b to
ce5a846
Compare
ae069a2 to
30ec627
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Merge activity
|
The base branch was changed.
## Summary When a tool result contains a `document` block (e.g. a PDF returned by Claude Code's Read tool), the Anthropic→Responses converters previously ignored it. This left the `function_call_output` with an empty content array, causing OpenAI to reject the request with `"Missing required parameter: 'input[N].content[0]'"`. Additionally, URL-sourced files were losing their `file_url` and `file_type` fields during chat↔responses conversion, producing equally empty `input_file` blocks. ## Changes - Added `AnthropicContentBlockTypeDocument` handling inside both `convertAnthropicContentBlocksToResponsesMessagesGrouped` and `convertAnthropicContentBlocksToResponsesMessages`, so document blocks nested in tool results are converted to `input_file` blocks instead of being silently dropped. - Added `defaultDocumentFilename` to synthesize a filename (e.g. `document.pdf`) when a document block has no title, since OpenAI rejects inline `file_data` without a `filename`. - Propagated `FileURL` and `FileType` through all three chat↔responses conversion paths (`ToResponsesToolMessage`, `ToResponsesMessages`, `ToChatMessages`) so URL-sourced files survive round-trips intact. - Added `toolresultdocument_test.go` covering: document block survival in both converters, title-less documents receiving a synthesized filename, and mixed text+document tool results preserving both blocks in order. - Added `fileurlpreservation_test.go` covering chat→responses and responses→chat round-trips for URL-sourced files. ## Type of change - [x] Bug fix - [ ] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [ ] Transports (HTTP) - [x] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./core/providers/anthropic/... ./core/schemas/... ``` Expected: all tests pass, including `TestToolResultDocumentSurvivesGroupedConversion`, `TestToolResultDocumentSurvivesConversion`, `TestToolResultDocumentWithoutTitleGetsFilename`, `TestToolResultDocumentAlongsideText`, `TestChatToResponsesKeepsFileURL`, and `TestResponsesToChatKeepsFileURL`. ## Breaking changes - [x] No ## Security considerations No auth, secrets, or PII implications. The change only affects how document content blocks and file URLs are forwarded to the upstream provider. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [ ] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
Rebuild the remaining Bedrock conversion on current dev after the Anthropic half landed in maximhq#5884. Changes: - core/providers/bedrock/ - centralize document materialization and preserve nested tool-result documents - core/changelog.md - record the provider fix
## Summary When a tool result contains a `document` block (e.g. a PDF returned by Claude Code's Read tool), the Anthropic→Responses converters previously ignored it. This left the `function_call_output` with an empty content array, causing OpenAI to reject the request with `"Missing required parameter: 'input[N].content[0]'"`. Additionally, URL-sourced files were losing their `file_url` and `file_type` fields during chat↔responses conversion, producing equally empty `input_file` blocks. ## Changes - Added `AnthropicContentBlockTypeDocument` handling inside both `convertAnthropicContentBlocksToResponsesMessagesGrouped` and `convertAnthropicContentBlocksToResponsesMessages`, so document blocks nested in tool results are converted to `input_file` blocks instead of being silently dropped. - Added `defaultDocumentFilename` to synthesize a filename (e.g. `document.pdf`) when a document block has no title, since OpenAI rejects inline `file_data` without a `filename`. - Propagated `FileURL` and `FileType` through all three chat↔responses conversion paths (`ToResponsesToolMessage`, `ToResponsesMessages`, `ToChatMessages`) so URL-sourced files survive round-trips intact. - Added `toolresultdocument_test.go` covering: document block survival in both converters, title-less documents receiving a synthesized filename, and mixed text+document tool results preserving both blocks in order. - Added `fileurlpreservation_test.go` covering chat→responses and responses→chat round-trips for URL-sourced files. ## Type of change - [x] Bug fix - [ ] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [ ] Transports (HTTP) - [x] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./core/providers/anthropic/... ./core/schemas/... ``` Expected: all tests pass, including `TestToolResultDocumentSurvivesGroupedConversion`, `TestToolResultDocumentSurvivesConversion`, `TestToolResultDocumentWithoutTitleGetsFilename`, `TestToolResultDocumentAlongsideText`, `TestChatToResponsesKeepsFileURL`, and `TestResponsesToChatKeepsFileURL`. ## Breaking changes - [x] No ## Security considerations No auth, secrets, or PII implications. The change only affects how document content blocks and file URLs are forwarded to the upstream provider. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [ ] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
Rebuild the remaining Bedrock conversion on current dev after the Anthropic half landed in maximhq#5884. Changes: - core/providers/bedrock/ - centralize document materialization and preserve nested tool-result documents - core/changelog.md - record the provider fix
Rebuild the remaining Bedrock conversion on current dev after the Anthropic half landed in maximhq#5884. Changes: - core/providers/bedrock/ - centralize document materialization and preserve nested tool-result documents - core/changelog.md - record the provider fix

Summary
When a tool result contains a
documentblock (e.g. a PDF returned by Claude Code's Read tool), the Anthropic→Responses converters previously ignored it. This left thefunction_call_outputwith an empty content array, causing OpenAI to reject the request with"Missing required parameter: 'input[N].content[0]'". Additionally, URL-sourced files were losing theirfile_urlandfile_typefields during chat↔responses conversion, producing equally emptyinput_fileblocks.Changes
AnthropicContentBlockTypeDocumenthandling inside bothconvertAnthropicContentBlocksToResponsesMessagesGroupedandconvertAnthropicContentBlocksToResponsesMessages, so document blocks nested in tool results are converted toinput_fileblocks instead of being silently dropped.defaultDocumentFilenameto synthesize a filename (e.g.document.pdf) when a document block has no title, since OpenAI rejects inlinefile_datawithout afilename.FileURLandFileTypethrough all three chat↔responses conversion paths (ToResponsesToolMessage,ToResponsesMessages,ToChatMessages) so URL-sourced files survive round-trips intact.toolresultdocument_test.gocovering: document block survival in both converters, title-less documents receiving a synthesized filename, and mixed text+document tool results preserving both blocks in order.fileurlpreservation_test.gocovering chat→responses and responses→chat round-trips for URL-sourced files.Type of change
Affected areas
How to test
go test ./core/providers/anthropic/... ./core/schemas/...Expected: all tests pass, including
TestToolResultDocumentSurvivesGroupedConversion,TestToolResultDocumentSurvivesConversion,TestToolResultDocumentWithoutTitleGetsFilename,TestToolResultDocumentAlongsideText,TestChatToResponsesKeepsFileURL, andTestResponsesToChatKeepsFileURL.Breaking changes
Security considerations
No auth, secrets, or PII implications. The change only affects how document content blocks and file URLs are forwarded to the upstream provider.
Checklist
docs/contributing/README.mdand followed the guidelines