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.

fix(logpanel): preserve rendered IDs across research switches (#5360)

Ziyang Guo8239c6882069
diff --git a/changelog.d/+logpanel-research-switch-dedup.bugfix.md b/changelog.d/+logpanel-research-switch-dedup.bugfix.md
new file mode 100644
index 0000000000..39f7436362
--- /dev/null
+++ b/changelog.d/+logpanel-research-switch-dedup.bugfix.md
@@ -0,0 +1 @@
+Prevent duplicate log rows from appearing while the log panel switches between research sessions.
diff --git a/src/local_deep_research/web/static/js/components/logpanel.js b/src/local_deep_research/web/static/js/components/logpanel.js
index f4567e13b8..e98b548e47 100644
--- a/src/local_deep_research/web/static/js/components/logpanel.js
+++ b/src/local_deep_research/web/static/js/components/logpanel.js
@@ -102,7 +102,17 @@
// still loading. The next loadLogsForResearch call will
// recompute from B's DOM. See issue #5151 (Gap 2).
window._logPanelState.counts = emptyCounts();
- window._logPanelState.renderedIds = new Set();
+ const renderedIds = new Set();
+ document
+ .querySelectorAll(
+ '#console-log-container .ldr-console-log-entry[data-log-id]'
+ )
+ .forEach((entry) => {
+ if (entry.dataset.logId) {
+ renderedIds.add(entry.dataset.logId);
+ }
+ });
+ window._logPanelState.renderedIds = renderedIds;
window._logPanelState._countRequestGen =
(window._logPanelState._countRequestGen || 0) + 1;
if (previousResearchId && previousResearchId !== researchId) {
@@ -678,6 +688,8 @@
*
* @param {Element} container - The log container element.
* @param {number} cap - The maximum allowed entry count after pruning.
+ * @param {number} [knownCount] - Known entry count after insertion. When
+ * at or below `cap`, pruning can return without querying the DOM.
* @returns {string[]} Normalized DOM types of removed entries, in removal
* order. A missing type is normalized to "info", matching the rest of
* the panel. Explicit unknown types retain their real lowercase value so
@@ -1025,7 +1037,7 @@
logContent.innerHTML = '';
- // Batch DOM insert using DocumentFragment (O(1) reflow vs O(n))
+ // Append one DocumentFragment to minimize batch-insert reflows.
// sortedLogs is newest-first, but DOM needs [oldest, ..., newest]
// for column-reverse CSS to show newest at visual top
const fragment = document.createDocumentFragment();
@@ -1391,6 +1403,8 @@
const lastTime = Number(lastEntry.dataset.logTimeMs || 0);
if (newTime < lastTime) {
// Out of order: scan backwards from the newest end
+ // The early break relies on every insertion path preserving
+ // oldest-to-newest DOM order.
for (let i = len - 1; i >= 0; i--) {
const entry = existingEntries[i];
const entryTime = Number(entry.dataset.logTimeMs || 0);
diff --git a/tests/js/components/logpanel.test.js b/tests/js/components/logpanel.test.js
index 030ccdb417..58c4cbf82a 100644
--- a/tests/js/components/logpanel.test.js
+++ b/tests/js/components/logpanel.test.js
@@ -2628,7 +2628,7 @@ describe('addLog — live pruning integration', () => {
expect(querySpy).not.toHaveBeenCalled();
});
- it('queries DOM and prunes in pruneToCap when knownCount > cap or omitted', () => {
+ it('queries DOM and prunes in pruneToCap when knownCount > cap', () => {
const container = document.createElement('div');
for (let i = 0; i < 3; i++) {
container.appendChild(makeLiveEntry(`entry-${i}`, 'info'));
@@ -2639,9 +2639,26 @@ describe('addLog — live pruning integration', () => {
expect(container.querySelectorAll('.ldr-console-log-entry')).toHaveLength(2);
});
- it('resets renderedIds when switching research', () => {
- window._logPanelState.renderedIds.add('old-log-id');
+ it('queries DOM and prunes in pruneToCap when knownCount is omitted', () => {
+ const container = document.createElement('div');
+ for (let i = 0; i < 3; i++) {
+ container.appendChild(makeLiveEntry(`entry-${i}`, 'info'));
+ }
+
+ const removed = window.logPanel._pruneToCap(container, 2);
+ expect(removed).toEqual(['info']);
+ expect(container.querySelectorAll('.ldr-console-log-entry')).toHaveLength(2);
+ });
+
+ it('rebuilds renderedIds from the live DOM when switching research', () => {
+ const entry = makeLiveEntry('rendered-before-switch');
+ document.getElementById('console-log-container').appendChild(entry);
+ window._logPanelState.renderedIds.add('stale-set-only-id');
+
window.logPanel.initialize('new-research-id');
- expect(window._logPanelState.renderedIds.has('old-log-id')).toBe(false);
+
+ expect(window._logPanelState.renderedIds).toEqual(
+ new Set(['live-rendered-before-switch'])
+ );
});
});
diff --git a/tests/utilities/test_close_base_llm.py b/tests/utilities/test_close_base_llm.py
index 2f08b27b57..6d9c44a55e 100644
--- a/tests/utilities/test_close_base_llm.py
+++ b/tests/utilities/test_close_base_llm.py
@@ -31,16 +31,14 @@ def _open_fd_count() -> int:
Inlined here to avoid coupling these tests to a private helper in
an unrelated production module. On Linux uses ``/proc/self/fd``
(fast); on macOS falls back to scanning ``RLIMIT_NOFILE``. On non-POSIX
- platforms (e.g. Windows) where resource is unavailable, returning 0
- makes calls a no-op for non-skipped test callers.
+ platforms (e.g. Windows) where resource is unavailable, callers skip
+ instead of silently passing with a synthetic count.
"""
try:
return len(os.listdir("/proc/self/fd"))
except (FileNotFoundError, OSError):
if resource is None:
- # Non-POSIX fallback (Windows): returning 0 makes FD assertions
- # no-ops for any non-skipped callers.
- return 0
+ pytest.skip("file descriptor counting requires POSIX support")
soft_limit = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
count = 0
for fd in range(soft_limit):