Repository navigation
feat: send tool result media to providers like user files - #31383
Conversation
45e4ffa to
9392c56
Compare
|
@codex review |
|
@codex security review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
🛡️ 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.
9392c56 to
034e596
Compare
|
@codex review |
There was a problem hiding this comment.
💡 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex security review |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
89f1395 to
95aa72c
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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.
95aa72c to
cdd36b4
Compare
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, aninput_fileinsidefunction_call_outputon Responses, and a user file part straight after the tool message on Chat Completions. Both have merged, and this PR pinscharm.land/fantasyto the coder_2_33 tip that has them. Chat Completions file parts now refuse text files, as Responses already did, soAcceptsFilePartMediaTypefollows.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
jsonbrejects NUL, and we redact the name like the rest of the tool response, since a URI likehttps://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.