Image attachments cause UI freeze — no compression, no payload pre-check
Summary
Sending image attachments through the OpenWork desktop app causes severe UI freeze and unresponsive sessions. Root cause is the frontend sending raw uncompressed images as data URLs via HTTP JSON body to opencode, with no size pre-check.
Steps to reproduce
- Open OpenWork desktop app
- Start a chat session
- Attach and send an image (> 1MB, e.g. a screenshot or photo)
- UI freezes / session becomes unresponsive
- Session must be manually deleted from
~/.local/share/opencode/storage/to recover
Root Cause
1. No image compression before sending
packages/app/src/app/components/session/composer.tsx:60-68:
const fileToDataUrl = (file: File) =>
new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onerror = () => reject(new Error("Failed to read attachment"));
// ...
reader.readAsDataURL(file); // Raw file, no compression
});
A 4MB PNG screenshot becomes a ~5.3MB data URL string, embedded directly in the JSON request body.
2. No payload size pre-check
The client checks MAX_ATTACHMENT_BYTES = 8 * 1024 * 1024 (8MB) against raw file size, but doesn't account for base64 encoding overhead (+33%) or JSON framing. There's no check against what the server can actually handle.
3. Storage bloat from large parts
opencode stores each message part (including the full base64 image) in storage/part/ files. A single image message can create 60+ MB part files, causing:
- Slow session loading when reading history
- Disk usage accumulation over time
Complete data flow
composer.tsx: FileReader.readAsDataURL(file) → raw data URL (no compression)
app.tsx: buildPromptParts() → FilePartInput.url → data URL as string in JSON
@opencode-ai/sdk: session.promptAsync() → HTTP POST with large JSON body
opencode server: createUserMessage() → stores full base64 in part files
Suggested Fix
- Compress images before encoding: Use canvas resize + JPEG transcode (max 2048px, quality 0.82, target < 1.5MB) in
addAttachments() - Move encoding off main thread: Use
createImageBitmap+OffscreenCanvasorTask.detachedto avoid UI blocking - Pre-check payload size: Estimate JSON body size before sending; show explicit error if too large
Environment
- OpenWork desktop app (Tauri, latest)
- opencode server (Bun/Hono)
- macOS 15 (Darwin 24.6.0), Apple Silicon, 16 GB RAM