Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

Keep research notices consistent during refreshes (#8051)

LearningCircuit1524c6f993e7
diff --git a/changelog.d/+research-notice-refresh.bugfix.md b/changelog.d/+research-notice-refresh.bugfix.md
new file mode 100644
index 0000000000..c1119d5fba
--- /dev/null
+++ b/changelog.d/+research-notice-refresh.bugfix.md
@@ -0,0 +1 @@
+Research notices retain their last successfully loaded state when a refresh fails, show a refresh status message, and keep newer settings updates when older reads finish later.
diff --git a/src/local_deep_research/web/static/js/research_form.js b/src/local_deep_research/web/static/js/research_form.js
index 84761df359..a54afd168c 100644
--- a/src/local_deep_research/web/static/js/research_form.js
+++ b/src/local_deep_research/web/static/js/research_form.js
@@ -225,17 +225,54 @@ function refetchSettingsAndUpdateWarnings() {
* Manually clear all warnings (useful for debugging stale warnings)
*/
function clearAllWarnings() {
- displayWarnings([]);
+ updateWarnings([]);
}
let warningsRequestGeneration = 0;
+// Capture the renderer before replacing its classic-script window binding.
+const renderResearchWarnings = displayWarnings;
// Make functions globally available for other scripts
window.refetchSettingsAndUpdateWarnings = refetchSettingsAndUpdateWarnings;
-window.displayWarnings = displayWarnings;
+window.displayWarnings = updateWarnings;
window.clearAllWarnings = clearAllWarnings;
window.checkAndDisplayWarnings = checkAndDisplayWarnings;
+function validWarnings(warnings) {
+ return Array.isArray(warnings) && warnings.every(warning =>
+ warning !== null && typeof warning === 'object' && !Array.isArray(warning)
+ );
+}
+
+function setWarningRefreshStatus(message) {
+ let status = document.getElementById('research-warning-refresh-status');
+ if (!message) {
+ status?.remove();
+ return;
+ }
+ const container = document.getElementById('research-notices')
+ || document.getElementById('research-alert');
+ if (!container) return;
+ if (!status) {
+ status = document.createElement('p');
+ status.id = 'research-warning-refresh-status';
+ status.setAttribute('role', 'status');
+ status.setAttribute('aria-live', 'polite');
+ container.before(status);
+ }
+ status.textContent = message;
+}
+
+// Settings saves and explicit clears supersede any older in-flight read.
+// Keep this public update path separate from the renderer so every producer
+// shares the same ordering regardless of the page's notice layout.
+function updateWarnings(warnings) {
+ if (!validWarnings(warnings)) return;
+ warningsRequestGeneration += 1;
+ setWarningRefreshStatus('');
+ renderResearchWarnings(warnings);
+}
+
/**
* Check warning conditions by fetching from backend
*/
@@ -252,16 +289,15 @@ function checkAndDisplayWarnings() {
})
.then(data => {
if (requestGeneration !== warningsRequestGeneration) return;
- if (data && data.warnings) {
- displayWarnings(data.warnings);
- } else {
- displayWarnings([]);
+ if (!data || !validWarnings(data.warnings)) {
+ throw new Error('Invalid warnings response');
}
+ updateWarnings(data.warnings);
})
.catch(_error => {
if (requestGeneration !== warningsRequestGeneration) return;
- // Clear warnings on error
- displayWarnings([]);
+ // Keep the last successful notices until a valid response arrives.
+ setWarningRefreshStatus('Could not refresh notices. Refresh the page to try again.');
});
}
diff --git a/tests/js/research-form-warning-coverage.test.js b/tests/js/research-form-warning-coverage.test.js
index 1e510c5ee3..1bef9d22ff 100644
--- a/tests/js/research-form-warning-coverage.test.js
+++ b/tests/js/research-form-warning-coverage.test.js
@@ -217,7 +217,7 @@ it('rechecks warnings after both successful and failed settings refreshes', asyn
message: 'Rendered after settings refresh',
}],
}
- : {},
+ : { warnings: [] },
), { status: 200 }));
}
throw new Error(`Unexpected request: ${url}`);
@@ -250,9 +250,9 @@ it('rechecks warnings after both successful and failed settings refreshes', asyn
type: 'configuration',
icon: '!',
title: 'Temporary warning',
- message: 'Must clear on a current request failure',
+ message: 'Must clear after a valid empty refresh',
}]);
- fetchMock.mockResolvedValueOnce(new Response('', { status: 503 }));
+ fetchMock.mockResolvedValueOnce(new Response(JSON.stringify({ warnings: [] }), { status: 200 }));
await window.checkAndDisplayWarnings();
diff --git a/tests/js/research-warning-refresh.test.js b/tests/js/research-warning-refresh.test.js
new file mode 100644
index 0000000000..b0eb71fa22
--- /dev/null
+++ b/tests/js/research-warning-refresh.test.js
@@ -0,0 +1,103 @@
+/** Warning refresh recovery and ordering, independent of the notice layout. */
+import { readFileSync } from 'node:fs';
+import { resolve as resolvePath } from 'node:path';
+import { runInNewContext } from 'node:vm';
+import '@js/config/urls.js';
+import '@js/security/xss-protection.js';
+
+beforeEach(async () => {
+ vi.resetModules();
+ vi.stubGlobal('URLS', window.URLS);
+ document.body.innerHTML = '<div id="research-notices"></div><div id="research-alert"></div>';
+ await import('@js/research_form.js');
+});
+
+afterEach(() => {
+ vi.restoreAllMocks();
+ vi.unstubAllGlobals();
+ document.body.replaceChildren();
+});
+
+const CURRENT_NOTICE = {
+ type: 'configuration',
+ title: 'Current configuration',
+ message: 'Latest settings were applied',
+ dismissKey: 'app.warnings.dismiss_research_hint',
+};
+
+it.each([{}, { warnings: null }, { warnings: {} }, { warnings: [null] }])(
+ 'retains loaded notices for an invalid refresh response: %j', async payload => {
+ window.displayWarnings([CURRENT_NOTICE]);
+ vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify(payload))));
+ await window.checkAndDisplayWarnings();
+ expect(document.body.textContent)
+ .toContain(CURRENT_NOTICE.message);
+ expect(document.getElementById('research-warning-refresh-status').textContent)
+ .toContain('Could not refresh notices');
+ },
+);
+
+it('shows refresh failure without existing notices and clears it after an empty success', async () => {
+ const fetchMock = vi.fn()
+ .mockRejectedValueOnce(new Error('temporarily unavailable'))
+ .mockResolvedValueOnce(new Response(JSON.stringify({ warnings: [] })));
+ vi.stubGlobal('fetch', fetchMock);
+ await window.checkAndDisplayWarnings();
+ expect(document.getElementById('research-warning-refresh-status').textContent)
+ .toContain('Could not refresh notices');
+ await window.checkAndDisplayWarnings();
+ expect(document.getElementById('research-warning-refresh-status')).toBeNull();
+ expect(document.querySelector('.warning-banner')).toBeNull();
+});
+
+it.each(['update', 'empty update', 'clear'])('a newer %s supersedes an earlier read', async operation => {
+ let resolve;
+ vi.stubGlobal('fetch', vi.fn(() => new Promise(done => { resolve = done; })));
+ const earlier = window.checkAndDisplayWarnings();
+ if (operation === 'clear') window.clearAllWarnings();
+ else window.displayWarnings(operation === 'update' ? [CURRENT_NOTICE] : []);
+ resolve(new Response(JSON.stringify({ warnings: [{ ...CURRENT_NOTICE, message: 'Earlier snapshot' }] })));
+ await earlier;
+ const container = document.body;
+ expect(container.textContent).not.toContain('Earlier snapshot');
+ if (operation === 'update') expect(container.textContent).toContain(CURRENT_NOTICE.message);
+ else expect(document.querySelector('.warning-banner')).toBeNull();
+});
+
+it('ignores a failed read after a newer settings update', async () => {
+ let reject;
+ vi.stubGlobal('fetch', vi.fn(() => new Promise((_resolve, done) => { reject = done; })));
+ const earlier = window.checkAndDisplayWarnings();
+ window.displayWarnings([CURRENT_NOTICE]);
+ reject(new Error('earlier read failed'));
+ await earlier;
+ expect(document.getElementById('research-warning-refresh-status')).toBeNull();
+ expect(document.body.textContent).toContain(CURRENT_NOTICE.message);
+});
+
+
+it.each(['network', 'http'])('retains loaded notices after a %s failure', async failure => {
+ window.displayWarnings([CURRENT_NOTICE]);
+ vi.stubGlobal('fetch', vi.fn(() => (failure === 'network'
+ ? Promise.reject(new Error('temporarily unavailable'))
+ : Promise.resolve(new Response('', { status: 503 })))));
+ await window.checkAndDisplayWarnings();
+ expect(document.body.textContent).toContain(CURRENT_NOTICE.message);
+ expect(document.getElementById('research-warning-refresh-status')).not.toBeNull();
+});
+
+
+it('updates notices when loaded as a classic browser script', () => {
+ const scope = {
+ document,
+ location: window.location,
+ URL,
+ URLS: window.URLS,
+ escapeHtml: window.escapeHtml,
+ };
+ scope.window = scope;
+ const script = readFileSync(resolvePath(__dirname, '../../src/local_deep_research/web/static/js/research_form.js'), 'utf8');
+ runInNewContext(script, scope);
+ scope.displayWarnings([CURRENT_NOTICE]);
+ expect(document.body.textContent).toContain(CURRENT_NOTICE.message);
+});