Skip to content

Conversation

@hendem
Copy link

@hendem hendem commented Jan 7, 2026

Fixes #3013

Summary

  • Add init(), dispose(), and clearSession() to PermissionNext namespace
  • Subscribe to session.deleted bus event to clean up orphaned pending permissions
  • Reject all pending permission requests when their session is deleted

Problem

When a session is deleted, any pending permission requests for that session remain in the pending map indefinitely. This causes:

  • Memory accumulation over time as pending entries are never removed
  • Orphaned promises that never resolve or reject

Solution

Subscribe to the session.deleted event and clean up all pending permissions for deleted sessions by:

  1. Rejecting pending promises with RejectedError
  2. Removing entries from the pending map

Testing

Added comprehensive tests in test/permission/cleanup.test.ts.

Copilot AI review requested due to automatic review settings January 7, 2026 02:09
@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

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

No duplicate PRs found

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds session cleanup functionality to the PermissionNext namespace to prevent memory leaks when sessions are deleted. It introduces init(), dispose(), and clearSession() methods that subscribe to session.deleted events and clean up orphaned pending permissions.

Key changes:

  • Adds event subscription mechanism to automatically clean up pending permissions when sessions are deleted
  • Introduces init() and dispose() functions to manage event subscriptions lifecycle
  • Adds clearSession() to reject and remove pending permissions for a specific session

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
packages/opencode/src/permission/next.ts Implements init(), dispose(), and clearSession() functions with session.deleted event subscription to clean up orphaned pending permissions
packages/opencode/test/permission/cleanup.test.ts Adds comprehensive test coverage for the new cleanup functionality including session clearing, event subscription, disposal, and duplicate init handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

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.

Mark Henderson added 3 commits January 10, 2026 14:09
Add init(), dispose(), and clearSession() to PermissionNext namespace
to properly clean up pending permission requests when a session is
deleted. This prevents memory accumulation from orphaned pending
entries that would never be resolved.

The fix subscribes to the session.deleted bus event and rejects all
pending permissions for that session, allowing proper garbage collection.
- Move subscriptions to per-instance state instead of module-level
- Add Event.Replied publishing in clearSession for consistency
- Make init() and dispose() async to work with instance state
- Remove unnecessary setTimeout delays in tests (Bus.publish awaits handlers)
Address Copilot review comments - import Session and use the proper
Session.Event.Deleted event definition instead of bypassing type
checking with manually constructed objects.
Mark Henderson and others added 3 commits January 10, 2026 14:09
This reverts commit 7b9bc5370b08ec55c543de381b88eaf9c050a139.

wip: zen

Reapply "wip: zen"

This reverts commit 09516ac8c3bb7c432b28cf63faa65c0e3b9f9684.
@fwang fwang force-pushed the fix/permission-approved-map-leak branch from 9f56615 to a9f2024 Compare January 10, 2026 19:11
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.

Uses a huge amount of memory

2 participants