[PR #7914] fix(core): add dispose functions to prevent subscription memory leaks #12564

Open
opened 2026-02-16 18:17:28 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7914

State: open
Merged: No


Summary

Re-implementation of #7032 rebased cleanly on current dev branch (original had merge conflicts).

  • Add dispose() functions to Share, ShareNext, Plugin, and Format namespaces
  • Add cleanupSession() and dispose() to ACP Agent for event subscription cleanup
  • Add Bus._getSubscriptionCount() test helpers
  • Add memory tests to verify subscription cleanup works correctly

Problem

Bus subscriptions accumulate during extended use because return values from Bus.subscribe() were ignored. This contributes to memory exhaustion during long sessions.

Solution

Each module now stores unsubscribe functions and provides dispose() to clean them up:

  • ShareNext: Tracks all 4 subscriptions, clears pending timeout queue on dispose
  • Share: Tracks subscription with disposed flag check
  • Plugin/Format: Store and cleanup subscription references
  • ACP Agent: Uses AbortController per session to cancel event streams

All 12 memory tests pass.

Supersedes #7032
Fixes #3013

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7914 **State:** open **Merged:** No --- ## Summary Re-implementation of #7032 rebased cleanly on current dev branch (original had merge conflicts). - Add `dispose()` functions to Share, ShareNext, Plugin, and Format namespaces - Add `cleanupSession()` and `dispose()` to ACP Agent for event subscription cleanup - Add `Bus._getSubscriptionCount()` test helpers - Add memory tests to verify subscription cleanup works correctly ## Problem Bus subscriptions accumulate during extended use because return values from `Bus.subscribe()` were ignored. This contributes to memory exhaustion during long sessions. ## Solution Each module now stores unsubscribe functions and provides `dispose()` to clean them up: - **ShareNext**: Tracks all 4 subscriptions, clears pending timeout queue on dispose - **Share**: Tracks subscription with disposed flag check - **Plugin/Format**: Store and cleanup subscription references - **ACP Agent**: Uses `AbortController` per session to cancel event streams All 12 memory tests pass. Supersedes #7032 Fixes #3013
yindo added the pull-request label 2026-02-16 18:17:28 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12564