Skip to content

fix(web): keep ReadMediaFile media rendering after session resume - #1552

Merged
wbxl2000 merged 1 commit into
mainfrom
fix/web-resume-media-tool
Jul 11, 2026
Merged

fix(web): keep ReadMediaFile media rendering after session resume#1552
wbxl2000 merged 1 commit into
mainfrom
fix/web-resume-media-tool

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Related Issue

No tracking issue — this is a clear, reproducible rendering bug; the problem is explained below.

Problem

In the web UI, a ReadMediaFile tool call renders as an image card while the session is streaming, but after resuming the session or reloading the page it degrades to a generic ReadMediaFile tool card — the image is gone.

The two delivery paths disagree on the tool-result payload shape:

  • Live (WS): the tool.result event carries output as the raw kosong content-part array ([text('<image path="…">'), image_url, text('</image>')]), which the web client parses into the media card.
  • Resume (REST snapshot / messages): the protocol projection flattened tool-role message content to text only (non-text parts became ''), so output arrived as "<image path=\"…\"></image>" — the media bytes never left the server, and the client fell back to the generic card. (The wire log on disk keeps the full parts; they were dropped only at projection time.)

What changed

  • In the shared protocol message projection (toProtocolMessage, used by both the snapshot and messages endpoints), a tool result that carries image/video/audio parts now passes the raw content-part array through as tool_result.output — the same shape the live event stream already sends. Text-only results keep the historical flattened string, so the common case is byte-identical. The protocol field is z.unknown() and the web client already parses both shapes, so no schema or client changes were needed.
  • Tests: agent-core projection now asserts media parts pass through (and text-only results still flatten to a string); kimi-web turn logic asserts a snapshot-shaped ReadMediaFile result surfaces as a media card.
  • Verified: agent-core suite (3736 tests) and kimi-web suite (390 tests) pass; agent-core / server / kimi-web typechecks clean.

This fits Kimi Code because it removes the divergence at its source — one canonical payload shape for both delivery paths — instead of adding a second, lossy recovery path in the client. Old sessions are fixed retroactively since the media bytes were always preserved in the wire log.

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. (Bug fix only — no user-facing behavior to document.)

Tool-role messages reached the snapshot/messages REST projection with
their content flattened to text, dropping image/video/audio parts, so a
ReadMediaFile result rendered as an image while streaming but fell back
to a generic tool card after a reload. Pass the raw content parts
through when a tool result carries media, matching the live tool.result
event shape the web client already parses.
@changeset-bot

changeset-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 762cde4

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 11, 2026

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

commit: 762cde4

@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 762cde4223

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wbxl2000
wbxl2000 merged commit 37bb4b8 into main Jul 11, 2026
11 checks passed
@wbxl2000
wbxl2000 deleted the fix/web-resume-media-tool branch July 11, 2026 13:11
@github-actions github-actions Bot mentioned this pull request Jul 11, 2026
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