The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
fix(control-pane): judge a failed refresh by the loads that started after it
L4XB9848380309cf
diff --git a/scripts/lib/control-pane/ui.js b/scripts/lib/control-pane/ui.jsindex 2d7db4ae2..93d608371 100644--- a/scripts/lib/control-pane/ui.js+++ b/scripts/lib/control-pane/ui.js@@ -439,6 +439,10 @@ function renderControlPaneHtml() {// The board keeps the last snapshot on screen, so a failed refresh has to// say that the data is no longer live, and since when.let loadedAt = null;+ // Loads are numbered as they start, so a failed refresh can tell whether+ // the board already shows data from a load that started after it.+ let loadsStarted = 0;+ let shownLoad = 0;function showRefreshFailure(error) {const since = loadedAt? ' The data below is from ' + loadedAt.toLocaleString() + '.'@@ -635,6 +639,7 @@ function renderControlPaneHtml() {}async function load() {+ const id = ++loadsStarted;const url = new URL('/api/snapshot', window.location.href);if (state.query) url.searchParams.set('query', state.query);const response = await fetch(url);@@ -653,6 +658,7 @@ function renderControlPaneHtml() {executable: snapshot.execution.allowActions && action.executable})));loadedAt = new Date();+ shownLoad = id;clearError('#app');}@@ -693,11 +699,14 @@ function renderControlPaneHtml() {// Live board: refresh on a gentle interval; pause while a prompt/tab is hidden.setInterval(() => {if (document.hidden) return;- const shownSince = loadedAt;- load().catch(error => {- // A load that finished in the meantime already replaced the data this- // refresh was for, so its failure no longer describes the board.- if (loadedAt === shownSince) showRefreshFailure(error);+ const refresh = load();+ // load() numbers itself before its first await.+ const id = loadsStarted;+ refresh.catch(error => {+ // Data from a load that started later is already on the board, so+ // this failure no longer describes it. An older load that succeeded+ // in the meantime does not make the board live.+ if (shownLoad < id) showRefreshFailure(error);});}, 15000);diff --git a/tests/lib/control-pane-ui.test.js b/tests/lib/control-pane-ui.test.jsindex 6e883c3ad..315c168c7 100644--- a/tests/lib/control-pane-ui.test.js+++ b/tests/lib/control-pane-ui.test.js@@ -129,6 +129,26 @@ async function runTests() {passed++;else failed++;+ if (+ await test('a refresh that fails after an older one succeeded is reported', async () => {+ const page = openPage(snapshot);+ await settle();++ page.hold = true;+ page.refresh();+ page.refresh();+ page.pending[0].succeed();+ await settle();+ page.pending[1].fail();+ await settle();+ const box = page.element('#app');+ assert.strictEqual(box.hidden, false, 'the latest refresh failed, so the board is not live');+ assert.match(box.textContent, /Live refresh failed\. The data below is from /);+ })+ )+ passed++;+ else failed++;+console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);process.exit(failed > 0 ? 1 : 0);}