Memory leak: TUI and Slack bot event listeners not cleaned up #6637

Open
opened 2026-02-16 18:04:49 -05:00 by yindo · 2 comments
Owner

Originally created by @sauerdaniel on GitHub (Jan 17, 2026).

Originally assigned to: @rekram1-node on GitHub.

Problem

Several event listeners in the TUI and Slack bot are never cleaned up:

TUI Sync Context (sync.tsx)

The sdk.event.listen() call returns an unsubscribe function that is never called:

// Listener never cleaned up
sdk.event.listen((e) => { ... })

Tooltip Component (tooltip.tsx)

Mouse event listeners (mouseenter, mouseleave) are added to elements but never removed on component unmount, causing accumulation.

Slack Bot (slack/index.ts)

  • Sessions Map grows unbounded (no cleanup of old sessions)
  • No graceful shutdown handling (SIGINT/SIGTERM)
  • No limit on maximum concurrent sessions

Impact

  • Event listeners accumulate over component lifecycles
  • Sessions accumulate in Slack bot
  • Memory grows continuously in long-running processes

Relates to #5363

Expected Behavior

  • TUI event listeners should be unsubscribed in onCleanup
  • Tooltip should remove event listeners on unmount
  • Slack bot should clean up old sessions and handle shutdown
Originally created by @sauerdaniel on GitHub (Jan 17, 2026). Originally assigned to: @rekram1-node on GitHub. ## Problem Several event listeners in the TUI and Slack bot are never cleaned up: ### TUI Sync Context (`sync.tsx`) The `sdk.event.listen()` call returns an unsubscribe function that is never called: ```typescript // Listener never cleaned up sdk.event.listen((e) => { ... }) ``` ### Tooltip Component (`tooltip.tsx`) Mouse event listeners (`mouseenter`, `mouseleave`) are added to elements but never removed on component unmount, causing accumulation. ### Slack Bot (`slack/index.ts`) - Sessions Map grows unbounded (no cleanup of old sessions) - No graceful shutdown handling (SIGINT/SIGTERM) - No limit on maximum concurrent sessions ### Impact - Event listeners accumulate over component lifecycles - Sessions accumulate in Slack bot - Memory grows continuously in long-running processes Relates to #5363 ## Expected Behavior - TUI event listeners should be unsubscribed in `onCleanup` - Tooltip should remove event listeners on unmount - Slack bot should clean up old sessions and handle shutdown
yindo added the perf label 2026-02-16 18:04:49 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 17, 2026):

This issue appears to be part of a broader set of memory leak issues across the codebase. Please check these related issues for context:

  • #9154: Memory leak: ACP session event streams never aborted (Sessions Map cleanup)
  • #9156: Memory leak: Uncleaned timeouts, intervals, and subscriptions (General cleanup patterns)
  • #8258: Memory leak: SDK event listeners never unsubscribed in App component (TUI App event listeners)
  • #8259: Memory leak: Footer component only clears last timeout in recursive chain (TUI Footer timeouts)
  • #8257: Memory leak: MCP clients not closed before reassignment (MCP resource cleanup)
  • #9153: Memory leak: MCP OAuth transports not closed on retry or cancellation (MCP OAuth cleanup)
  • #5363: opencode eating 70gb of memory? (Original memory issue tracking)

While this issue specifically addresses TUI sync context, tooltip components, and Slack bot sessions, the underlying patterns (missing cleanup, unsubscribe functions ignored, unbounded collections) are consistent across these related issues. Consider coordinating fixes across all these issues to establish consistent cleanup patterns throughout the codebase.

@github-actions[bot] commented on GitHub (Jan 17, 2026): This issue appears to be part of a broader set of memory leak issues across the codebase. Please check these related issues for context: - #9154: Memory leak: ACP session event streams never aborted (Sessions Map cleanup) - #9156: Memory leak: Uncleaned timeouts, intervals, and subscriptions (General cleanup patterns) - #8258: Memory leak: SDK event listeners never unsubscribed in App component (TUI App event listeners) - #8259: Memory leak: Footer component only clears last timeout in recursive chain (TUI Footer timeouts) - #8257: Memory leak: MCP clients not closed before reassignment (MCP resource cleanup) - #9153: Memory leak: MCP OAuth transports not closed on retry or cancellation (MCP OAuth cleanup) - #5363: opencode eating 70gb of memory? (Original memory issue tracking) While this issue specifically addresses TUI sync context, tooltip components, and Slack bot sessions, the underlying patterns (missing cleanup, unsubscribe functions ignored, unbounded collections) are consistent across these related issues. Consider coordinating fixes across all these issues to establish consistent cleanup patterns throughout the codebase.
Author
Owner

@sauerdaniel commented on GitHub (Feb 16, 2026):

Status: fix is implemented in PR #9147. Remaining blocker is CI on e2e (windows) (NotFoundError), which cascades to the linux gate.

@sauerdaniel commented on GitHub (Feb 16, 2026): Status: fix is implemented in PR #9147. Remaining blocker is CI on `e2e (windows)` (`NotFoundError`), which cascades to the linux gate.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6637