Skip to content

fix: reattach video tool results for openai providers#1019

Open
zgqq wants to merge 1 commit into
MoonshotAI:mainfrom
zgqq:fix/openai-tool-result-video
Open

fix: reattach video tool results for openai providers#1019
zgqq wants to merge 1 commit into
MoonshotAI:mainfrom
zgqq:fix/openai-tool-result-video

Conversation

@zgqq

@zgqq zgqq commented Jun 23, 2026

Copy link
Copy Markdown

Related Issue

No related issue. This fixes a provider conversion bug where video media returned by a tool is omitted before the next OpenAI-compatible chat request.

Problem

OpenAI-compatible chat providers can accept video_url content parts, and regular user messages already serialize them. However, when a tool returns video media, the tool message is converted to text and only images are reattached in a follow-up user message. Videos are replaced with an omission note, so video-capable OpenAI-compatible providers never receive the media.

What changed

  • Reattach video_url tool result media alongside image_url media in the follow-up user message.
  • Keep audio results as an inline omission note because Chat Completions still has no URL-based audio content part here.
  • Updated OpenAI-compatible provider tests for video tool results.
  • Added a changeset for the CLI bundle.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Verification

  • pnpm exec vitest run packages/kosong/test/openai-legacy.test.ts
  • pnpm --filter @moonshot-ai/kosong run typecheck

@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d204867

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@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: d2048672bf

ℹ️ 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".

function toolResultImageParts(message: Message): OpenAIContentPart[] {
const images: OpenAIContentPart[] = [];
function isReattachableToolMediaPart(part: ContentPart): boolean {
return part.type === 'image_url' || part.type === 'video_url';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate video reattachment to video-capable chat providers

When a custom/MCP tool returns a video_url while the provider is the default OpenAI Chat Completions backend (or another compatible endpoint that only accepts text/image/audio/file user parts), this now queues that video as a follow-up user content part and the next request is rejected for unsupported video_url. Previously those tool videos stayed as an inline omission note, so OpenAI users could continue the turn; this should only reattach video for models/endpoints known to accept video_url.

Useful? React with 👍 / 👎.

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