Skip to content

fix(vscode-ide-companion): add missing activate() Disposables#27936

Open
parveshsaini wants to merge 2 commits into
google-gemini:mainfrom
parveshsaini:parveshsaini/fix/vscode-companion-disposable-leak
Open

fix(vscode-ide-companion): add missing activate() Disposables#27936
parveshsaini wants to merge 2 commits into
google-gemini:mainfrom
parveshsaini:parveshsaini/fix/vscode-companion-disposable-leak

Conversation

@parveshsaini

Copy link
Copy Markdown

Summary

activate() in the VS Code companion extension wraps two groups of
registrations in an extra pair of parentheses, which turns each group into a
JavaScript comma expression instead of separate arguments to
context.subscriptions.push(...). A comma expression evaluates both operands
but yields only the last one, so the first registration in each group runs
but its Disposable is never pushed onto context.subscriptions — and is
therefore never disposed on deactivation.

Two Disposables leak today:

  • the gemini.diff.accept command, and
  • the onDidChangeWorkspaceFolders listener.

Impact:

  • On deactivation/reload within the same extension host (e.g. an extension
    update), gemini.diff.accept stays registered. Re-activation then throws
    command 'gemini.diff.accept' already exists.
  • The onDidChangeWorkspaceFolders listener is never torn down, so a stale
    listener keeps calling ideServer.syncEnvVars() against an IDEServer that
    has already been stopped.

Details

The two offending groups in packages/vscode-ide-companion/src/extension.ts:

// group 1
(vscode.commands.registerCommand('gemini.diff.accept', ...),
 vscode.commands.registerCommand('gemini.diff.cancel', ...)),

// group 2
(vscode.workspace.onDidChangeWorkspaceFolders(...),
 vscode.workspace.onDidGrantWorkspaceTrust(...)),

The surrounding registrations in the same two push() calls already use the
flat one-argument-per-Disposable style, which is what makes the two
parenthesized groups stand out as unintended. The fix removes the stray ( / )
around each group so every registration is its own argument to push().

This is a platform-independent defect (JavaScript comma-operator semantics),
present since the companion extension was introduced.

Related Issues

Closes #27790

How to Validate

npm test -w packages/vscode-ide-companion -- src/extension.test.ts

This PR adds a regression test, adds every registered disposable to context.subscriptions, to extension.test.ts. The existing vscode mock
returned undefined from registerCommand / the workspace listeners, which is
why the leak was invisible to the suite; the mock now returns a tagged
Disposable so the test can assert what actually lands in
context.subscriptions.

  • Without the fix, the new test fails — context.subscriptions is missing
    gemini.diff.accept and onDidChangeWorkspaceFolders
    (expected [ 'onDidCloseTextDocument', …(5) ] to include 'gemini.diff.accept');
    the suite reports 1 failed | 11 passed.
  • With the fix, all four registrations (gemini.diff.accept,
    gemini.diff.cancel, onDidChangeWorkspaceFolders,
    onDidGrantWorkspaceTrust) are present and the suite reports 12 passed.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@parveshsaini parveshsaini requested a review from a team as a code owner June 15, 2026 05:48
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug in the VS Code companion extension where certain command and workspace event registrations were failing to be disposed of properly due to incorrect syntax. By removing unintended comma expressions, the extension now correctly tracks these Disposables, preventing memory leaks and command registration conflicts during extension reloads.

Highlights

  • Fixed Disposable Leaks: Removed erroneous parentheses that created JavaScript comma expressions, ensuring all command and workspace event registrations are correctly pushed to context.subscriptions.
  • Regression Testing: Updated the VS Code mock in the test suite to return tagged Disposables and added a new test case to verify that all expected registrations are successfully added to the subscription list.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions Bot added the size/s A small PR label Jun 15, 2026
@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 50
  • Additions: +39
  • Deletions: -11
  • Files changed: 2

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality labels Jun 15, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request cleans up redundant parentheses in the VS Code extension activation code and updates the test suite to verify that registered disposables are correctly added to the context subscriptions. Feedback on the changes highlights a resource leak in the tests, where calling activate(context) starts an Express server that is never cleaned up, and recommends adding a deactivate() call in afterEach to prevent hanging test processes.

expect(vscode.workspace.onDidGrantWorkspaceTrust).toHaveBeenCalled();
});

it('adds every registered disposable to context.subscriptions', async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Resource Leak in Tests

Calling activate(context) starts an Express server on a random port via ideServer.start(context). Because deactivate() is never called in afterEach (or within the tests), these HTTP servers and their associated sockets are leaked for every test that executes activate(context). This can lead to port exhaustion, memory leaks, and hanging test processes, especially in CI or watch mode.

To resolve this, please import deactivate from ./extension.js and call it in afterEach to ensure proper cleanup:

import { activate, deactivate } from './extension.js';

// ...

afterEach(async () => {
  await deactivate();
  vi.restoreAllMocks();
});

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added deactivate() to afterEach to tear down the IDE server, plus a dispose mock on the output channel so cleanup doesn't throw. All 12 tests still pass ✅

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

Labels

area/core Issues related to User Interface, OS Support, Core Functionality priority/p2 Important but can be addressed in a future release. size/m A medium sized PR size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(vscode-ide-companion): comma operator in activate() leaks two Disposables (gemini.diff.accept, onDidChangeWorkspaceFolders)

1 participant