Skip to content

file type mapping bug fix - #5884

Merged
akshaydeo merged 3 commits into
devfrom
08-05-file_type_mapping_bug_fix
Aug 6, 2026
Merged

file type mapping bug fix#5884
akshaydeo merged 3 commits into
devfrom
08-05-file_type_mapping_bug_fix

Conversation

@akshaydeo

@akshaydeo akshaydeo commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

go test ./core/providers/anthropic/... ./core/schemas/...

Expected: all tests pass, including TestToolResultDocumentSurvivesGroupedConversion, TestToolResultDocumentSurvivesConversion, TestToolResultDocumentWithoutTitleGetsFilename, TestToolResultDocumentAlongsideText, TestChatToResponsesKeepsFileURL, and TestResponsesToChatKeepsFileURL.

Breaking changes

  • 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
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Preserved document attachments in tool-result content, including placement alongside text.
    • Generated filenames for documents without titles using the source media type.
    • Preserved file URLs and file types when converting messages between Chat and Responses formats.
  • Tests

    • Added coverage for document handling, filename generation, content ordering, and file metadata preservation.

Walkthrough

Anthropic tool-result conversion preserves nested document blocks and synthesizes filenames for untitled inline files. Chat and Responses file conversions retain file_url and file_type metadata in both directions.

Changes

File content preservation

Layer / File(s) Summary
Anthropic document conversion
core/providers/anthropic/responses.go, core/providers/anthropic/toolresultdocument_test.go
Grouped and ungrouped tool-result conversion preserves document blocks as input_file content. Untitled inline files receive synthesized filenames. Tests cover document-only and mixed text-document results.
File URL round-trip
core/schemas/mux.go, core/schemas/fileurlpreservation_test.go
Chat and Responses conversions preserve file_url and file_type metadata. Tests cover both conversion directions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: pratham-mishra04, tejasghatte, sammaji

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title identifies the primary file type mapping bug fix and matches the pull request changes.
Description check ✅ Passed The description clearly explains the problem, changes, tests, affected areas, breaking changes, and security impact.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 08-05-file_type_mapping_bug_fix

Comment @coderabbitai help to get the list of available commands.

@akshaydeo akshaydeo mentioned this pull request Aug 6, 2026
18 tasks
@akshaydeo
akshaydeo marked this pull request as ready for review August 6, 2026 00:29

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e661c5 and 7192207.

📒 Files selected for processing (4)
  • core/providers/anthropic/responses.go
  • core/providers/anthropic/toolresultdocument_test.go
  • core/schemas/fileurlpreservation_test.go
  • core/schemas/mux.go

Comment thread core/schemas/mux.go
@akshaydeo
akshaydeo force-pushed the 08-05-harness_tests branch from 2e661c5 to fca3cbe Compare August 6, 2026 09:11
@akshaydeo
akshaydeo force-pushed the 08-05-file_type_mapping_bug_fix branch from 7192207 to cf642b7 Compare August 6, 2026 09:11
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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.

@akshaydeo akshaydeo mentioned this pull request Aug 6, 2026
10 tasks
coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 6, 2026
@akshaydeo akshaydeo mentioned this pull request Aug 6, 2026
9 tasks
@akshaydeo
akshaydeo force-pushed the 08-05-harness_tests branch from fca3cbe to aae15b7 Compare August 6, 2026 17:18
@akshaydeo
akshaydeo force-pushed the 08-05-file_type_mapping_bug_fix branch from cf642b7 to a906f5c Compare August 6, 2026 17:18
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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.

@akshaydeo akshaydeo mentioned this pull request Aug 6, 2026
18 tasks
@akshaydeo
akshaydeo force-pushed the 08-05-file_type_mapping_bug_fix branch from a906f5c to fa93a62 Compare August 6, 2026 18:01
@akshaydeo
akshaydeo force-pushed the 08-05-harness_tests branch from aae15b7 to 05d76fb Compare August 6, 2026 18:01
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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.

@akshaydeo
akshaydeo force-pushed the 08-05-harness_tests branch from 05d76fb to ae069a2 Compare August 6, 2026 19:38
@akshaydeo
akshaydeo force-pushed the 08-05-file_type_mapping_bug_fix branch from fa93a62 to 647b82b Compare August 6, 2026 19:38
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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.

@akshaydeo
akshaydeo force-pushed the 08-05-file_type_mapping_bug_fix branch from 647b82b to ce5a846 Compare August 6, 2026 19:57
@akshaydeo
akshaydeo force-pushed the 08-05-harness_tests branch from ae069a2 to 30ec627 Compare August 6, 2026 19:57
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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.

akshaydeo commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

  • Aug 6, 7:58 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Aug 6, 8:00 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo changed the base branch from 08-05-harness_tests to graphite-base/5884 August 6, 2026 19:59
@akshaydeo
akshaydeo changed the base branch from graphite-base/5884 to dev August 6, 2026 19:59
@akshaydeo
akshaydeo dismissed coderabbitai[bot]’s stale review August 6, 2026 19:59

The base branch was changed.

@akshaydeo
akshaydeo requested a review from a team as a code owner August 6, 2026 19:59
@akshaydeo
akshaydeo merged commit da60e05 into dev Aug 6, 2026
6 checks passed
@akshaydeo
akshaydeo deleted the 08-05-file_type_mapping_bug_fix branch August 6, 2026 20:00
akshaydeo added a commit that referenced this pull request Aug 7, 2026
## 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
@akshaydeo akshaydeo mentioned this pull request Aug 7, 2026
18 tasks
michaeldunn9 added a commit to michaeldunn9/bifrost that referenced this pull request Aug 11, 2026
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
atharvamhaske pushed a commit to atharvamhaske/bifrost that referenced this pull request Aug 13, 2026
## 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
michaeldunn9 added a commit to michaeldunn9/bifrost that referenced this pull request Aug 17, 2026
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
michaeldunn9 added a commit to michaeldunn9/bifrost that referenced this pull request Aug 20, 2026
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
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.

1 participant