Skip to content

fix(images): compress oversized attachments before upload - #590

Merged
agegr merged 1 commit into
agegr:mainfrom
jiangguishan:deepseek-image-optimization
Aug 25, 2026
Merged

fix(images): compress oversized attachments before upload#590
agegr merged 1 commit into
agegr:mainfrom
jiangguishan:deepseek-image-optimization

Conversation

@jiangguishan

@jiangguishan jiangguishan commented Aug 24, 2026

Copy link
Copy Markdown

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

  • Images up to 1 MiB are preserved unchanged.
  • GIFs are preserved to avoid dropping animation.
  • Larger images are resized to a maximum 1024px side and encoded as JPEG at 0.85 quality.
  • Compression is used only when it produces a smaller payload.
  • Decode/canvas failures fall back to the original image through FileReader.

Verification

  • TypeScript: tsc --noEmit
  • Lint: npm run lint -- --quiet
  • Tests: 682 passed (npm test)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread components/ChatInput.tsx Outdated
Comment on lines +243 to +247
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 };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread hooks/useAgentSession.ts Outdated
try {
if (showLoading) setLoading(true);
const params = new URLSearchParams({ deferThinking: "1", deferMedia: "1" });
const params = new URLSearchParams({ deferThinking: "1" });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@agegr
agegr force-pushed the deepseek-image-optimization branch from 7a8331f to 10df85b Compare August 25, 2026 14:43
@agegr agegr changed the title feat(images): compress large attachments and render tool-result images fix(images): compress oversized attachments before upload Aug 25, 2026
@agegr
agegr merged commit 9d7cd52 into agegr:main Aug 25, 2026
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.

2 participants