fix: sanitize OpenAI compat gateway images and surface streaming errors#2062
Open
BingqingLyu wants to merge 5 commits into
Open
fix: sanitize OpenAI compat gateway images and surface streaming errors#2062BingqingLyu wants to merge 5 commits into
BingqingLyu wants to merge 5 commits into
Conversation
…ompat endpoint Gateway-provided images (via OpenAI compat /v1/chat/completions) bypassed the sanitization/resize pipeline because detectAndLoadPromptImages() early- returned existingImages unsanitized when no image refs were found in prompt text. Large images (e.g. Mac Retina screenshots) hit Anthropic's 5MB limit. Additionally, in streaming mode, when a lifecycle "error" event fired before the async catch block, the stream was closed with only [DONE] and no error content — silently swallowing the failure. Fixes openclaw#59913 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…or path Set sawAssistantDelta before emitting the lifecycle error event in the catch block, so the lifecycle handler skips writing a second error chunk. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
25 tasks
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
Fixes openclaw#59913
/v1/chat/completionsimage_urlparts) bypassed the sanitization/resize pipeline.detectAndLoadPromptImages()early-returnedexistingImagesunsanitized when no image refs were found in the prompt text. Large images (e.g. Mac Retina screenshots >5MB) were forwarded to Anthropic at full resolution, hitting the 5MB per-image limit.stream: true), when a lifecycle"error"event fired before the async catch block could run, the stream was closed with onlydata: [DONE]— the error was completely swallowed and the client received no error content.Changes
src/agents/pi-embedded-runner/run/images.ts: ApplysanitizeImagesWithLog()toexistingImageson the early-return path (no prompt image refs detected)src/gateway/openai-http.ts: Write error content chunk in the lifecycle"error"handler before closing the stream, when no assistant content was already sentTest plan
existingImagesare sanitized even when prompt has no image references (images.test.ts)openai-http.test.ts)AI-assisted: Built with Claude Code. Fully tested locally. I understand what the code does.
🤖 Generated with Claude Code