Skip to content

fix(cli): stabilize resetFileSearchState closure in useAtCompletion#24971

Closed
spencer426 wants to merge 1 commit intomainfrom
fix/useatcompletion-closure
Closed

fix(cli): stabilize resetFileSearchState closure in useAtCompletion#24971
spencer426 wants to merge 1 commit intomainfrom
fix/useatcompletion-closure

Conversation

@spencer426
Copy link
Copy Markdown
Contributor

@spencer426 spencer426 commented Apr 8, 2026

Summary

Stabilizes the resetFileSearchState closure in useAtCompletion to prevent stale React Fiber nodes from being kept alive in memory.

Details

In useAtCompletion.ts, resetFileSearchState captured an initial stale closure to the Ink/React FiberNodes and held it forever in the global workspace context event listener. Wrapping the function in useCallback ensures a stable, non-stale closure.

This is 4 of 4 atomic PRs split from the monolithic memory leak PR #24963.

Related Issues

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

@spencer426 spencer426 requested a review from a team as a code owner April 8, 2026 21:07
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented Apr 8, 2026

Hi @spencer426, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this.

We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines.

Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed.

Thank you for your understanding and for being a part of our community!

@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 memory management issue within the useAtCompletion hook. By stabilizing the resetFileSearchState function, the changes ensure that event listeners and effects do not retain stale references to component state, improving the overall stability and memory footprint of the CLI UI.

Highlights

  • Closure Stabilization: Wrapped the resetFileSearchState function in useCallback to ensure a stable reference across renders.
  • Memory Leak Prevention: Updated useEffect dependencies to prevent stale closures from holding onto React Fiber nodes, effectively mitigating potential memory leaks.
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 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 counter productive. 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
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2026

You already have 7 pull requests open. Please work on getting existing PRs merged before opening more.

@github-actions github-actions Bot closed this Apr 8, 2026
Copy link
Copy Markdown
Contributor

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

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 updates the useAtCompletion hook in packages/cli to wrap the resetFileSearchState function in a useCallback hook. It also updates the dependency arrays of related useEffect hooks to include resetFileSearchState, ensuring stable function identity and correct effect execution. I have no feedback to provide.

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.

1 participant