fix: prevent /model command from overwriting externally-added settings#2504
Open
Br1an67 wants to merge 1 commit intoQwenLM:mainfrom
Open
fix: prevent /model command from overwriting externally-added settings#2504Br1an67 wants to merge 1 commit intoQwenLM:mainfrom
Br1an67 wants to merge 1 commit intoQwenLM:mainfrom
Conversation
When setValue() saved settings, it passed the entire in-memory originalSettings object to the file writer. If the user had manually added entries to settings.json while the app was running (e.g. new model providers), those entries would be silently dropped because the stale in-memory copy did not contain them. This adds saveSettingsKey() which builds a minimal update containing only the changed key path, so all other file content is preserved. Closes QwenLM#2454
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
The
/modelcommand (and anysetValue()call) silently removes entries manually added tosettings.jsonwhile the app is running. This fix ensures only the changed key is written to disk.Dive Deeper
Root cause:
setValue()calledsaveSettings(settingsFile), which passed the entire in-memoryoriginalSettingsobject toupdateSettingsFilePreservingFormat(). The merge function (applyUpdates()) iterates over keys in the update object — for array-valued keys (likemodelProviders), the stale in-memory version completely replaces the on-disk version, silently dropping entries the user added after app startup.Fix: Added
saveSettingsKey(filePath, key, value)which:{ model: { name: "new-model" } })updateSettingsFilePreservingFormat()applyUpdates()only touches keys present in the update, all other file content is preservedThe existing
saveSettings()function is kept for backward compatibility but is no longer called fromsetValue().Testing Matrix
model.namepreserves amodelProvidersarray on diskCloses #2454