Skip to content

fix(mcp): preserve original attachments omitted from model output - #3688

Merged
RealKai42 merged 8 commits into
mainfrom
fix/mcp-attachment-originals
Sep 10, 2026
Merged

fix(mcp): preserve original attachments omitted from model output#3688
RealKai42 merged 8 commits into
mainfrom
fix/mcp-attachment-originals

Conversation

@RealKai42

@RealKai42 RealKai42 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This fixes received MCP attachments being omitted without a usable original-file reference.

Problem

Unsupported embedded blobs and image formats, oversized binary parts, and audio/video omitted during provider conversion can disappear from the model-visible result. Saving only processed text cannot recover their original bytes. References must also remain usable after a session fork, and large attachment lists must not bypass the tool-output budget.

What changed

  • Preserve unsupported embedded blobs, rejected inline images, and embedded audio/video of all sizes in the existing session media store. Keep supported inline delivery, including unchanged small images, and retain their originals before later history degradation. MCP image-compression originals use the same store.
  • Validate base64 and use content-addressed names. Preserve textual MIME types with readable extensions; distinguish plain SVG from compressed SVG.
  • Provide stable kimi-file:// references alongside local paths. Read and ReadMediaFile read these references directly from session storage, independently of the active runtime filesystem. Pagination preserves the reference, so a fork can continue reading its own copy after the source file is removed. Binary Read errors expose the resolved local path for a converter.
  • Include attachment notices in budgeted tool output. Long lists and compression details are saved as text; a short spill suffix keeps the list reference visible after text truncation.
  • Propagate cancellation through MCP output processing, image compression boundaries, and attachment writes. Do not swallow cancellation as an ordinary save failure or repeat the remote call.
  • Report preservation failures while retaining other usable output and the original MCP execution status. Update bilingual documentation and add a CLI patch changeset.

Session attachment readers remain registered without workspace FS access when the model supports the content, and returned media tags retain stable references for follow-up crops. Backing stores without local paths can still return usable attachment references.

Resource links are not downloaded. This adds neither format readers/converters nor an aggregate storage quota. Historical absolute paths are not rewritten; stable references resolve against the current session.

Validation

  • 1,083 related tests passed across MCP, media, Read, tool execution, truncation, lifecycle, loop, plan, and compaction suites.
  • Real server fork test passes: read the first page, fork, remove the source file, then use the returned Next Read arguments unchanged and verify all remaining Unicode content.
  • Verify attachment reads succeed when the runtime cannot access daemon storage, workspace reads still use the client buffer, and binary errors label server-local paths for converters.
  • Verify small-media original references survive OpenAI and Anthropic lowering; byte-check PDF, unknown binary data, rejected images, and audio/video originals.
  • Recover every reference in a 150-attachment list through paginated Read, with and without large accompanying text; verify all original bytes and bounded model-visible output.
  • Cover textual MIME extensions, invalid base64, persistence failures, already-canceled calls, and cancellation during writes.
  • Core/server typechecks, repository lint (existing warnings only), and documentation build pass. Tool snapshots are updated for Read's new reference support.

Client provider-matrix validation: all 21 end-to-end tests pass. The image-reference regression checks that the actual uploaded file reference is resolved and that the provider receives a data URL; documenting the generic kimi-file:// scheme in tool descriptions is allowed.

Checklist

  • I have read the CONTRIBUTING document.
  • I have explained the problem above; there is no linked issue.
  • I have added tests that prove the fix works.
  • Ran gen-changesets skill.
  • Ran gen-docs skill.

@changeset-bot

changeset-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d9e84f7

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 commented Sep 9, 2026

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-09T16:08:32.551682Z d9e84f7 Manual request
🔒 Security Review Completed 2026-09-09T16:15:41.187151Z d9e84f7 Manual request
ℹ️ 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.

@pkg-pr-new

pkg-pr-new Bot commented Sep 9, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@d9e84f7
npx https://pkg.pr.new/@moonshot-ai/kimi-code@d9e84f7

commit: d9e84f7

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

ℹ️ 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 packages/agent-core-v2/src/agent/mcp/output.ts Outdated
Comment thread packages/agent-core-v2/src/agent/mcp/output.ts Outdated
Comment thread packages/agent-core-v2/src/agent/mcp/output.ts Outdated
Comment thread packages/agent-core-v2/src/agent/mcp/output.ts Outdated

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

ℹ️ 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 packages/agent-core-v2/src/agent/mcp/output.ts Outdated
Comment thread packages/agent-core-v2/src/agent/mcp/output.ts Outdated
Comment thread packages/agent-core-v2/src/agent/mcp/tools/mcp.ts
Comment thread packages/agent-core-v2/src/agent/mcp/output.ts

@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: 375df0c429

ℹ️ 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 packages/agent-core-v2/src/agent/tools/os/read/readTool.ts Outdated
Comment thread packages/agent-core-v2/src/agent/tools/os/read/readTool.ts Outdated
@RealKai42

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

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

Reviewed commit: da85429da1

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.

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

ℹ️ 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 packages/agent-core-v2/src/agent/media/mediaToolsRegistrar.ts
Comment thread packages/agent-core-v2/src/agent/mcp/output.ts
@RealKai42

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

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

Reviewed commit: f8f96e1264

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.

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

ℹ️ 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 packages/agent-core-v2/src/agent/mcp/output.ts Outdated
@RealKai42

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: d9e84f7efa

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

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

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

Reviewed commit: d9e84f7efa

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.

@RealKai42
RealKai42 merged commit 9f7e68e into main Sep 10, 2026
15 checks passed
@RealKai42
RealKai42 deleted the fix/mcp-attachment-originals branch September 10, 2026 02:37
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