Memory leak: ACP session event streams never aborted #6634

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

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

Originally assigned to: @rekram1-node on GitHub.

Problem

In the ACP (Agent Communication Protocol) module, sessions and their event streams are not properly cleaned up:

  1. Session Map Growth - Sessions are stored in a Map but never removed when completed
  2. Event Stream Leaks - Event streams created via session.stream() are never aborted when sessions end
  3. No Disposal Mechanism - No dispose() method exists to clean up session resources

Code Location

  • packages/opencode/src/acp/agent.ts
  • packages/opencode/src/acp/session.ts
  • packages/opencode/src/acp/types.ts

Impact

  • Memory grows with each session that completes
  • Event stream listeners accumulate
  • No way to explicitly clean up session resources

Relates to #5363

Expected Behavior

  • Sessions should be removed from Map when completed
  • Event streams should be aborted when session ends
  • A dispose() method should be available for explicit cleanup
Originally created by @sauerdaniel on GitHub (Jan 17, 2026). Originally assigned to: @rekram1-node on GitHub. ## Problem In the ACP (Agent Communication Protocol) module, sessions and their event streams are not properly cleaned up: 1. **Session Map Growth** - Sessions are stored in a Map but never removed when completed 2. **Event Stream Leaks** - Event streams created via `session.stream()` are never aborted when sessions end 3. **No Disposal Mechanism** - No `dispose()` method exists to clean up session resources ### Code Location - `packages/opencode/src/acp/agent.ts` - `packages/opencode/src/acp/session.ts` - `packages/opencode/src/acp/types.ts` ### Impact - Memory grows with each session that completes - Event stream listeners accumulate - No way to explicitly clean up session resources Relates to #5363 ## Expected Behavior - Sessions should be removed from Map when completed - Event streams should be aborted when session ends - A `dispose()` method should be available for explicit cleanup
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 is part of a broader set of memory leak issues being tracked. While not direct duplicates, the following related issues address similar resource cleanup problems:

  • #5627: ACP event subscription architecture causes cross-session pollution and duplicate events
  • #9156: Memory leak: Uncleaned timeouts, intervals, and subscriptions
  • #9155: Memory leak: TUI and Slack bot event listeners not cleaned up
  • #9153: Memory leak: MCP OAuth transports not closed on retry or cancellation
  • #5363: opencode eating 70gb of memory (general memory consumption issue)

These issues share the root cause of incomplete resource cleanup across different OpenCode modules. Consider reviewing all related memory leak issues together for a comprehensive cleanup strategy.

@github-actions[bot] commented on GitHub (Jan 17, 2026): This issue is part of a broader set of memory leak issues being tracked. While not direct duplicates, the following related issues address similar resource cleanup problems: - #5627: ACP event subscription architecture causes cross-session pollution and duplicate events - #9156: Memory leak: Uncleaned timeouts, intervals, and subscriptions - #9155: Memory leak: TUI and Slack bot event listeners not cleaned up - #9153: Memory leak: MCP OAuth transports not closed on retry or cancellation - #5363: opencode eating 70gb of memory (general memory consumption issue) These issues share the root cause of incomplete resource cleanup across different OpenCode modules. Consider reviewing all related memory leak issues together for a comprehensive cleanup strategy.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6634