opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix(tui): prevent UI freezes from clipboard operations and event loop

Open coleleavitt opened this issue 1 week ago • 2 comments

Summary

  • Replace Bun.$ with node:child_process in clipboard.ts to avoid GC crashes caused by Bun shell interpreter bug
  • Add debouncing to clipboard copy operations (100ms) to prevent rapid-fire clipboard access
  • Add yield point in SDK event loop to prevent render thread starvation

Problem

TUI would intermittently freeze, especially when clipboard operations were triggered. Root cause traced to Bun shell interpreter GC bug (oven-sh/bun#23177) where the shell interpreter is freed while still in use.

Solution

  1. clipboard.ts: Replaced all Bun.$ usage with Node.js child_process (spawn, execSync) which doesn't have this issue
  2. app.tsx: Added debouncedCopy() function wrapping all 4 clipboard copy calls with 100ms debounce
  3. sdk.tsx: Added await new Promise((r) => setTimeout(r, 0)) after flush to yield to render thread

Testing

Manual testing confirms UI no longer freezes during clipboard operations.

Related

  • Bun bug: oven-sh/bun#23177
  • Fix PR to Bun: oven-sh/bun#25916

coleleavitt avatar Jan 09 '26 00:01 coleleavitt