Agent Zero AI framework
Preserve unchanged chat-list state
Alessandro392611f9d9ea
diff --git a/tests/test_webui_chat_deletion.py b/tests/test_webui_chat_deletion.pyindex 129bddfa0..2132ff695 100644--- a/tests/test_webui_chat_deletion.py+++ b/tests/test_webui_chat_deletion.py@@ -57,6 +57,7 @@ function assert(condition, message) {{function reset(contexts, selected) {{model.contexts = contexts.map((context) => ({{ ...context }}));+ model.contextsJson = "";model.selected = selected;model.selectedContext = model.contexts.find((context) => context.id === selected);model.deletedContextIds = {{}};@@ -69,6 +70,36 @@ const chats = [{{ id: "c", created_at: 10 }},];+reset(chats, "");+model.applyContexts(chats);+const unchangedContexts = model.contexts;+model.applyContexts(chats.map((context) => ({{ ...context }})));+assert(+ model.contexts === unchangedContexts,+ "unchanged snapshots must preserve the Alpine contexts array",+);+model.applyContexts([{{ ...chats[0], name: "Renamed" }}, ...chats.slice(1)]);+assert(+ model.contexts !== unchangedContexts && model.contexts[0].name === "Renamed",+ "changed context metadata must replace the contexts array",+);++const tree = [+ {{ id: "parent", created_at: 20 }},+ {{ id: "child", parent_context_id: "parent", created_at: 10 }},+];+reset(tree, "");+model.applyContexts(tree);+const unchangedTree = model.contexts;+model.selected = "parent";+model.expandedParents = {{}};+model.applyContexts(tree.map((context) => ({{ ...context }})));+assert(model.contexts === unchangedTree, "unchanged chat trees must preserve identity");+assert(+ model.expandedParents.parent === true,+ "selection synchronization must still run for unchanged contexts",+);+reset(chats, "b");globalThis.__context = "a";await model.selectChat("a");diff --git a/webui/components/sidebar/AGENTS.md b/webui/components/sidebar/AGENTS.mdindex 68ae23586..895ccc60c 100644--- a/webui/components/sidebar/AGENTS.md+++ b/webui/components/sidebar/AGENTS.md@@ -32,6 +32,7 @@- The utility-message preference controls both individual utility steps and utility-only process-group chrome so hidden utility runs cannot leave empty headers in the transcript.- Chat deletion removes the sidebar row optimistically in the same render batch as fallback selection. Keep successful local deletion tombstones for the page session so out-of-order poll or push snapshots cannot reinsert rows; restore the row and clear its tombstone if the delete request fails.- Chat selection must synchronize the sidebar store even when the low-level context has already switched to the requested ID.+- Unchanged context snapshots preserve the Alpine contexts-array identity to avoid chat-list reconciliation, while selection and parent-expansion synchronization still run; changed metadata and deletion tombstones must still replace the visible list.## Work Guidancediff --git a/webui/components/sidebar/chats/chats-store.js b/webui/components/sidebar/chats/chats-store.jsindex 1f608f0e7..5347ddf9d 100644--- a/webui/components/sidebar/chats/chats-store.js+++ b/webui/components/sidebar/chats/chats-store.js@@ -17,6 +17,7 @@ import { store as chatInputStore } from "/components/chat/input/input-store.js";const model = {contexts: [],+ contextsJson: "",selected: "",selectedContext: null,loggedIn: false,@@ -58,9 +59,14 @@ const model = {const incomingContexts = Array.isArray(contextsList) ? contextsList : [];// Sort by created_at time (newer first)- this.contexts = incomingContexts+ const nextContexts = incomingContexts.filter((context) => !this.deletedContextIds[context?.id]).sort((a, b) => (b.created_at || 0) - (a.created_at || 0));+ const contextsJson = JSON.stringify(nextContexts);+ if (contextsJson !== this.contextsJson) {+ this.contextsJson = contextsJson;+ this.contexts = nextContexts;+ }// Keep selectedContext in sync when the currently selected context's// metadata changes (e.g. project activation/deactivation).