fix(images): compress oversized attachments before upload - #590
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df47d24e14
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!bitmap) { | ||
| // Can't decode; fall back to the original file so the image is still sent. | ||
| const raw = await file.arrayBuffer(); | ||
| const base64 = btoa(String.fromCharCode(...new Uint8Array(raw))); | ||
| return { data: base64, mimeType: file.type }; |
There was a problem hiding this comment.
Avoid spreading the fallback buffer into
fromCharCode
When createImageBitmap rejects a selected image (for example, a HEIC/TIFF image or malformed image), this passes one argument per byte to String.fromCharCode. V8 throws a RangeError at roughly 125K arguments, while this picker accepts images up to 10MB, so such a file makes the async attachment operation reject and it is never added. Encode in chunks or retain the prior FileReader fallback instead.
Useful? React with 👍 / 👎.
| try { | ||
| if (showLoading) setLoading(true); | ||
| const params = new URLSearchParams({ deferThinking: "1", deferMedia: "1" }); | ||
| const params = new URLSearchParams({ deferThinking: "1" }); |
There was a problem hiding this comment.
Preserve deferred loading for historical tool-result images
Removing deferMedia makes every session-open response include every base64 tool-result image, even though the corresponding tool blocks remain collapsed. Tool output is not constrained or recompressed by the new upload path, so existing sessions with accumulated screenshots can now transfer and parse tens or hundreds of megabytes every time they are opened (and the same change occurs on branch-context loads), causing severe stalls or failed loads. Keep these blobs deferred and fetch the selected result's image when it is expanded.
Useful? React with 👍 / 👎.
7a8331f to
10df85b
Compare
Summary
Compresses oversized image attachments in the browser before they enter the conversation, reducing repeated base64 payload growth and avoiding provider/gateway HTTP 413 errors.
Tool-result image rendering is intentionally left to #499, which already provides inline rendering with lazy history loading.
Behavior
Verification
tsc --noEmitnpm run lint -- --quietnpm test)