From e94d7a2e8184e9531e4c59205f20a5854d1f5380 Mon Sep 17 00:00:00 2001 From: Serge Alex Date: Mon, 9 Nov 2026 01:57:10 +0300 Subject: [PATCH] fix(panel): refresh memory stats periodically Previously __refreshStats() ran once at panel init. If the bridge was still starting (supervisor 5s delay), fetchBridge failed and the status line stayed stuck at WS: ? entries: 0 (always 0) until F5. Now: setInterval(__refreshStats, 30000) plus refresh after every successful health probe. --- content/content.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/content/content.js b/content/content.js index aef8c98..d932cf5 100644 --- a/content/content.js +++ b/content/content.js @@ -365,9 +365,16 @@ if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text canStart = true; }); setInterval(function () { - BRIDGE.health().then(function (r) { if (UI && UI.setConnected) UI.setConnected(!!(r && r.ok)); }); + BRIDGE.health().then(function (r) { + if (UI && UI.setConnected) UI.setConnected(!!(r && r.ok)); + if (r && r.ok) __refreshStats(); + }); }, 30000); __refreshStats(); + // Keep stats fresh: without this, if bridge was down at init, the panel + // stays stuck at "? 0 (always 0)" until F5. Refresh every 30s, and also + // immediately on every successful health probe. + setInterval(__refreshStats, 30000); }); }); function __refreshStats() { try { var DB = globalThis.DSH_BRIDGE; if (!UI || !UI.setStats) return; if (!DB || !DB.fetchBridge) { UI.setStats('?', 0, 0); return; } DB.fetchBridge('GET', '/memory/state').then(function (j) { var st = (j && j.ok && j.data) ? j.data : {}; var entries = st.entries || []; var total = entries.length; var alwaysN = entries.filter(function (e) { return e.importance === 'always' && e.state !== 'archive' && e.state !== 'done'; }).length; return DB.fetchBridge('GET', '/health').then(function (hj) { UI.setStats((hj && hj.ok && hj.workspace) || '?', total, alwaysN); }); }).catch(function (e) { console.warn('[dsh-memory] stats ' + String(e)); UI.setStats('?', 0, 0); }); } catch (e) { console.warn('[dsh-memory] stats ' + String(e)); } }