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 issue #301: Prevent duplicate links in detailed report mode

LearningCircuitae09cd058db5
diff --git a/src/local_deep_research/search_system.py b/src/local_deep_research/search_system.py
index 5f8f92bc44..dc0d3ae7a9 100644
--- a/src/local_deep_research/search_system.py
+++ b/src/local_deep_research/search_system.py
@@ -180,8 +180,11 @@ class AdvancedSearchSystem:
self.questions_by_iteration = self.strategy.questions_by_iteration.copy()
# Send progress message with search info
- # if hasattr(self.strategy, "all_links_of_system"):
- self.all_links_of_system.extend(self.strategy.all_links_of_system)
+ # Only extend if they're different objects in memory to avoid duplication
+ # This check prevents doubling the list when they reference the same object
+ # Fix for issue #301: "too many links in detailed report mode"
+ if id(self.all_links_of_system) != id(self.strategy.all_links_of_system):
+ self.all_links_of_system.extend(self.strategy.all_links_of_system)
# Include the search system instance for access to citations
result["search_system"] = self
diff --git a/tests/fix_tests/README.md b/tests/fix_tests/README.md
new file mode 100644
index 0000000000..f6733998d1
--- /dev/null
+++ b/tests/fix_tests/README.md
@@ -0,0 +1,36 @@
+# Fix Tests
+
+This directory contains tests for specific bug fixes in the codebase.
+
+## Tests
+
+### test_duplicate_links_fix.py
+
+Demonstrates and tests the fix for GitHub issue [#301](https://github.com/LearningCircuit/local-deep-research/issues/301) - "too many links in detailed report mode".
+
+The test simulates the bug where links are duplicated in the `all_links_of_system` list when using detailed report mode. It compares the behavior before and after implementing the fix.
+
+#### Bug Description
+
+The bug occurred because `search_system.py` was unconditionally extending `self.all_links_of_system` with `self.strategy.all_links_of_system` in the `analyze_topic` method, even though they were the same list object (when initialized with the same reference).
+
+#### Fix
+
+The fix checks if the lists are the same object (have the same `id()`) before extending:
+
+```python
+# Only extend if they're different objects in memory to avoid duplication
+if id(self.all_links_of_system) != id(self.strategy.all_links_of_system):
+ self.all_links_of_system.extend(self.strategy.all_links_of_system)
+```
+
+This prevents duplicating the content when both lists are actually the same object.
+
+#### Running the Test
+
+```bash
+cd tests/fix_tests
+python test_duplicate_links_fix.py
+```
+
+The test demonstrates both the bug and the fixed behavior side-by-side.
\ No newline at end of file
diff --git a/tests/fix_tests/test_duplicate_links_fix.py b/tests/fix_tests/test_duplicate_links_fix.py
new file mode 100644
index 0000000000..2884b25f22
--- /dev/null
+++ b/tests/fix_tests/test_duplicate_links_fix.py
@@ -0,0 +1,102 @@
+"""
+Test script to demonstrate the duplicate links issue and our fix for issue #301.
+
+This test demonstrates the problem where the search system duplicates links in detailed report mode
+by unconditionally extending the all_links_of_system list with itself.
+
+GitHub issue: https://github.com/LearningCircuit/local-deep-research/issues/301
+
+The fix is to check if the lists are the same object (have the same id()) before extending.
+"""
+
+class Strategy:
+ def __init__(self, all_links=None):
+ # Create a new list if None is provided
+ self.all_links_of_system = [] if all_links is None else all_links
+ print(f"Strategy initialized with list id: {id(self.all_links_of_system)}")
+
+ def analyze_topic(self, query):
+ # Add some links
+ self.all_links_of_system.extend([
+ {"title": "Link 1", "link": "http://example.com/1"},
+ {"title": "Link 2", "link": "http://example.com/2"},
+ ])
+ print(f"Strategy now has {len(self.all_links_of_system)} links")
+ return {"content": "Analysis results"}
+
+class AdvancedSearchSystem:
+ def __init__(self):
+ # Initialize with empty list
+ self.all_links_of_system = []
+ print(f"Search system initialized with list id: {id(self.all_links_of_system)}")
+
+ # Create strategy with our list reference
+ self.strategy = Strategy(all_links=self.all_links_of_system)
+
+ # Check if they're the same object
+ print(f"Are lists the same object? {id(self.all_links_of_system) == id(self.strategy.all_links_of_system)}")
+
+ def analyze_topic_with_bug(self, query):
+ # Run the strategy
+ result = self.strategy.analyze_topic(query)
+
+ # BUG: Unconditionally extend our list with the strategy's list
+ # This is problematic because they're the same list
+ print("\nBUG DEMO: Extending unconditionally")
+ before_count = len(self.all_links_of_system)
+ print(f"Before extending: {before_count} links")
+
+ self.all_links_of_system.extend(self.strategy.all_links_of_system)
+
+ after_count = len(self.all_links_of_system)
+ print(f"After extending: {after_count} links")
+ print(f"Added {after_count - before_count} links (duplicates)")
+
+ # Return results
+ return {
+ "all_links_of_system": self.all_links_of_system,
+ "content": result["content"]
+ }
+
+ def analyze_topic_with_fix(self, query):
+ # Run the strategy
+ result = self.strategy.analyze_topic(query)
+
+ # FIX: Only extend if they're different objects
+ print("\nFIX DEMO: Only extending if lists are different")
+ before_count = len(self.all_links_of_system)
+ print(f"Before fix check: {before_count} links")
+
+ if id(self.all_links_of_system) != id(self.strategy.all_links_of_system):
+ print("Lists are different objects - extending")
+ self.all_links_of_system.extend(self.strategy.all_links_of_system)
+ else:
+ print("Lists are the same object - not extending (avoiding duplicates)")
+
+ after_count = len(self.all_links_of_system)
+ print(f"After fix check: {after_count} links")
+ print(f"Added {after_count - before_count} links")
+
+ # Return results
+ return {
+ "all_links_of_system": self.all_links_of_system,
+ "content": result["content"]
+ }
+
+def test_bug_and_fix():
+ print("=== Testing Bug and Fix ===\n")
+
+ print("1. Creating first search system to demonstrate the bug:")
+ search_system1 = AdvancedSearchSystem()
+ result1 = search_system1.analyze_topic_with_bug("What is quantum computing?")
+ print(f"\nFinal link count with bug: {len(result1['all_links_of_system'])}")
+
+ print("\n2. Creating second search system to demonstrate the fix:")
+ search_system2 = AdvancedSearchSystem()
+ result2 = search_system2.analyze_topic_with_fix("What is quantum computing?")
+ print(f"\nFinal link count with fix: {len(result2['all_links_of_system'])}")
+
+ print("\nTest complete!")
+
+if __name__ == "__main__":
+ test_bug_and_fix()
\ No newline at end of file