Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-pandas-strip-media.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Fix context compaction for text-only models by retrying rejected image content without media.
1 change: 1 addition & 0 deletions packages/agent-core-v2/src/kosong/contract/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ const IMAGE_FORMAT_PROVIDER_MESSAGE_PATTERNS = [

const IMAGE_FORMAT_STATUS_MESSAGE_PATTERNS = [
/unsupported image (?:url|format|type)/,
/unknown variant [`'"]?image_url[`'"]?/,
/does not represent a valid image/,
/could not (?:process|decode) (?:the |input )?image/,
/unable to process (?:the |input )?image/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ describe('FullCompaction', () => {
);
if (hasMedia) {
sawMedia = true;
throw new APIStatusError(400, 'unsupported image format: image/avif');
throw new APIStatusError(400, 'unknown variant image_url, expected text');
}
sawStrippedResend = true;
return textResult('Recovered compacted summary.');
Expand Down
12 changes: 12 additions & 0 deletions packages/agent-core-v2/test/kosong/contract/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
classifyApiError,
createAbortError,
isAbortError,
isImageFormatError,
isRetryableGenerateError,
normalizeAPIStatusError,
throwIfAbortError,
Expand Down Expand Up @@ -131,6 +132,17 @@ describe('isRetryableGenerateError', () => {
});
});

describe('isImageFormatError', () => {
it('recognizes providers that reject the image_url content variant', () => {
const error = new APIStatusError(
400,
'messages[124]: unknown variant image_url, expected text at line 1 column 811568',
);

expect(isImageFormatError(error)).toBe(true);
});
});

describe('classifyApiError', () => {
it('classifies typed errors and carries the status code', () => {
expect(classifyApiError(new APIContextOverflowError(400, 'context length exceeded'))).toEqual({
Expand Down