[Bug] Compaction truncation drops media parts from kept user messages
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
Hướng nghiên cứu
Start with packages/agent-core-v2/src/agent/contextMemory/compactionHandoff.ts, especially replaceMessageText and the truncation paths at lines 269–277 and 375–377. Then inspect the compaction tests under packages/agent-core-v2/test/... and add a regression case for a kept user message with text and an image_url part at a truncation boundary. Done means truncation shortens the text while preserving the media part.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What version of Kimi Code is running?
2.6.3 (source main snapshot, 2026-11-18). Confirmed by reading the compaction handoff code.
Which open platform/subscription were you using?
None involved (code-level audit).
Which model were you using?
None involved (code-level audit).
What platform is your computer?
Windows 11 x64.
What issue are you seeing?
When compaction truncates a kept user message, any media parts (images/audio/video) in that message are deleted, not just the text.
packages/agent-core-v2/src/agent/contextMemory/compactionHandoff.ts:363-373:
function replaceMessageText<T extends MessageLike>(message: T, text: string): T {
return {
...message,
content: [
...message.content.filter(
(part) => isUserPromptSubmitHookPart(part) || isSkillActivationPart(part),
),
{ type: 'text', text },
],
} as unknown as T;
}
replaceMessageText is used by truncateUserMessage (:375-377) and by the tail-boundary truncation path (:269-277). The filter keeps only hook and skill-activation parts, so every image_url / audio_url / video_url part is dropped. Text truncation is expected; deleting the attachment is not.
This only happens to messages that do not fit the 20K COMPACT_USER_MESSAGE_MAX_TOKENS budget, but it is easiest to hit with a long message that also carries a screenshot: the newest user input survives, the image silently does not.
The existing tests (packages/agent-core-v2/test/...) compare live and resumed contexts after compaction, and both sides apply the same truncation, so they stay equal while the image is gone. There is no assertion that non-text parts survive truncation.
What steps can reproduce the bug?
- Build a session whose user messages exceed
COMPACT_USER_MESSAGE_MAX_TOKENS(20,000 estimated tokens). - Include one recent user message that has both a long text body and an image part, positioned at the head or tail truncation boundary.
- Run
/compact. - Inspect the rebuilt history: the message contains only text, and the image part is missing.
A unit test can call selectCompactionUserMessages with a message that does not fit the budget and assert that replaceMessageText/truncateUserMessage preserves image_url parts.
What is the expected behavior?
Truncation should shorten only the text. Media parts in a kept user message should be preserved (or explicitly replaced with the existing media placeholder logic), not dropped without a trace.
Additional information
Suggested fix: make replaceMessageText keep all non-text parts, not just hook/skill parts, and replace only the text content. If a message has multiple text parts, concatenate them before truncation and emit a single truncated text part while leaving media parts intact. A regression test should assert that an image_url part survives a boundary truncation.
Contribution
- I am willing to submit a PR for this bug fix myself (please wait for maintainer approval in this issue first)
- Ngôn ngữ chính
- TypeScript
- Star
- 8.3k
- Fork
- 1.4k
- Merge trung bình
- 12 giờ 6 phút
- Pull request đã merge (30 ngày)
- 596
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của MoonshotAI/kimi-code
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
MoonshotAI/kimi-code#5539 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Kimi RC workspace folder picker does not display symbolic link directoriesCó thể đã có người làm @markankamaransheogarat-sys đã nhận 2 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
MoonshotAI/kimi-code#5296 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
MoonshotAI/kimi-code#5256 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
MoonshotAI/kimi-code#5062 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
MoonshotAI/kimi-code#5057 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của MoonshotAI/kimi-code
Issue tương tự
-
Add Alice&BotĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
slavakurilyak/awesome-ai-agents#1048 ·
-
bot:ai-assisted component:faucet github_actions security status:untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
midnightntwrk/midnight-faucet-api#215 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[功能] 手机端命令执行显示 AI 动作描述Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
NanmiCoder/cc-haha#2034 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mobile prio:low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
digitalfabrik/entitlementcard#3324 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày