Skip to content

Agent Zero AI framework

Refresh context indicator after clearing chat

Alessandro9f0db8ad046d
diff --git a/plugins/_context_window/AGENTS.md b/plugins/_context_window/AGENTS.md
index 7748c7463..fea48f33c 100644
--- a/plugins/_context_window/AGENTS.md
+++ b/plugins/_context_window/AGENTS.md
@@ -41,8 +41,9 @@
restores the accepted response after the accounting tail is drained.
- Responses API turns keep their native result and callback behavior unchanged.
- Older chats without a stored breakdown show the explanatory empty state.
-- The indicator refreshes once per new Agent 0 generation and again when the
- run completes; streamed updates to the same generation do not refetch it.
+- The indicator refreshes once per new Agent 0 generation, when the run
+ completes, and when the active chat log GUID changes (including Clear Chat);
+ streamed updates to the same generation do not refetch it.
- `_model_config` supplies the effective model limit and the
`model-context-strip-end` WebUI slot; it does not own this feature's state.
- The `contextWindowUsage` Interface setting defaults to visible on mobile and
diff --git a/plugins/_context_window/extensions/webui/apply_snapshot_before/refresh-context-window.js b/plugins/_context_window/extensions/webui/apply_snapshot_before/refresh-context-window.js
index 5a21adbd5..51a17cdd5 100644
--- a/plugins/_context_window/extensions/webui/apply_snapshot_before/refresh-context-window.js
+++ b/plugins/_context_window/extensions/webui/apply_snapshot_before/refresh-context-window.js
@@ -3,6 +3,7 @@ import { store as contextWindowStore } from "/plugins/_context_window/webui/cont
const OVERRIDE_REVISION_KEY = "_model_config_override_revision";
let lastContextId = "";
let lastRevision = null;
+let lastLogGuid = "";
let lastGenerationKey = "";
function latestGenerationKey(logs) {
@@ -21,6 +22,7 @@ export default async function refreshContextWindow(ctx) {
if (!contextId) {
lastContextId = "";
lastRevision = null;
+ lastLogGuid = "";
lastGenerationKey = "";
return;
}
@@ -28,15 +30,18 @@ export default async function refreshContextWindow(ctx) {
const contexts = Array.isArray(snapshot?.contexts) ? snapshot.contexts : [];
const active = contexts.find(item => item?.id === contextId) || null;
const revision = active?.[OVERRIDE_REVISION_KEY] || null;
+ const logGuid = String(snapshot?.log_guid || "");
const generationKey = latestGenerationKey(snapshot?.logs);
if (
contextId === lastContextId
&& revision === lastRevision
+ && logGuid === lastLogGuid
&& (!generationKey || generationKey === lastGenerationKey)
) return;
lastContextId = contextId;
lastRevision = revision;
+ lastLogGuid = logGuid;
if (generationKey) lastGenerationKey = generationKey;
await contextWindowStore.refresh(contextId);
}
diff --git a/plugins/_context_window/tests/test_context_window.py b/plugins/_context_window/tests/test_context_window.py
index b97bba481..04ae433b3 100644
--- a/plugins/_context_window/tests/test_context_window.py
+++ b/plugins/_context_window/tests/test_context_window.py
@@ -194,6 +194,8 @@ def test_webui_and_accounting_are_plugin_owned():
assert "rpartition(" not in helper
assert 'item?.type !== "agent"' in refresh_hook
assert "Number(item.agentno || 0) !== 0" in refresh_hook
+ assert 'const logGuid = String(snapshot?.log_guid || "")' in refresh_hook
+ assert "logGuid === lastLogGuid" in refresh_hook
assert "generationKey === lastGenerationKey" in refresh_hook