MoonshotAI / MoonshotAI/kimi-code

[Bug]: VS Code session export corrupts emoji at the topic truncation boundary

Open Beginner friendly
#3,611 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

What version of Kimi Code is running?

VS Code extension 0.7.5, main@55685c58b5dbff692e16c66efa65fa6d32222f61

Which open platform/subscription were you using?

Not applicable. This reproduces in the deterministic local session export formatter without a model or API request.

Which model were you using?

Not applicable.

What platform is your computer?

Darwin 25.5.0 arm64 arm

What issue are you seeing?

The VS Code session Markdown exporter can split an emoji's UTF-16 surrogate pair when shortening the overview topic.

If an emoji crosses the 80-character truncation boundary, the exported topic ends with a replacement character:

- **Topic**: aaa�…

instead of preserving the emoji:

- **Topic**: aaa😀…

The full user message remains correct. Only the shortened overview topic is corrupted.

What steps can reproduce the bug?
  1. Check out main at 55685c58b5dbff692e16c66efa65fa6d32222f61.

  2. Add this focused test as apps/vscode/test/session-context.test.ts:

import type { ContextMessage } from "@moonshot-ai/kimi-code-sdk";
import { describe, expect, it } from "vitest";

import { buildExportMarkdown } from "../src/utils/session-context";

describe("buildExportMarkdown", () => {
  it("keeps surrogate pairs intact when shortening the topic", () => {
    const prefix = "a".repeat(79);
    const history = [
      {
        role: "user",
        content: [{ type: "text", text: `${prefix}😀 continues` }],
        toolCalls: [],
      } satisfies ContextMessage,
    ];

    const markdown = buildExportMarkdown({
      sessionId: "session-test",
      workDir: "/workspace",
      history,
      tokenCount: 0,
      now: new Date("2026-09-07T00:00:00.000Z"),
    });

    expect(markdown).toContain(`- **Topic**: ${prefix}😀…`);
  });
});
  1. Run:
pnpm --filter kimi-code exec vitest run \
  --config vitest.config.ts \
  test/session-context.test.ts
  1. The test fails because the topic contains �… instead of 😀….
What is the expected behavior?

Topic truncation should preserve complete Unicode code points. It should never produce an unpaired surrogate or a replacement character.

For this reproduction, the shortened topic should end with 😀….

Additional information

buildExportMarkdown shortens the first user message to 80 characters:

https://github.com/MoonshotAI/kimi-code/blob/55685c58b5dbff692e16c66efa65fa6d32222f61/apps/vscode/src/utils/session-context.ts#L30

The helper uses JavaScript string length and slice(), which operate on UTF-16 code units:

https://github.com/MoonshotAI/kimi-code/blob/55685c58b5dbff692e16c66efa65fa6d32222f61/apps/vscode/src/utils/session-context.ts#L216-L218

The duplicate search covered buildExportMarkdown, session export emoji, surrogate pair, and unpaired surrogate. No matching issue or active pull request was found.

Contribution
  • I am willing to submit a PR for this bug fix myself (please wait for maintainer approval in this issue first)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in apps/vscode/src/utils/session-context.ts, especially the topic-shortening helper around lines 216–218 and its use in buildExportMarkdown. Add the focused regression test at apps/vscode/test/session-context.test.ts, then run the provided Vitest command. Done means the test passes and truncation preserves the complete 😀 code point without producing �.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vscode
Domain
desktop
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
90/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.