Skip to content

fix: align v1 protocol handshake and tool_result media passthrough#1630

Merged
sailist merged 4 commits into
MoonshotAI:mainfrom
sailist:fix/heartbeat-and-media-parts
Jul 13, 2026
Merged

fix: align v1 protocol handshake and tool_result media passthrough#1630
sailist merged 4 commits into
MoonshotAI:mainfrom
sailist:fix/heartbeat-and-media-parts

Conversation

@sailist

@sailist sailist commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — this PR fixes two independent protocol-alignment bugs found while developing against kap-server.

Problem

  1. Spec-compliant clients rejected the server handshake. kap-server dropped the server-initiated WS heartbeat and no longer emits heartbeat_ms in server_hello, but the published v1 schema still required the field, so clients validating against the schema rejected the handshake before subscribing.
  2. Media parts were lost in tool_result projection (v2). Tool results carrying image/video/audio content parts were flattened to text in the agent-core-v2 message projection, so media produced by tools such as ReadMediaFile no longer rendered after a session reload or resume.

What changed

1. Make heartbeat_ms optional in server_hello

  • Marked heartbeat_ms optional in serverHelloPayloadSchema (advisory only).
  • Added a ws-control test for a server_hello without heartbeat_ms.
  • Aligned kimi-web WireServerHello and the server-e2e handshake assertion with the relaxed schema.

2. Pass media parts through tool_result projection

  • Keep the raw kosong content-part array for tool results carrying image/video/audio parts instead of flattening them to text.
  • This restores ReadMediaFile media rendering after session reload/resume on the v2 server backend.
  • Added projector test coverage for tool exchanges carrying media parts.

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.

sailist added 3 commits July 13, 2026 22:17
kap-server dropped the server-initiated WS heartbeat and no longer emits
heartbeat_ms in server_hello, but the published v1 schema still required
it, so spec-compliant clients rejected the handshake before subscribing.

- mark heartbeat_ms optional in serverHelloPayloadSchema (advisory only)
- add a ws-control test for a server_hello without heartbeat_ms
- align kimi-web WireServerHello and the server-e2e handshake assertion
- keep raw kosong content-part array for tool results carrying
  image/video/audio parts instead of flattening to text
- restore ReadMediaFile media rendering after session reload/resume
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 431ec76

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

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/protocol Patch
@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 13, 2026

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

commit: 431ec76

@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: 47c74d68de

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

/**
* Build the protocol-shaped `Message.content[]` for one history entry:
* 1. `tool` role → a single `tool_result` part.
* 1. `tool` role → a single `tool_result` part. Plain-text results keep the

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 Move v2 projection notes to the module header

packages/agent-core-v2/AGENTS.md requires comments in this tree to live solely in the top-of-file block and never beside functions, methods, or statements. These newly added media-passthrough details extend the function JSDoc, so touching this file leaves it out of compliance; move the rationale into the module header or remove the per-function commentary.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in 431ec76 — moved the media-passthrough rationale into the module header and trimmed the per-function JSDoc back to its previous form.

Per the agent-core-v2 comment conventions, comments live solely in the
top-of-file block — move the media-passthrough rationale out of the
buildProtocolContent JSDoc into the module header.
@sailist sailist merged commit 0303b82 into MoonshotAI:main Jul 13, 2026
23 of 24 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 14, 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