fix(cli): lazily load settings in onModelChange to prevent stale closure data loss#20403
fix(cli): lazily load settings in onModelChange to prevent stale closure data loss#20403KumarADITHYA123 wants to merge 2 commits intogoogle-gemini:mainfrom
Conversation
Summary of ChangesHello @KumarADITHYA123, 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 critical state-corruption defect in the CLI's configuration loading mechanism. By refactoring the Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a state corruption issue where onModelChange would use stale settings data captured at boot time. The fix is to lazily load the settings within the onModelChange callback, ensuring that the most recent configuration is always used when saving a model change. This change correctly resolves the bug and has the added benefit of removing a settings load from the startup path, which should improve initialization time. The implementation is consistent with the existing onReload handler, which uses a similar lazy-loading pattern.
OVERVIEW This PR structurally resolves a state-corruption defect inside loadCliConfig in packages/cli.
Previously, the onModelChange callback permanently, statically captured the loadedSettings object at boot time. If the CLI hot-reloaded or the config mutated on disk at runtime, any subsequent /model change would blindly write back to the .gemini file using outdated memory pointers, clobbering the user's latest config state.
FIX IMPLEMENTATION I converted the static memory capture into a dynamic, lazy-loaded functional request, mirroring the proven architecture of onReload:
Before: onModelChange: (model: string) => saveModelChange(loadedSettings, model) After: onModelChange: (model: string) => saveModelChange(loadSettings(cwd), model)
By decoupling this, we also permanently eliminated the redundant loadSettings(cwd) file system read at boot time. The unused loadedSettings variable definition was pruned to strictly satisfy ESLint no-unused-vars constraints. Both loadSettings(cwd) and saveModelChange remain fully synchronous, matching the original signature (model: string) => void.
TESTING
Verified strict function signature typing satisfies the backend backend requirements.
Verified local test suites pass flawlessly with the functional decoupling.
Fixes #20402