Skip to content

Conversation

@sauerdaniel
Copy link
Contributor

@sauerdaniel sauerdaniel commented Jan 17, 2026

Summary

Add proper cleanup for ACP (Agent Communication Protocol) sessions to prevent resource leaks from orphaned sessions.

Fixes #9154
Relates to #5363

Problem

When ACP sessions are created:

  1. Sessions may not be properly cleaned up when the parent process ends
  2. Event listeners may not be removed
  3. Orphaned sessions can accumulate

Solution

Add proper session lifecycle management:

  • Track active sessions
  • Clean up sessions on process exit
  • Remove event listeners properly

Changes

  • packages/opencode/src/acp/session.ts - Add session cleanup logic

Testing

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

Note: Manual ACP session cleanup testing was not performed.

Add cleanup mechanism for ACP session map and event streams to prevent
unbounded growth. Implements proper session lifecycle management.
@github-actions
Copy link
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.

@github-actions
Copy link
Contributor

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

No duplicate PRs found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak: ACP session event streams never aborted

1 participant