Skip to content

fix: model config settings lost after scope change (fixes #1518)#1603

Open
revworxai wants to merge 1 commit into
agent0ai:mainfrom
revworxai:fix/1518-model-config-scope-save
Open

fix: model config settings lost after scope change (fixes #1518)#1603
revworxai wants to merge 1 commit into
agent0ai:mainfrom
revworxai:fix/1518-model-config-scope-save

Conversation

@revworxai
Copy link
Copy Markdown

Problem

When changing the Project/Agent Profile scope in Settings → Model Configuration, user edits are silently discarded. The scoped config.json file is created at the correct path, but it contains the unchanged fallback/global config instead of the user's modifications.

For example: selecting Project + Agent Profile, changing Main Model from Opus → Sonnet, and clicking Save results in a config file that still shows Opus.

Fixes #1518

Root Cause

In plugins/_model_config/webui/config.html, each model section captures a static reference at render time:

x-data="{ model: config[section.key], ... }"

When the user changes scope (Project/Agent Profile), plugin-settings-store.js calls loadSettings() which replaces context.settings with a new object:

this.settings = result.ok ? (result.data || {}) : {};

The model variable in the child x-data scope still references the old object. User edits via x-model="model.name" modify the stale object, while save() serializes the new (unmodified) object.

A secondary issue: initConfigFields(config) only runs once in x-init, so _kwargs_text fields are never re-initialized after a scope change.

Fix

Two changes to plugins/_model_config/webui/config.html:

  1. Use a getter so model always resolves from the current config object:
- x-data="{ model: config[section.key], modelType: ...
+ x-data="{ get model() { return config[section.key]; }, modelType: ...
  1. Add a $watch to re-initialize kwargs text fields when config changes after scope switch:
  $store.modelConfig.installSettingsHooks(context, config);
+ $watch('config', (val) => $store.modelConfig.initConfigFields(val));

Testing

  1. Open Settings → Config Models
  2. Select a Project + Agent Profile combination that has no existing scoped config
  3. Observe the "Settings do not yet exist for this combination" info message
  4. Change the Main Model name to something distinctive (e.g., Opus → Sonnet)
  5. Click Save
  6. Reopen Settings → Config Models
  7. Re-select the same Project + Agent Profile
  8. Before fix: Model reverts to the global value (Opus)
  9. After fix: Model shows the saved value (Sonnet) and the info message is gone

Also verified:

  • Global scope save still works correctly (no regression)
  • Advanced Settings kwargs fields re-initialize properly after scope change
  • Per-Chat Override toggle persists correctly at scoped level

v2: watch scope identifiers (projectName, agentProfileKey) instead of
the deep config object. v1 used $watch('config', ...) which fired on
every keystroke in the kwargs textarea (because _kwargs_text lives on
config.chat_model), causing initConfigFields to revert user edits.
@revworxai revworxai force-pushed the fix/1518-model-config-scope-save branch from b1356fb to 2e3e345 Compare May 5, 2026 00:14
@revworxai
Copy link
Copy Markdown
Author

Update — v2 of the fix

Force-pushed a corrected version. The original commit had a regression that I caught during further testing on a real instance.

What changed: The first version added $watch('config', (val) => initConfigFields(val)) to re-initialize _kwargs_text after a scope change. Because Alpine's $watch on an object is a deep watcher, it fired on every mutation inside config — including each keystroke in the kwargs <textarea> (which writes to model._kwargs_text living on config.chat_model). initConfigFields would then reset _kwargs_text from the unchanged kwargs object, reverting the keystroke. Net effect: the kwargs field appeared frozen — characters could not be deleted.

Fix: Watch the scope identifiers (primitives) instead of the deep config object. context.projectName and context.agentProfileKey only change when the user actually picks a different scope from the dropdowns:

$watch('context.projectName',     () => $store.modelConfig.initConfigFields(config));
$watch('context.agentProfileKey', () => $store.modelConfig.initConfigFields(config));

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.

Plugin settings not saved correctly when using per-agent profile scope

1 participant