fix(cli): preserve runtime-added models when saving settings#2455
Merged
tanzhenxin merged 2 commits intoQwenLM:mainfrom Apr 5, 2026
Merged
fix(cli): preserve runtime-added models when saving settings#2455tanzhenxin merged 2 commits intoQwenLM:mainfrom
tanzhenxin merged 2 commits intoQwenLM:mainfrom
Conversation
LaZzyMan
approved these changes
Mar 18, 2026
Collaborator
LaZzyMan
left a comment
There was a problem hiding this comment.
Review Summary
This PR correctly fixes #2454 by changing the settings persistence strategy from rewriting the entire snapshot to applying incremental patches.
Strengths
- ✅ Correct fix: The patch-based approach preserves externally added models
- ✅ Good test coverage: Regression test validates the fix
- ✅ Minimal changes: Only touches necessary code paths
- ✅ Clear documentation: PR description explains the problem and solution well
Code Quality
- Clean implementation of helper
- Proper type safety maintained
- No security concerns
LGTM - Approved.
LaZzyMan
approved these changes
Mar 18, 2026
Collaborator
LaZzyMan
left a comment
There was a problem hiding this comment.
Review Summary
This PR correctly fixes #2454 by changing the settings persistence strategy from rewriting the entire snapshot to applying incremental patches.
Strengths
- Correct fix: The patch-based approach preserves externally added models
- Good test coverage: Regression test validates the fix
- Minimal changes: Only touches necessary code paths
- Clear documentation: PR description explains the problem and solution well
Code Quality
- Clean implementation of createSettingsUpdate() helper
- Proper type safety maintained
- No security concerns
LGTM - Approved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
This PR fixes
#2454by changing settings persistence to write only the updated setting patch instead of rewriting the entire in-memory settings snapshot. This preserves models manually added tosettings.jsonwhile Qwen Code is already running and a later/modelchange updatesmodel.name.Dive Deeper
Before this change,
LoadedSettings.setValue()updated the in-memory settings object and then calledsaveSettings()with the fulloriginalSettingspayload that was loaded at startup. If the user manually edited~/.qwen/settings.jsonwhile the CLI was still running, any newly addedmodelProvidersentries only existed on disk, not in memory. A later/modelswitch rewrote the file from the stale snapshot and silently dropped those externally added models.This change narrows persistence to the key being updated:
LoadedSettings.setValue()now builds a nested patch for the changed path, such asmodel.namesaveSettings()applies that patch withupdateSettingsFilePreservingFormat()I also added a regression test that simulates:
settings.jsonsettings.setValue(SettingScope.User, 'model.name', ...)Reviewer Test Plan
~/.qwen/settings.jsonand append a second model entry under the same provider./modelto switch to the newly added model.~/.qwen/settings.jsonstill contains both model entries and onlymodel.namechanged.Automated verification run for this patch:
npx vitest run packages/cli/src/config/settings.test.tsnpx vitest run packages/cli/src/utils/commentJson.test.tsnpx eslint packages/cli/src/config/settings.ts packages/cli/src/config/settings.test.tsnpm run build --workspace=@qwen-code/qwen-codeTesting Matrix
Linked issues / bugs
Fixes #2454