opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix(tui): clean up SDK event listeners on unmount

Open sauerdaniel opened this issue 1 week ago • 2 comments

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

sauerdaniel avatar Jan 13 '26 17:01 sauerdaniel

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

github-actions[bot] avatar Jan 13 '26 17:01 github-actions[bot]

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

github-actions[bot] avatar Jan 13 '26 17:01 github-actions[bot]