Desktop app freezes when clicking binary executable files in file tree #7936

Open
opened 2026-02-16 18:08:43 -05:00 by yindo · 1 comment
Owner

Originally created by @RecoveryAshes on GitHub (Jan 29, 2026).

Originally assigned to: @adamdotdevin on GitHub.

Description

When clicking on a binary executable file (e.g., compiled Go binary, or any executable without extension) in the file tree of the desktop/web app, the application freezes/hangs. CPU and memory usage do not max out, but the UI becomes completely unresponsive.

Steps to Reproduce

  1. Open OpenCode desktop app
  2. Navigate to a project that contains compiled binary files (e.g., bin/ directory with Go executables)
  3. Click on a binary executable file in the file tree
  4. The app freezes

Root Cause Analysis

The issue is in packages/opencode/src/file/index.ts - the File.read() function lacks proper binary file detection.

Current flow:

Click file in tree → file.load() → API /file/content → File.read()

Problem in File.read() (line 279-324):

const encode = await shouldEncode(bunFile)

if (encode) {
  // Reads entire file into memory and converts to base64
  const buffer = await bunFile.arrayBuffer()
  const content = Buffer.from(buffer).toString("base64")
  return { type: "text", content, mimeType, encoding: "base64" }
}

// If not detected as binary, tries to read as text
const content = await bunFile.text()

The shouldEncode() function relies primarily on MIME type detection, which is insufficient for:

  • Executables without extensions (common on macOS/Linux)
  • Files detected as application/octet-stream

This causes:

  1. Backend: Large executable files (tens of MB) loaded entirely into memory and converted to base64
  2. Network: Huge base64 string transferred to frontend
  3. Frontend: Code highlighting component attempts to render massive string → browser freezes

Irony

The AI tool's ReadTool (packages/opencode/src/tool/read.ts) has robust binary detection:

  • Extension checking (.exe, .so, .bin, .dll, etc.)
  • Null byte detection
  • Non-printable character ratio check (>30%)

But File.read() used by the file browser doesn't use this logic!

Suggested Fix

  1. Add the isBinaryFile() detection from tool/read.ts to File.read() in file/index.ts
  2. Return an error or special marker for binary executables instead of attempting to read
  3. Add file size limits for preview
  4. Display a friendly "Cannot preview binary file" message instead of attempting to render

Environment

  • Platform: macOS
  • App: Desktop/Web UI
  • Binary file type: Go-compiled executable (no extension)

Related Code

  • packages/opencode/src/file/index.ts - File.read() (missing binary protection)
  • packages/opencode/src/tool/read.ts - isBinaryFile() (has proper detection)
  • packages/app/src/context/file.tsx - file.load()
  • packages/app/src/pages/session.tsx - File rendering
Originally created by @RecoveryAshes on GitHub (Jan 29, 2026). Originally assigned to: @adamdotdevin on GitHub. ## Description When clicking on a binary executable file (e.g., compiled Go binary, or any executable without extension) in the file tree of the desktop/web app, the application freezes/hangs. CPU and memory usage do not max out, but the UI becomes completely unresponsive. ## Steps to Reproduce 1. Open OpenCode desktop app 2. Navigate to a project that contains compiled binary files (e.g., `bin/` directory with Go executables) 3. Click on a binary executable file in the file tree 4. The app freezes ## Root Cause Analysis The issue is in `packages/opencode/src/file/index.ts` - the `File.read()` function lacks proper binary file detection. ### Current flow: ``` Click file in tree → file.load() → API /file/content → File.read() ``` ### Problem in `File.read()` (line 279-324): ```typescript const encode = await shouldEncode(bunFile) if (encode) { // Reads entire file into memory and converts to base64 const buffer = await bunFile.arrayBuffer() const content = Buffer.from(buffer).toString("base64") return { type: "text", content, mimeType, encoding: "base64" } } // If not detected as binary, tries to read as text const content = await bunFile.text() ``` The `shouldEncode()` function relies primarily on MIME type detection, which is insufficient for: - Executables without extensions (common on macOS/Linux) - Files detected as `application/octet-stream` This causes: 1. **Backend**: Large executable files (tens of MB) loaded entirely into memory and converted to base64 2. **Network**: Huge base64 string transferred to frontend 3. **Frontend**: Code highlighting component attempts to render massive string → **browser freezes** ### Irony The AI tool's `ReadTool` (`packages/opencode/src/tool/read.ts`) has robust binary detection: - Extension checking (`.exe`, `.so`, `.bin`, `.dll`, etc.) - Null byte detection - Non-printable character ratio check (>30%) But `File.read()` used by the file browser doesn't use this logic! ## Suggested Fix 1. Add the `isBinaryFile()` detection from `tool/read.ts` to `File.read()` in `file/index.ts` 2. Return an error or special marker for binary executables instead of attempting to read 3. Add file size limits for preview 4. Display a friendly "Cannot preview binary file" message instead of attempting to render ## Environment - Platform: macOS - App: Desktop/Web UI - Binary file type: Go-compiled executable (no extension) ## Related Code - `packages/opencode/src/file/index.ts` - `File.read()` (missing binary protection) - `packages/opencode/src/tool/read.ts` - `isBinaryFile()` (has proper detection) - `packages/app/src/context/file.tsx` - `file.load()` - `packages/app/src/pages/session.tsx` - File rendering
yindo added the perfweb labels 2026-02-16 18:08:43 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 29, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #10916: OpenCode refuses to read ".PNG" images - also related to binary file detection issues

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 29, 2026): This issue might be a duplicate of existing issues. Please check: - #10916: OpenCode refuses to read ".PNG" images - also related to binary file detection issues Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7936