Skip to content

fix(vscode-ide-companion): stop leaking gemini.diff.accept and onDidChangeWorkspaceFolders disposables#28526

Open
godququ5-code wants to merge 1 commit into
google-gemini:mainfrom
godququ5-code:fix/vscode-companion-disposable-leak
Open

fix(vscode-ide-companion): stop leaking gemini.diff.accept and onDidChangeWorkspaceFolders disposables#28526
godququ5-code wants to merge 1 commit into
google-gemini:mainfrom
godququ5-code:fix/vscode-companion-disposable-leak

Conversation

@godququ5-code

Copy link
Copy Markdown

Summary

Fixes #27790.

The two context.subscriptions.push(...) calls in activate() wrapped a pair of registrations in a stray parenthesis pair, collapsing them into a comma expression whose value was only the last operand. As a result the gemini.diff.accept command Disposable and the onDidChangeWorkspaceFolders listener Disposable were created but never added to context.subscriptions, so they were never disposed on deactivation. On re-activation within the same extension host this threw command 'gemini.diff.accept' already exists, and the stale onDidChangeWorkspaceFolders listener kept firing ideServer.syncEnvVars() against a stopped IDEServer.

  • Removed the extra parentheses so each registration is its own argument to push().
  • Added a regression test in extension.test.ts that tags the created Disposables and asserts both gemini.diff.accept and onDidChangeWorkspaceFolders land in context.subscriptions.

Test plan

  • cd packages/vscode-ide-companion && npm test (vitest): new test in extension.test.ts passes; existing tests unaffected.

…hangeWorkspaceFolders disposables

The two context.subscriptions.push(...) calls wrapped a pair of
registrations in a stray parenthesis pair, collapsing them into a comma
expression whose value was only the last operand. As a result the
`gemini.diff.accept` command Disposable and the `onDidChangeWorkspaceFolders`
listener Disposable were created but never added to context.subscriptions, so
they were never disposed on deactivation (re-activation then threw
'command already exists' and a stale listener kept firing).

Remove the extra parentheses so each registration is its own argument to
push(). Add a regression test that tags the created Disposables and asserts
both land in context.subscriptions.

Fixes google-gemini#27790
@godququ5-code
godququ5-code requested a review from a team as a code owner July 24, 2026 06:38
@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 resource leak issue where specific command and listener registrations were not being added to the extension's subscription list due to incorrect syntax. By removing the stray parentheses, these objects are now correctly tracked, ensuring they are properly disposed of during extension deactivation and preventing duplicate registration errors on re-activation.

Highlights

  • Fixed Disposable Registration: Removed incorrect parentheses in context.subscriptions.push() calls that were causing comma expressions, preventing some Disposables from being tracked and disposed of correctly.
  • Regression Testing: Added a new test case in extension.test.ts to verify that both the gemini.diff.accept command and the onDidChangeWorkspaceFolders listener are properly registered in context.subscriptions.
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 Jul 24, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 39
  • Additions: +35
  • Deletions: -4
  • Files changed: 2

@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 fixes a bug where certain VS Code command and listener registrations were wrapped in stray parentheses, causing them to be evaluated as comma expressions and preventing them from being tracked for disposal in context.subscriptions. A new test is added to verify that all created Disposables are correctly registered. The reviewer suggested using optional chaining when inspecting context.subscriptions in the test to avoid potential TypeError exceptions from undefined elements.

Comment on lines +159 to +162
expect(pushed.some((d) => d.command === 'gemini.diff.accept')).toBe(true);
expect(
pushed.some((d) => d.kind === 'onDidChangeWorkspaceFolders'),
).toBe(true);

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

Since some of the mocked VS Code APIs (such as onDidCloseTextDocument or registerTextDocumentContentProvider) return undefined by default in the test environment, context.subscriptions will contain undefined elements. Accessing d.command or d.kind directly on these elements will throw a TypeError: Cannot read properties of undefined. Use optional chaining (d?.command and d?.kind) to safely inspect the subscriptions.

Suggested change
expect(pushed.some((d) => d.command === 'gemini.diff.accept')).toBe(true);
expect(
pushed.some((d) => d.kind === 'onDidChangeWorkspaceFolders'),
).toBe(true);
expect(pushed.some((d) => d?.command === 'gemini.diff.accept')).toBe(true);
expect(
pushed.some((d) => d?.kind === 'onDidChangeWorkspaceFolders'),
).toBe(true);

@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 Jul 24, 2026
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/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