Skip to content

fix: prevent /model command from overwriting externally-added settings#2504

Open
Br1an67 wants to merge 1 commit intoQwenLM:mainfrom
Br1an67:fix/settings-save-overwrites
Open

fix: prevent /model command from overwriting externally-added settings#2504
Br1an67 wants to merge 1 commit intoQwenLM:mainfrom
Br1an67:fix/settings-save-overwrites

Conversation

@Br1an67
Copy link
Copy Markdown
Contributor

@Br1an67 Br1an67 commented Mar 19, 2026

TLDR

The /model command (and any setValue() call) silently removes entries manually added to settings.json while the app is running. This fix ensures only the changed key is written to disk.

Dive Deeper

Root cause: setValue() called saveSettings(settingsFile), which passed the entire in-memory originalSettings object to updateSettingsFilePreservingFormat(). The merge function (applyUpdates()) iterates over keys in the update object — for array-valued keys (like modelProviders), 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:

  1. Builds a minimal update object containing only the changed key path (e.g., { model: { name: "new-model" } })
  2. Passes only this minimal object to updateSettingsFilePreservingFormat()
  3. Since applyUpdates() only touches keys present in the update, all other file content is preserved

The existing saveSettings() function is kept for backward compatibility but is no longer called from setValue().

Testing Matrix

  • All 87 existing settings tests pass
  • All 8 existing commentJson tests pass
  • New test: verifies that updating only model.name preserves a modelProviders array on disk

Closes #2454

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: /model command silently removes manually-added models from settings.json

1 participant