Skip to content

fix(kosong): degrade unsupported base64 image/video to placeholder instead of throwing - #1

Closed
xpzouying wants to merge 1 commit into
mainfrom
fix/anthropic-unsupported-media-placeholder
Closed

fix(kosong): degrade unsupported base64 image/video to placeholder instead of throwing#1
xpzouying wants to merge 1 commit into
mainfrom
fix/anthropic-unsupported-media-placeholder

Conversation

@xpzouying

Copy link
Copy Markdown
Owner

Related Issue

No issue — the problem is described below.

Problem

Reading a media file whose base64 media type Anthropic does not accept (e.g. an .avif mislabeled .jpg) hangs the session. ReadMediaFile succeeds and the image lands in history as a tool result; on the next request the Anthropic serializer throws Unsupported media type for base64 image while converting that history to the wire format. Because the whole history is resent every turn, every subsequent request hits the same throw — and compaction, which serializes the same history to summarize it, fails the same way, so the session cannot even recover on its own.

Only the Anthropic adapter throws here; it already degrades unsupported audio to a placeholder text block. Image and video should do the same.

What changed

In imageUrlPartToAnthropic / videoUrlPartToAnthropic, an unsupported base64 media type now returns a placeholder text block carrying the mime (e.g. (image omitted: unsupported format image/avif)) instead of throwing, mirroring the existing OMITTED_MEDIA_PLACEHOLDER audio path. History is left untouched — the placeholder is produced only at serialization time. The malformed-data-URL throw is kept (that is a real error). Tests updated and added for the image/video unsupported-format paths.

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.

…stead of throwing

An image or video whose base64 media type Anthropic does not accept (e.g. avif)
threw during request serialization. Since history is resent every turn, that
throw failed every request and even blocked compaction from recovering, hanging
the session. Return a placeholder text block carrying the mime instead,
mirroring the existing audio degradation.
@xpzouying

Copy link
Copy Markdown
Owner Author

Closing as redundant: upstream MoonshotAI#1536 (merged 2026-07-10) already fixes this comprehensively — a single image-format policy enforced at every ingestion point (ReadMediaFile refuses with a conversion command; MCP/REST/ACP replace with a text notice; turn.prompt/steer backstop) plus a 400-recovery media-stripped resend. This branch's change (degrading the Anthropic serializer throw) targets a path MoonshotAI#1536 already guards, and would remove the throw that MoonshotAI#1536 relies on as a recovery tripwire.

@xpzouying xpzouying closed this Jul 12, 2026
@xpzouying
xpzouying deleted the fix/anthropic-unsupported-media-placeholder branch July 12, 2026 13:55
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