[PR #7395] fix(tui): prevent UI freezes from clipboard operations and event loop #12384

Closed
opened 2026-02-16 18:17:18 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7395

State: closed
Merged: No


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

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7395 **State:** closed **Merged:** No --- ## 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
yindo added the pull-request label 2026-02-16 18:17:18 -05:00
yindo closed this issue 2026-02-16 18:17:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12384