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.

chore(lint): enable bug-detection trio (consistent-return, no-loop-func, require-atomic-updates) (#3655)

LearningCircuit3f1d744a3cfb
diff --git a/eslint.config.js b/eslint.config.js
index 66a7dc2a5b..3fa0d4690c 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -240,6 +240,17 @@ export default [
// (security/safe-logger.js) sanitises output. Tests and the
// SafeLogger module itself are exempted via overrides below.
"no-console": "error",
+
+ // Bug-detection trio:
+ // - consistent-return: every return path returns the same shape so
+ // callers don't have to special-case undefined
+ // - no-loop-func: closures inside a loop that capture mutable loop
+ // state — classic stale-reference hazard
+ // - require-atomic-updates: state updated based on a pre-await read
+ // is racy if the variable can change during the await
+ "consistent-return": "error",
+ "no-loop-func": "error",
+ "require-atomic-updates": "error",
},
languageOptions: {
diff --git a/src/local_deep_research/web/static/js/collection_upload.js b/src/local_deep_research/web/static/js/collection_upload.js
index 5355560e69..1576bdf278 100644
--- a/src/local_deep_research/web/static/js/collection_upload.js
+++ b/src/local_deep_research/web/static/js/collection_upload.js
@@ -354,13 +354,16 @@ async function handleBatchedUpload(files, pdfStorageMode, csrfToken, uploadUrl)
for (let batchIndex = 0; batchIndex < batches.length; batchIndex++) {
const batch = batches[batchIndex];
const batchSize = batch.reduce((sum, f) => sum + f.size, 0);
+ // Capture into a const so the progress closure references a stable
+ // per-iteration baseline (avoids closure-over-loop-var hazard).
+ const startBytes = uploadedBytes;
updateBatchProgress(batchIndex + 1, batches.length, uploadedBytes, totalSize);
try {
const result = await uploadBatch(batch, pdfStorageMode, csrfToken, uploadUrl, (loaded) => {
// Progress within this batch
- const currentProgress = uploadedBytes + loaded;
+ const currentProgress = startBytes + loaded;
const percent = Math.round((currentProgress / totalSize) * 100);
updateBatchProgressBytes(percent, currentProgress, totalSize);
});
diff --git a/src/local_deep_research/web/static/js/components/custom_dropdown.js b/src/local_deep_research/web/static/js/components/custom_dropdown.js
index efde7590b2..4815943c37 100644
--- a/src/local_deep_research/web/static/js/components/custom_dropdown.js
+++ b/src/local_deep_research/web/static/js/components/custom_dropdown.js
@@ -170,8 +170,6 @@
} else {
SafeLogger.log(`Dropdown ${input.id} is closed, options will update when opened`);
}
-
- return true;
}
/**
diff --git a/src/local_deep_research/web/static/js/components/history.js b/src/local_deep_research/web/static/js/components/history.js
index 27a0ed4197..686befb008 100644
--- a/src/local_deep_research/web/static/js/components/history.js
+++ b/src/local_deep_research/web/static/js/components/history.js
@@ -30,7 +30,8 @@
const uiUtils = {
showSpinner(container, message) {
if (window.ui && window.ui.showSpinner) {
- return window.ui.showSpinner(container, message);
+ window.ui.showSpinner(container, message);
+ return;
}
// Fallback implementation
@@ -49,7 +50,8 @@
hideSpinner(container) {
if (window.ui && window.ui.hideSpinner) {
- return window.ui.hideSpinner(container);
+ window.ui.hideSpinner(container);
+ return;
}
// Fallback implementation
@@ -62,7 +64,8 @@
showError(message) {
if (window.ui && window.ui.showError) {
- return window.ui.showError(message);
+ window.ui.showError(message);
+ return;
}
// Fallback implementation
@@ -72,7 +75,8 @@
showMessage(message) {
if (window.ui && window.ui.showMessage) {
- return window.ui.showMessage(message);
+ window.ui.showMessage(message);
+ return;
}
// Fallback implementation
@@ -682,6 +686,9 @@
if (currentSemanticId !== semanticSearchId) return; // stale
if (searchMode !== SM.SEMANTIC) return; // mode changed
if (results && results.needsIndexing) {
+ // Race-safe: stale-id guard above ensures only the latest
+ // request reaches this assignment.
+ // eslint-disable-next-line require-atomic-updates
historyContainer.innerHTML = `
<div class="ldr-empty-state">
<i class="fas fa-brain"></i>
diff --git a/src/local_deep_research/web/static/js/components/history_search.js b/src/local_deep_research/web/static/js/components/history_search.js
index 3c9b7224b1..32603f63c9 100644
--- a/src/local_deep_research/web/static/js/components/history_search.js
+++ b/src/local_deep_research/web/static/js/components/history_search.js
@@ -110,6 +110,10 @@ async function triggerIndexing() {
progressText.textContent = 'Collection not available. Please refresh the page.';
progressText.style.color = 'var(--error-color)';
}
+ // Reset the in-progress flag we set synchronously at the top of this
+ // function. The early `if (isIndexing) return` guard makes concurrent
+ // overlap impossible.
+ // eslint-disable-next-line require-atomic-updates
isIndexing = false;
return;
}
@@ -188,6 +192,9 @@ async function triggerIndexing() {
SafeLogger.log('Indexing started, beginning polling');
} catch (startError) {
SafeLogger.error('Error starting indexing:', startError);
+ // Reset the in-progress flag we set synchronously at the top; the
+ // early-return guard above prevents concurrent overlap.
+ // eslint-disable-next-line require-atomic-updates
isIndexing = false;
if (progressText) {
progressText.textContent = `Error: ${startError.message}`;
@@ -368,6 +375,9 @@ async function semanticSearchHistory(query) {
if (!response.ok) {
if (response.status === 404) {
+ // Cache is invalid (collection deleted server-side); clear so the
+ // next call re-fetches. Single-writer pattern, no race.
+ // eslint-disable-next-line require-atomic-updates
cachedCollectionId = null;
}
throw new Error(`Server returned ${response.status}`);
diff --git a/src/local_deep_research/web/static/js/components/progress.js b/src/local_deep_research/web/static/js/components/progress.js
index 5ce900c0d0..f692d20023 100644
--- a/src/local_deep_research/web/static/js/components/progress.js
+++ b/src/local_deep_research/web/static/js/components/progress.js
@@ -1279,8 +1279,9 @@
window.addEventListener('error', function(event) {
if (event.message && event.message.includes('WebSocket') && event.message.includes('frame header')) {
SafeLogger.warn('Caught WebSocket frame header error, suppressing');
+ // preventDefault is the addEventListener-style way to suppress;
+ // the legacy `return true` only worked with window.onerror = ...
event.preventDefault();
- return true; // Prevent the error from showing in console
}
});
diff --git a/src/local_deep_research/web/static/js/components/settings.js b/src/local_deep_research/web/static/js/components/settings.js
index 2b4bfd178d..60d6eaf168 100644
--- a/src/local_deep_research/web/static/js/components/settings.js
+++ b/src/local_deep_research/web/static/js/components/settings.js
@@ -794,8 +794,10 @@
});
if (hasInvalidJson) {
+ // preventDefault blocks submission for addEventListener-style
+ // handlers; the legacy `return false` only worked with
+ // inline onsubmit="..." attributes.
e.preventDefault();
- return false;
}
});
}
@@ -1893,10 +1895,11 @@
<div id="${sectionId}" class="ldr-settings-section-body">
`;
- // Add all settings in this category
- groupedSettings[type][category].forEach(setting => {
+ // Add all settings in this category (for-of, not forEach, so the
+ // synchronous body doesn't get flagged as a closure over `html`)
+ for (const setting of groupedSettings[type][category]) {
html += renderSettingItem(setting);
- });
+ }
html += `
</div>
@@ -2774,10 +2777,11 @@
<div id="${sectionId}" class="ldr-settings-section-body">
`;
- // Add all settings in this category
- groupedSettings[type][category].forEach(setting => {
+ // Add all settings in this category (for-of, not forEach, so the
+ // synchronous body doesn't get flagged as a closure over `html`)
+ for (const setting of groupedSettings[type][category]) {
html += renderSettingItem(setting);
- });
+ }
html += `
</div>
diff --git a/src/local_deep_research/web/static/js/followup.js b/src/local_deep_research/web/static/js/followup.js
index eba8125bc8..3905d4a372 100644
--- a/src/local_deep_research/web/static/js/followup.js
+++ b/src/local_deep_research/web/static/js/followup.js
@@ -324,8 +324,10 @@ class FollowUpResearch {
// Close modal
bootstrap.Modal.getInstance(this.modalElement).hide();
- // Redirect to progress page to show the research is running
+ // Redirect to progress page to show the research is running.
+ // Single navigation site; no concurrent writers to window.location.
// bearer:disable javascript_lang_open_redirect — server-generated UUID in hardcoded /progress/ path
+ // eslint-disable-next-line require-atomic-updates
window.location.href = `/progress/${data.research_id}`;
} else {
window.ui.showInlineError('followup-error-container', 'Error starting follow-up research: ' + (data.error || 'Unknown error'));
diff --git a/src/local_deep_research/web/static/js/services/help.js b/src/local_deep_research/web/static/js/services/help.js
index 61cc110cd2..1a5007a05a 100644
--- a/src/local_deep_research/web/static/js/services/help.js
+++ b/src/local_deep_research/web/static/js/services/help.js
@@ -264,6 +264,9 @@ const HelpService = (function() {
*/
async function init() {
if (initialized) return;
+ // Set the flag BEFORE awaiting so a second concurrent init() call
+ // returns at the guard above instead of double-running everything.
+ initialized = true;
// Initialize panel states (async to load from backend)
await initPanelStates();
@@ -280,8 +283,6 @@ const HelpService = (function() {
}
});
});
-
- initialized = true;
}
// Auto-initialize when DOM is ready
diff --git a/src/local_deep_research/web/static/js/services/pdf.js b/src/local_deep_research/web/static/js/services/pdf.js
index d487d73f5d..ae976c6eea 100644
--- a/src/local_deep_research/web/static/js/services/pdf.js
+++ b/src/local_deep_research/web/static/js/services/pdf.js
@@ -327,6 +327,10 @@ async function generatePdf(title, content, _metadata = {}) {
let currentX = margin;
let lineStarted = false;
+ // PDF generator state (currentY, pageNum) is mutated by both this
+ // closure and the surrounding loop; the closure runs synchronously
+ // each loop iteration so the no-loop-func hazard doesn't apply here.
+ // eslint-disable-next-line no-loop-func
const processTextSegment = (segment) => {
if (!segment) return;
@@ -624,6 +628,9 @@ async function generatePdf(title, content, _metadata = {}) {
pdf.setFont("helvetica", "bold");
pdf.setTextColor(255, 255, 255);
+ // tableY is mutated by the surrounding loop but the forEach is
+ // synchronous, so no closure-over-loop-var hazard.
+ // eslint-disable-next-line no-loop-func
headerCells.forEach((cell, index) => {
const text = cell.textContent.trim();
let x = margin;
@@ -648,6 +655,8 @@ async function generatePdf(title, content, _metadata = {}) {
// Draw cell content
pdf.setTextColor(0, 0, 0);
+ // Synchronous forEach; closure-over-tableY is benign.
+ // eslint-disable-next-line no-loop-func
cellContents.forEach((cellText, index) => {
let x = margin;
for (let j = 0; j < index; j++) {
@@ -712,6 +721,8 @@ async function generatePdf(title, content, _metadata = {}) {
// Draw code content
pdf.setTextColor(0, 0, 0);
+ // Synchronous forEach; closure-over-currentY is benign.
+ // eslint-disable-next-line no-loop-func
wrappedLines.forEach((line, index) => {
pdf.text(line, margin + 10, currentY + 15 + (index * lineHeight));
});
diff --git a/tests/ui_tests/mobile/test_mobile_nav_all_pages.js b/tests/ui_tests/mobile/test_mobile_nav_all_pages.js
index b1f6092034..e9cad547ae 100644
--- a/tests/ui_tests/mobile/test_mobile_nav_all_pages.js
+++ b/tests/ui_tests/mobile/test_mobile_nav_all_pages.js
@@ -394,6 +394,8 @@ async function testAllPages() {
} catch (error) {
console.error('❌ Test failed:', error);
+ // Single test runner; no concurrent writers to process.exitCode.
+ // eslint-disable-next-line require-atomic-updates
process.exitCode = 1;
} finally {
if (browser) {
diff --git a/tests/ui_tests/run_all_tests.js b/tests/ui_tests/run_all_tests.js
index 20d0cde7b1..58da08cc06 100644
--- a/tests/ui_tests/run_all_tests.js
+++ b/tests/ui_tests/run_all_tests.js
@@ -75,7 +75,9 @@ async function waitForServer(maxWaitMs = 60000) {
} catch {
wasDown = true;
}
- await new Promise(r => setTimeout(r, delay));
+ // Capture into const so the closure isn't flagged as no-loop-func.
+ const sleepFor = delay;
+ await new Promise(r => setTimeout(r, sleepFor));
delay = Math.min(delay * 2, 8000);
}
console.log(`Server did not respond within ${maxWaitMs/1000}s — subsequent tests may fail`);
diff --git a/tests/ui_tests/test_change_password_validation.js b/tests/ui_tests/test_change_password_validation.js
index 20beba4060..fbc8c95db4 100644
--- a/tests/ui_tests/test_change_password_validation.js
+++ b/tests/ui_tests/test_change_password_validation.js
@@ -291,6 +291,8 @@ async function testChangePasswordValidation() {
await page.type('input[name="confirm_password"]', testUser.password, { delay: 30 });
// Set up dialog handler
+ // Single test sequence; no concurrent writers to alertMessage.
+ // eslint-disable-next-line require-atomic-updates
alertMessage = null;
page.once('dialog', async dialog => {
alertMessage = dialog.message();
diff --git a/tests/ui_tests/test_followup_research.js b/tests/ui_tests/test_followup_research.js
index 8d47d26931..f791a51c1b 100644
--- a/tests/ui_tests/test_followup_research.js
+++ b/tests/ui_tests/test_followup_research.js
@@ -132,7 +132,7 @@ async function testFollowUpResearch() {
log('⚠️ Skipping follow-up research test in CI environment', 'warning');
log(' Modal visibility issues with Bootstrap in headless Chrome', 'info');
log(' Test passes locally but fails in CI - needs investigation', 'info');
- return 0; // Return success to not fail CI
+ return; // Caller doesn't use return value; finally → process.exit(0)
}
// Launch browser
diff --git a/tests/ui_tests/test_rate_limiting_settings.js b/tests/ui_tests/test_rate_limiting_settings.js
index 8937c2f3c1..4af0d8dc2f 100644
--- a/tests/ui_tests/test_rate_limiting_settings.js
+++ b/tests/ui_tests/test_rate_limiting_settings.js
@@ -19,7 +19,7 @@ async function testRateLimiting() {
if (process.env.CI && process.env.ENABLE_RATE_LIMITING !== 'true') {
console.log('⚠️ Skipping rate limiting test in CI (requires ENABLE_RATE_LIMITING=true)');
console.log('ℹ️ This test needs rate limiting enabled, but CI disables it by default');
- return true;
+ return; // Caller awaits but doesn't use return value
}
const browser = await puppeteer.launch(getPuppeteerLaunchOptions());
diff --git a/tests/ui_tests/test_settings_simple.js b/tests/ui_tests/test_settings_simple.js
index 500017c874..8d7d395aa7 100644
--- a/tests/ui_tests/test_settings_simple.js
+++ b/tests/ui_tests/test_settings_simple.js
@@ -136,6 +136,8 @@ const { getPuppeteerLaunchOptions } = require('./puppeteer_config');
// Press Enter
console.log('Pressing Enter on API key field...');
+ // Single test sequence; no concurrent writers to apiCalls.
+ // eslint-disable-next-line require-atomic-updates
apiCalls.length = 0; // Clear previous calls
await page.keyboard.press('Enter');