[PR #8254] fix(tui): clean up SDK event listeners on unmount #12678

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

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

State: open
Merged: No


Summary

Fix memory leak in the TUI App component where SDK event listeners (onStdout, onStderr, onMessage, onFinished) are never unsubscribed.

Problem

In packages/tui/src/app.tsx, the useEffect hook sets up event listeners via sdk.on() calls but the cleanup function only calls sdk.stop() without removing the listeners. This causes:

  • Event listener accumulation over time
  • Memory retention of closed sessions
  • Potential duplicate event handling

Solution

  • Store unsubscribe functions returned by sdk.on()
  • Call all unsubscribe functions in the cleanup return
  • Ensures proper cleanup when component unmounts or session changes

Fixes #8258

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8254 **State:** open **Merged:** No --- ## Summary Fix memory leak in the TUI App component where SDK event listeners (onStdout, onStderr, onMessage, onFinished) are never unsubscribed. ## Problem In `packages/tui/src/app.tsx`, the `useEffect` hook sets up event listeners via `sdk.on()` calls but the cleanup function only calls `sdk.stop()` without removing the listeners. This causes: - Event listener accumulation over time - Memory retention of closed sessions - Potential duplicate event handling ## Solution - Store unsubscribe functions returned by `sdk.on()` - Call all unsubscribe functions in the cleanup return - Ensures proper cleanup when component unmounts or session changes Fixes #8258
yindo added the pull-request label 2026-02-16 18:17:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12678