Skip to content

feat: send tool result media to providers like user files - #31383

Merged
ethanndickson merged 11 commits into
mainfrom
codagt-1430-tool-result-filename
Nov 10, 2026
Merged

ethanndickson merged 11 commits into
mainfrom
codagt-1430-tool-result-filename

Conversation

@ethanndickson

@ethanndickson ethanndickson commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Part of CODAGT-1430. This is the first of four stacked PRs.

Today a PDF in an MCP tool result reaches no provider. On Anthropic we strip it in chatd. On OpenAI Chat Completions fantasy swaps it for a "cannot be displayed" note, and on Responses it sends a placeholder that points at a user message it never sends.

coder/fantasy#73 and coder/fantasy#74 make fantasy convert tool result media with the converter it already uses for user files: an Anthropic document inside tool_result, an input_file inside function_call_output on Responses, and a user file part straight after the tool message on Chat Completions. Both have merged, and this PR pins charm.land/fantasy to the coder_2_33 tip that has them. Chat Completions file parts now refuse text files, as Responses already did, so AcceptsFilePartMediaType follows.

The converters take a filename, so an MCP embedded resource blob is now named after the last element of its URI path, and we store the name with the tool result so later turns send the same one. OpenAI picks the file type from the extension, so we append the right one when it's missing or wrong. We drop names with control characters, as Postgres jsonb rejects NUL, and we redact the name like the rest of the tool response, since a URI like https://host/sse/<token> would otherwise put the token in the chat history.

There's also a test proving aibridge's Chat Completions re-encode keeps a user file part, as that's where these PDFs end up.

Anthropic still strips tool result PDFs until the next PR in the stack.

@linear-code

linear-code Bot commented Oct 28, 2026

Copy link
Copy Markdown

CODAGT-1430

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T06:08:14.223956Z 95aa72c Manual request
🔒 Security Review ✅ Completed 2026-11-04T07:27:44.534139Z 70a8382 Manual request

Security findings

Advisory findings (1)

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9392c560b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread go.mod Resolved
Comment thread coderd/x/chatd/mcpclient/mcpclient.go Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛡️ Codex Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 9392c560b2

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread go.mod Resolved
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 034e5965b4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/mcpclient/mcpclient.go Resolved
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 70a8382efe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 70a8382efe

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ethanndickson
ethanndickson marked this pull request as ready for review November 4, 2026 07:47
@ethanndickson
ethanndickson force-pushed the codagt-1430-tool-result-filename branch 2 times, most recently from 89f1395 to 95aa72c Compare November 9, 2026 06:04
@ethanndickson
ethanndickson temporarily deployed to main November 9, 2026 06:04 — with GitHub Actions Inactive
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 95aa72c75a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

coder/fantasy#73 and coder/fantasy#74 convert tool result media through
each provider's file part converter and add a filename. Both merged into
coder_2_33; pin its tip, f153e3842fa7.

coder/fantasy#74 also stops sending text files as Chat Completions file
parts, so Chat Completions routes no longer accept them and chatprompt
inlines user text files as text, as it does on Responses.
… storage

An MCP tool that returns an embedded resource blob now names the media
after the last element of the resource URI path. chatloop copies the
name into the media tool result, and chatprompt stores it in the
persisted media result and restores it for the next prompt, so
providers can label the file the same way they label a user attachment.
…transport as files

Send a PDF tool result with a filename through the anthropic, OpenAI
Chat Completions, OpenAI Responses and openai-compat clients and check
the request body: an Anthropic document inside tool_result, a user file
part right after the tool message on Chat Completions, and an
input_file inside function_call_output on Responses, each with the
filename.
… user file part

chatd sends PDFs on Chat Completions as user file parts, both for
attachments and for tool results. aibridge decodes the body into
openai-go types and encodes it again, so check that file_data and
filename survive.
…the path import

resourceFilename imports the path package, and revive rejects the
newServerRedactor loop variable named path.
…haracters

A percent-encoded NUL in a resource URI decodes into the filename, and
Postgres jsonb rejects \u0000, so the tool result could not be saved.
Such a name is never a useful label, so send the media without one.
…atch the media type

OpenAI detects the file type of an input file from its filename extension. A PDF from a URI such as https://api/x/files/12345 had no extension, and report.bin had a wrong one. The stored name is replayed on every turn, so a rejected name would break every later turn.

Keep the name when its extension maps to the media type. Otherwise append the canonical extension, which is always .pdf for application/pdf. Return no name when the media type has no known extension, so the provider default applies.
The filename comes from the resource URI of an untrusted inline MCP server. A URI such as https://host/sse/<token> made the token the filename, which reached the model and the stored chat history. Redact the filename like the other tool response fields.
lint/go/new-code runs errcheck with check-blank, which rejects the
discarded mime.ParseMediaType and mime.ExtensionsByType errors.
The tool result filename comes from the last segment of an MCP resource URI, which has no length limit. A long segment was stored with the chat and sent to the model on every later turn, and Anthropic rejects a document title over 500 characters. Normalize the name with the rule for uploaded file names: remove control characters, trim spaces, and truncate to 255 bytes on a UTF-8 boundary. A name with a control character now keeps its other characters instead of being dropped.
…file name is truncated

Providers such as OpenAI detect the file type from the file name
extension, so truncation to the stored name limit now shortens only
the stem.
@ethanndickson
ethanndickson force-pushed the codagt-1430-tool-result-filename branch from 95aa72c to cdd36b4 Compare November 9, 2026 06:47
@ethanndickson
ethanndickson temporarily deployed to main November 9, 2026 06:48 — with GitHub Actions Inactive
@ethanndickson
ethanndickson merged commit 5cbf086 into main Nov 10, 2026
28 of 29 checks passed
@ethanndickson
ethanndickson temporarily deployed to main November 10, 2026 13:06 — with GitHub Actions Inactive
@ethanndickson
ethanndickson deleted the codagt-1430-tool-result-filename branch November 10, 2026 13:06
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 10, 2026

This branch was previously deployed

1 inactive deployment
main — cdd36b45 Deployed Nov 10, 2026 by ethanndickson via cla #253267
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants