fix: correct MIME type detection for Computer Use screenshots#261
Closed
amDosion wants to merge 2 commits intoclaude-code-best:mainfrom
Closed
fix: correct MIME type detection for Computer Use screenshots#261amDosion wants to merge 2 commits intoclaude-code-best:mainfrom
amDosion wants to merge 2 commits intoclaude-code-best:mainfrom
Conversation
added 2 commits
April 13, 2026 20:22
…y, KAIROS activation, openclaw autonomy Squashed merge of: 1. fix/mcp-tsc-errors — 修复上游 MCP 重构后的 tsc 错误和测试失败 2. feat/pipe-mute-disconnect — Pipe IPC 逻辑断开、/lang 命令、mute 状态机 3. feat/stub-recovery-all — 实现全部 stub 恢复 (task 001-012) 4. feat/kairos-activation — KAIROS 激活解除阻塞 + 工具实现 5. codex/openclaw-autonomy-pr — 自治权限系统、运行记录、managed flows Conflicts resolved: - src/commands/assistant/assistant.tsx (stub-recovery + kairos) - src/services/api/openai/__tests__/queryModelOpenAI.test.ts (mcp-fix + autonomy) Tested: bun test (2695 pass, 0 fail)
The original detectMimeFromBase64() compared raw byte magic numbers (0x89, 0xFF, etc.) against charCodeAt(0) of a base64-encoded string. Base64 encoding transforms byte values, so none of the conditions ever matched and the function always returned the default "image/png" — causing API 400 errors when screenshots were actually JPEG. Fix: decode the first 12 raw bytes from the base64 string and check standard magic byte signatures directly: - PNG: 89 50 4E 47 - JPEG: FF D8 FF (covers all marker variants) - WebP: RIFF header + WEBP at bytes 8-11 (precise, won't match WAV/AVI) - GIF: "GIF" prefix (covers GIF87a and GIF89a)
Contributor
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR introduces a comprehensive autonomy subsystem with daemon state management, background session handling, template job creation, language preferences, and pipe muting infrastructure. It adds Changes
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Possibly related PRs
Suggested reviewers
✨ Finishing Touches🧪 Generate unit tests (beta)
|
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
detectMimeFromBase64()was comparing raw byte magic numbers against base64-encoded characters — base64 transforms byte values so no condition ever matched, always returningimage/png400 invalid_request_error: image was specified using image/png but appears to be image/jpegChanges
packages/@ant/computer-use-mcp/src/toolCalls.ts— rewritedetectMimeFromBase64():Buffer.from(b64.slice(0, 16), "base64")to get raw bytes89 50 4E 47(4-byte signature)FF D8 FF(3-byte, covers all JFIF/EXIF/DQT variants)RIFF(bytes 0-3) +WEBP(bytes 8-11), won't false-positive on WAV/AVIGIFprefix (covers GIF87a and GIF89a)Verification
Buffer.from().toString('base64')computationtsc --noEmitpasses with zero new errorsTest plan
400API errorimage/jpegSummary by CodeRabbit
Release Notes
en/zh/auto) via/langcommandps,logs,kill, andattachcommands for session control