fix: persist model name to .env so dotted names survive restart#426
Conversation
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 resolves a critical configuration issue where LLM model names, particularly those containing dots, were not correctly persisted across application restarts. The problem arose because the setup wizard saved 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 addresses the issue of persisting model names with dots by saving them to the .env file during setup. The changes are logical, introducing a centralized method for backend environment variables and applying fallbacks consistently. The added tests effectively verify the fix. I have one suggestion to refactor some duplicated code to improve maintainability, aligning with the practice of using specialized helpers for environment variable resolution.
| let model = optional_env("OPENAI_MODEL")? | ||
| .or_else(|| settings.selected_model.clone()) | ||
| .unwrap_or_else(|| "gpt-4o".to_string()); |
There was a problem hiding this comment.
This pattern for resolving the model name is now used in several places (NearAi, OpenAi, Anthropic, Ollama, OpenAiCompatible, Tinfoil). To improve maintainability and reduce code duplication, consider extracting this logic into a private helper function inside impl LlmConfig.
For example, you could add a helper function:
fn resolve_model(env_var: &str, settings: &Settings, default: &str) -> Result<String, ConfigError> {
Ok(optional_env(env_var)?
.or_else(|| settings.selected_model.clone())
.unwrap_or_else(|| default.to_string()))
}And then simplify the call sites:
let model = Self::resolve_model("OPENAI_MODEL", settings, "gpt-4o")?;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.
|
Re: Gemini Code Assist review feedback Verified false positive. Gemini suggests extracting a |
…ai#400) The setup wizard saved selected_model to the DB but not to .env. Since Config::from_env_with_toml() runs before the DB connects, the model name was lost on restart -- backends fell back to hardcoded defaults, truncating names like "llama3.2" to "llama3". - Add LlmBackend::model_env_var() as single source of truth for the backend-to-env-var mapping - Write the model env var in write_bootstrap_env() using the new method - Add selected_model fallback to all 6 backends (was missing from OpenAI, Anthropic, Ollama, and Tinfoil) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address review feedback: the env → settings → default model resolution pattern was repeated across all 6 backends. Centralise it in a single LlmConfig::resolve_model() helper. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c0dd0e7 to
1515a52
Compare
…ai#426) * fix: persist model name to .env so dotted names survive restart (nearai#400) The setup wizard saved selected_model to the DB but not to .env. Since Config::from_env_with_toml() runs before the DB connects, the model name was lost on restart -- backends fell back to hardcoded defaults, truncating names like "llama3.2" to "llama3". - Add LlmBackend::model_env_var() as single source of truth for the backend-to-env-var mapping - Write the model env var in write_bootstrap_env() using the new method - Add selected_model fallback to all 6 backends (was missing from OpenAI, Anthropic, Ollama, and Tinfoil) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: extract resolve_model() helper to reduce duplication Address review feedback: the env → settings → default model resolution pattern was repeated across all 6 backends. Centralise it in a single LlmConfig::resolve_model() helper. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
…ai#426) * fix: persist model name to .env so dotted names survive restart (nearai#400) The setup wizard saved selected_model to the DB but not to .env. Since Config::from_env_with_toml() runs before the DB connects, the model name was lost on restart -- backends fell back to hardcoded defaults, truncating names like "llama3.2" to "llama3". - Add LlmBackend::model_env_var() as single source of truth for the backend-to-env-var mapping - Write the model env var in write_bootstrap_env() using the new method - Add selected_model fallback to all 6 backends (was missing from OpenAI, Anthropic, Ollama, and Tinfoil) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: extract resolve_model() helper to reduce duplication Address review feedback: the env → settings → default model resolution pattern was repeated across all 6 backends. Centralise it in a single LlmConfig::resolve_model() helper. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Fixes #400.
selected_modelto the DB but not to.env. SinceConfig::from_env_with_toml()runs before the DB connects, the model name was lost on restart -- backends fell back to hardcoded defaults, truncating names likellama3.2tollama3.LlmBackend::model_env_var()as single source of truth for backend-to-env-var mappingwrite_bootstrap_env()now writes the model env var using the new methodselected_modelfallback to all 6 backends (was missing from OpenAI, Anthropic, Ollama, and Tinfoil)Test plan
cargo test-- all 1814 tests passcargo clippy --all --benches --tests --examples --all-features-- zero warningsopenai_compatiblewith a dotted model name (e.g.llama3.2), restart, verify model name is preserved in configGenerated with Claude Code