fix(compaction): filter media parts to prevent API error#1398
Merged
RealKai42 merged 4 commits intoMoonshotAI:mainfrom Mar 11, 2026
Merged
fix(compaction): filter media parts to prevent API error#1398RealKai42 merged 4 commits intoMoonshotAI:mainfrom
RealKai42 merged 4 commits intoMoonshotAI:mainfrom
Conversation
…xt compaction When context usage is high and auto-compaction triggers, media content parts (image_url, audio_url, video_url) were included in the compaction request. The Kimi API does not accept media parts in compaction messages, causing a 400 error: "the message contains an invalid part type: video_url". Filter out ImageURLPart, AudioURLPart, and VideoURLPart from compaction input, keeping only text and tool-related parts. Preserved (recent) messages retain their original media parts. Fixes MoonshotAI#1395 Fixes MoonshotAI#1390 Related: MoonshotAI#802
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When context usage is high (~85%+) and auto-compaction triggers, media content parts (
image_url,audio_url,video_url) are included in the compaction request sent to the Kimi API. The API rejects these with:This PR filters out
ImageURLPart,AudioURLPart, andVideoURLPartfrom the compaction input inSimpleCompaction.prepare(), while preserving media parts in recent (non-compacted) messages.Root cause:
compaction.py:177only filteredThinkPartbut let all media parts through:Changes
src/kimi_cli/soul/compaction.py— Filter media parts from compaction input (2-line change)tests/core/test_simple_compaction.py— Add 2 test cases:test_prepare_filters_out_media_parts— Verifies all 3 media types are strippedtest_prepare_preserves_media_parts_in_recent_messages— Verifies preserved messages keep media intactReproduction
Related
custom_instructionsupport)