fix(memory): Fix event listener leaks in TUI and Slack bot #9147
+62
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fix memory leaks from event listeners not being properly cleaned up in TUI components and the Slack bot.
Fixes #9155
Problems
1. TUI Sync Context (
sync.tsx)The
sdk.event.listen()call sets up event listeners but the returned unsubscribe function is never called.2. Tooltip Component (
tooltip.tsx)Mouse event listeners are added to elements but never removed on component unmount.
3. Slack Bot (
slack/index.ts)Solution
TUI Sync Context
Store and call unsubscribe function in
onCleanup:Tooltip Component
Add proper cleanup in
onCleanuphandler.Slack Bot
lastUsedtimestamp to sessionsMAX_SESSIONSlimit (100)Changes
packages/opencode/src/cli/cmd/tui/context/sync.tsx- Store and call unsubscribepackages/ui/src/components/tooltip.tsx- Add event listener cleanuppackages/slack/src/index.ts- Add session management and shutdown handlersTesting
bun turbo typecheck)Note: Manual TUI and Slack bot testing was not performed. Memory leak verification requires runtime memory profiling.