Skip to content

Agent Zero AI framework

Keep model presets bound after deletion

Alessandro529dc8c46552
diff --git a/plugins/_model_config/AGENTS.md b/plugins/_model_config/AGENTS.md
index 66b4c8aae..969cce154 100644
--- a/plugins/_model_config/AGENTS.md
+++ b/plugins/_model_config/AGENTS.md
@@ -20,6 +20,7 @@
- `model_config_get` exposes `model_configured` as a derived chat-model readiness flag from provider, model name, and API-key availability.
- Applying a model preset may inherit durable tuning such as context windows and rate limits, but must replace or clear per-slot `kwargs` so provider-specific extra params never leak across model providers.
- Repair provider-specific model-config aliases at the model-config read/build boundary; keep provider-specific repairs out of provider-agnostic core wrappers such as `models.py`.
+- Preset editor rows use stable UI-only keys; never key them by array position or editable preset name because deleting or renaming a row must not rebind nested model fields to another preset.
## Work Guidance
diff --git a/plugins/_model_config/webui/main.html b/plugins/_model_config/webui/main.html
index a7ba13605..6d3b54b7f 100644
--- a/plugins/_model_config/webui/main.html
+++ b/plugins/_model_config/webui/main.html
@@ -15,13 +15,16 @@
await $store.modelConfig.refreshApiKeyStatus();
">
<template x-if="$store.modelConfig._loaded && $store.modelConfig._presetsLoaded">
- <div class="presets-page" x-data="{ presets: JSON.parse(JSON.stringify($store.modelConfig.globalPresets)) }">
+ <div class="presets-page" x-data="{
+ presets: JSON.parse(JSON.stringify($store.modelConfig.globalPresets)).map((preset, idx) => ({ ...preset, _key: idx })),
+ nextPresetKey: $store.modelConfig.globalPresets.length
+ }">
<div class="presets-header">
<div class="field-title" style="font-size:1rem;">Model Presets</div>
<div class="field-description">Global presets shared across all projects and agents. Used by the model switcher in the chat area.</div>
</div>
- <template x-for="(preset, idx) in presets" :key="idx">
+ <template x-for="(preset, idx) in presets" :key="preset._key">
<div class="preset-card" x-data="{ expanded: false }">
<div class="preset-card-header" @click="expanded = !expanded">
<span class="material-symbols-outlined preset-expand-icon"
@@ -64,6 +67,7 @@
<button class="text-button preset-add-btn"
@click="
presets = [...presets, {
+ _key: nextPresetKey++,
name: 'Preset ' + (presets.length + 1),
chat: { provider: '', name: '', api_key: '', api_base: '', kwargs: {}, _kwargs_text: '' },
utility: { provider: '', name: '', api_key: '', api_base: '', kwargs: {}, _kwargs_text: '' }
diff --git a/tests/test_model_config_ui.py b/tests/test_model_config_ui.py
index 6a12713e2..9151d63b6 100644
--- a/tests/test_model_config_ui.py
+++ b/tests/test_model_config_ui.py
@@ -20,3 +20,12 @@ def test_model_config_text_buttons_have_shared_primitive() -> None:
assert 'class="text-button preset-add-btn"' in preset_modal
assert 'class="text-button preset-delete-btn"' in preset_modal
assert 'class="text-button"' in config_modal
+
+
+def test_model_preset_rows_keep_stable_identity_after_middle_delete() -> None:
+ preset_modal = read("plugins", "_model_config", "webui", "main.html")
+
+ assert ':key="preset._key"' in preset_modal
+ assert "_key: idx" in preset_modal
+ assert "_key: nextPresetKey++" in preset_modal
+ assert ':key="idx"' not in preset_modal