GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(memory): Fix event listener leaks in TUI and Slack bot by sauerdaniel · Pull Request #9147 · anomalyco/opencode

Conversation

@sauerdaniel

@sauerdaniel sauerdaniel commented Jan 17, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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)

  • Sessions Map grows without bounds
  • No cleanup of old/stale sessions
  • No graceful shutdown handling

Solution

TUI Sync Context

Store and call unsubscribe function in onCleanup:

const unsubscribe = sdk.event.listen((e) => { ... })
onCleanup(unsubscribe)

Tooltip Component

Add proper cleanup in onCleanup handler.

Slack Bot

  • Add lastUsed timestamp to sessions
  • Add periodic cleanup of sessions older than 1 hour
  • Add MAX_SESSIONS limit (100)
  • Add graceful shutdown handlers for SIGINT/SIGTERM

Changes

  • packages/opencode/src/cli/cmd/tui/context/sync.tsx - Store and call unsubscribe
  • packages/ui/src/components/tooltip.tsx - Add event listener cleanup
  • packages/slack/src/index.ts - Add session management and shutdown handlers

Testing

  • TypeScript compilation passes (bun turbo typecheck)
  • Unit tests pass (725 tests, 0 failures)

Note: Manual TUI and Slack bot testing was not performed. Memory leak verification requires runtime memory profiling.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bnainar reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@github-actions github-actions Bot added the needs:issue label Jan 17, 2026
@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

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

Potential Duplicate PRs Found

  1. fix(tui): clean up SDK event listeners on unmount #8254 - fix(tui): clean up SDK event listeners on unmount

    • fix(tui): clean up SDK event listeners on unmount #8254
    • Why related: Directly addresses the same TUI sync context event listener cleanup issue mentioned in the current PR
  2. fix(core): add dispose functions to prevent subscription memory leaks #7032 - fix(core): add dispose functions to prevent subscription memory leaks

    • fix(core): add dispose functions to prevent subscription memory leaks #7032
    • Why related: Addresses core subscription memory leak cleanup mechanisms that may overlap with the event listener fixes

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jan 17, 2026
fix(memory): Fix timeout, interval, and subscription cleanup #9148
Closed
2 tasks done
@github-actions github-actions Bot removed the needs:issue label Jan 17, 2026
@github-actions github-actions Bot mentioned this pull request Jan 24, 2026
fix(opencode): memory leaks in session handling #10392
Closed
@thdxr
thdxr force-pushed the dev branch from cbab81f to 2d3c7a0 Compare January 30, 2026 04:49
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 00637c0 to 71e0ba2 Compare January 30, 2026 14:32
@thdxr
thdxr force-pushed the dev branch 3 times, most recently from f1ae801 to 08fa7f7 Compare January 30, 2026 14:37
@sauerdaniel
sauerdaniel force-pushed the pr/memory-tui branch from 0feb0fe to cf73908 Compare February 10, 2026 19:45
@sauerdaniel

sauerdaniel commented Feb 10, 2026

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Feb 11, 2026
[BUG/PERF] Severe Memory Leak and Disk Swell leading to System Kernel Panic (macOS) #12687
Closed
fix: resolve memory leaks and zombie processes from missing cleanup handlers #13183
Closed
@sauerdaniel
sauerdaniel force-pushed the pr/memory-tui branch 6 times, most recently from f4fd64a to fab3aed Compare February 16, 2026 11:06
@sauerdaniel

sauerdaniel commented Feb 16, 2026

Copy link
Copy Markdown
Contributor Author

Status update: implementation is complete and linked issue coverage remains intact (Fixes #9155).

Current blocker is CI only:

  • e2e (windows) fails with repeated NotFoundError
  • test (linux) then fails on the upstream gate because e2e is red

No new code changes pending on this PR right now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sauerdaniel sauerdaniel mentioned this pull request Feb 16, 2026
Memory leak: TUI and Slack bot event listeners not cleaned up #9155
Closed
@sauerdaniel
sauerdaniel force-pushed the pr/memory-tui branch from fab3aed to 892d61e Compare February 20, 2026 13:35
@sauerdaniel
fix(memory): Fix event listener memory leaks in TUI and Slack bot
40a921c
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
@sauerdaniel
sauerdaniel force-pushed the pr/memory-tui branch from 892d61e to 40a921c Compare February 20, 2026 13:39
This was referenced Feb 22, 2026
fix: cleanup SDK event listeners to prevent memory leaks #14635
Closed
fix: resolve memory leak issues across multiple subsystems #14650
Closed
@binarydoubling binarydoubling mentioned this pull request Mar 9, 2026
Multiple memory leaks cause unbounded RAM growth during extended TUI usage #16697
Closed
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
@github-actions

github-actions Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@sauerdaniel
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.