fix(setup): preserve model name when re-running onboarding with same provider#694
fix(setup): preserve model name when re-running onboarding with same provider#694
Conversation
…provider (#600) Each provider setup function unconditionally cleared selected_model, so re-running the wizard with "Keep current provider? Yes" would lose the model name, forcing the user to re-select it every time. Now only clears selected_model when the backend actually changes (old model may be invalid for the new provider). When keeping the same provider, the model is preserved and Step 4 shows the "Keep current model" prompt. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello, 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 onboarding process where the user's previously selected language model was inadvertently cleared when re-configuring the same LLM provider. The changes introduce conditional logic to ensure that the selected model is only reset if the user switches to a different provider, thereby preserving their choice when re-onboarding with the existing one. This enhancement streamlines the user experience by preventing unnecessary re-selection of models. 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 correctly fixes the issue where the selected model was being cleared unconditionally when re-running the onboarding process. The logic to only clear the model when the provider changes is sound, and the changes have been applied consistently across all relevant setup functions. The addition of regression tests is also a great improvement to ensure this behavior is maintained.
I have one suggestion regarding code duplication that has been introduced. Consolidating the repeated logic into a helper method would improve the maintainability of the code, aligning with established patterns for minimizing boilerplate and maintaining consistency. Please see my specific comment for details.
| // Clear model only when switching providers (old model may be invalid) | ||
| if self.settings.llm_backend.as_deref() != Some("anthropic") { | ||
| self.settings.selected_model = None; | ||
| } | ||
| self.settings.llm_backend = Some("anthropic".to_string()); |
There was a problem hiding this comment.
This logic for conditionally clearing selected_model and updating llm_backend is now duplicated in four places (setup_anthropic_oauth, setup_api_key_provider, setup_ollama_generic, setup_openai_compatible_generic) and also in the new tests. To improve maintainability and reduce code duplication, consider extracting this into a helper method on SetupWizard. This aligns with the principle of using specialized helper functions to minimize boilerplate and maintain consistency across similar operations.
For example, you could add a method like this:
/// Sets the LLM backend, clearing the selected model if the provider has changed.
fn set_llm_backend(&mut self, backend_id: &str) {
if self.settings.llm_backend.as_deref() != Some(backend_id) {
self.settings.selected_model = None;
}
self.settings.llm_backend = Some(backend_id.to_string());
}Then, you can replace the repeated blocks in all four setup_* functions with a single call, e.g., self.set_llm_backend("anthropic");.
This would also allow you to simplify the new tests by calling this helper method instead of duplicating the logic there as well. The tests would become more robust as they would test the behavior of the helper method directly, rather than being coupled to the implementation details.
References
- Use specialized helper functions like
parse_option_env<T>when resolving environment variables intoOption<T>fields to minimize boilerplate and maintain consistency across configuration files.
Summary
setup_api_key_provider,setup_ollama_generic,setup_openai_compatible_generic,setup_anthropic_oauth) unconditionally clearedselected_modeltoNone, even when the user kept the same providerselected_modelwhen the backend actually changes, so Step 4 correctly shows "Keep current model?" when re-onboarding with the same providerTest plan
test_same_provider_preserves_selected_model-- verifies model survives re-selecting same backendtest_different_provider_clears_selected_model-- verifies model is cleared when switching backendscargo clippy --all --all-featurescleancargo fmtcleanGenerated with Claude Code