~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(collections): preserve sweep state on empty 2xx (#5371)
Ziyang Guo7bc60f59c8a1
diff --git a/changelog.d/+background-sweep-2xx-body.bugfix.md b/changelog.d/+background-sweep-2xx-body.bugfix.mdnew file mode 100644index 0000000000..4d6abc26c5--- /dev/null+++ b/changelog.d/+background-sweep-2xx-body.bugfix.md@@ -0,0 +1 @@+Keep the background-sweep toggle ON when a successful enable response has an empty or unparseable body.diff --git a/src/local_deep_research/web/static/js/collections_manager.js b/src/local_deep_research/web/static/js/collections_manager.jsindex 2334f85b0a..c9d9daef1c 100644--- a/src/local_deep_research/web/static/js/collections_manager.js+++ b/src/local_deep_research/web/static/js/collections_manager.js@@ -111,6 +111,13 @@ function legacyArmNeedsClear(legacyOn) {return legacyOn !== false;}+function setBackgroundSweepToggleState(checked) {+ const currentToggle = document.getElementById('background-sweep-toggle');+ if (currentToggle) {+ currentToggle.checked = checked;+ }+}+/*** Load the background-sweep setting and update the toggle.*@@ -176,9 +183,31 @@ async function saveBackgroundSweepSetting() {});try {const response = await putSetting('document_scheduler.sweep_library_collections', desired);- const data = await response.json();- if (!response.ok || data.error) {- SafeLogger.error('Failed to save background-sweep setting:', data.error);+ const preserveIndeterminateSuccess = (detail) => {+ // Trust a successful enable. For disable, an unknown body cannot+ // confirm the legacy gate is disarmed, so keep the honest ON state.+ SafeLogger.warn(+ 'Background-sweep setting write succeeded but its response was indeterminate; preserving ON state:',+ detail+ );+ setBackgroundSweepToggleState(true);+ };+ let data;+ try {+ data = await response.json();+ } catch (error) {+ if (response.ok) {+ preserveIndeterminateSuccess(error);+ return;+ }+ throw error;+ }+ if (response.ok && data == null) {+ preserveIndeterminateSuccess('empty response body');+ return;+ }+ if (!response.ok || data == null || data.error) {+ SafeLogger.error('Failed to save background-sweep setting:', data?.error);toggle.checked = !desired;return;}@@ -206,12 +235,12 @@ async function saveBackgroundSweepSetting() {// set, so the reconciler can stay armed — the honest state is ON.// Reflect reality rather than a false OFF.SafeLogger.error('Failed to clear legacy generate_rag on OFF:', legacyData.error);- toggle.checked = true;+ setBackgroundSweepToggleState(true);}}} catch (error) {SafeLogger.error('Error saving background-sweep setting:', error);- toggle.checked = !desired;+ setBackgroundSweepToggleState(!desired);}}diff --git a/tests/js/collections-manager.test.js b/tests/js/collections-manager.test.jsindex 5c3013ef33..c053939cbf 100644--- a/tests/js/collections-manager.test.js+++ b/tests/js/collections-manager.test.js@@ -619,6 +619,78 @@ describe('background-sweep toggle', () => {expect(toggle.checked).toBe(true);});+ it.each([+ [+ 'unparseable',+ () => Promise.reject(new SyntaxError('invalid JSON')),+ expect.any(SyntaxError),+ ],+ ['null', () => Promise.resolve(null), 'empty response body'],+ ])(+ 'keeps ON after a successful save with a %s response body',+ async (_bodyType, json, expectedDetail) => {+ const toggle = makeToggle();+ toggle.checked = true;+ const warnSpy = vi.spyOn(globalThis.SafeLogger, 'warn');+ const errorSpy = vi.spyOn(globalThis.SafeLogger, 'error');+ globalThis.safeFetchWithAuth.mockResolvedValue({+ ok: true,+ json,+ });++ try {+ await saveBackgroundSweepSetting();++ expect(globalThis.safeFetchWithAuth).toHaveBeenCalledTimes(1);+ expect(toggle.checked).toBe(true);+ expect(warnSpy).toHaveBeenCalledWith(+ expect.stringContaining('preserving ON state'),+ expectedDetail+ );+ expect(errorSpy).not.toHaveBeenCalled();+ } finally {+ warnSpy.mockRestore();+ errorSpy.mockRestore();+ }+ }+ );++ it.each([+ [+ 'unparseable',+ () => Promise.reject(new SyntaxError('invalid JSON')),+ expect.any(SyntaxError),+ ],+ ['null', () => Promise.resolve(null), 'empty response body'],+ ])(+ 'keeps an indeterminate OFF save on the same warning path for a %s body',+ async (_bodyType, json, expectedDetail) => {+ const toggle = makeToggle();+ toggle.checked = false;+ const warnSpy = vi.spyOn(globalThis.SafeLogger, 'warn');+ const errorSpy = vi.spyOn(globalThis.SafeLogger, 'error');+ globalThis.safeFetchWithAuth.mockResolvedValue({+ ok: true,+ json,+ });++ try {+ await saveBackgroundSweepSetting();++ expect(globalThis.safeFetchWithAuth).toHaveBeenCalledTimes(1);+ expect(toggle.checked).toBe(true);+ expect(warnSpy).toHaveBeenCalledWith(+ expect.stringContaining('preserving ON state'),+ expectedDetail+ );+ expect(errorSpy).not.toHaveBeenCalled();+ } finally {+ warnSpy.mockRestore();+ errorSpy.mockRestore();+ }+ }+ );+it('reverts the toggle when the save fails', async () => {const toggle = makeToggle();toggle.checked = true;