fix(memory): Fix event listener leaks in TUI and Slack bot#9147
fix(memory): Fix event listener leaks in TUI and Slack bot#9147sauerdaniel wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate PRs Found
These PRs appear to target the same memory leak issues, particularly around TUI event listener cleanup. Review their implementation status to ensure no duplicated work. |
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
0feb0fe to
cf73908
Compare
|
Rebased onto latest dev and resolved merge conflicts.\n\nChanges:\n- tooltip.tsx: Added imports (children, onCleanup, onMount) and event listener cleanup logic\n- sync.tsx: Auto-merged successfully\n- slack/index.ts: Auto-merged successfully\n\nAll typechecks pass. Ready for review. |
1988a3a to
f4fd64a
Compare
Clean up SDK event listeners on unmount in TUI sync context and improve Slack bot session management to prevent leaks. TUI changes (sync.tsx): - Store unsubscribe function from sdk.event.listen() - Call unsubscribe in onCleanup handler Slack changes: - Add lastUsed timestamp to sessions - Add periodic cleanup of old sessions (1 hour timeout) - Add graceful shutdown handlers for SIGINT/SIGTERM - Limit max sessions to prevent unbounded growth
f4fd64a to
fab3aed
Compare
|
Status update: implementation is complete and linked issue coverage remains intact ( Current blocker is CI only:
No new code changes pending on this PR right now. |
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.