~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(report): split section number on first period only (fix IndexError + name truncation) (#4345)
LearningCircuitb0d5dd236f71
diff --git a/changelog.d/+report-structure-split-indexerror.bugfix.md b/changelog.d/+report-structure-split-indexerror.bugfix.mdnew file mode 100644index 0000000000..bc1e19a028--- /dev/null+++ b/changelog.d/+report-structure-split-indexerror.bugfix.md@@ -0,0 +1 @@+Fix report structure parsing crashing with `IndexError` on a numbered section line without a period (e.g. `1 Introduction`), and stop truncating section names that contain periods (`1. U.S. Policy` is now kept whole instead of becoming `U`). The section number is now split on the first period only, with a guard for malformed lines.diff --git a/src/local_deep_research/report_generator.py b/src/local_deep_research/report_generator.pyindex fe3b9a0678..cc42359cb6 100644--- a/src/local_deep_research/report_generator.py+++ b/src/local_deep_research/report_generator.py@@ -174,8 +174,11 @@ class IntegratedReportGenerator:continueif line.strip().startswith(tuple("123456789")):- # Main section- section_name = line.split(".")[1].strip()+ # Main section — require a dot-delimited name (e.g. "1. Intro").+ parts = line.split(".", 1)+ if len(parts) < 2 or not parts[1].strip():+ continue+ section_name = parts[1].strip()current_section = {"name": section_name, "subsections": []}structure.append(current_section)elif line.strip().startswith("-") and current_section:diff --git a/tests/report/test_report_structure_parsing.py b/tests/report/test_report_structure_parsing.pyindex f192288fe7..c0a0555c87 100644--- a/tests/report/test_report_structure_parsing.py+++ b/tests/report/test_report_structure_parsing.py@@ -597,11 +597,10 @@ class TestReportGenerationIntegration:class TestSplitDotBug:- """Document the split('.')[1] bug at line 139 that mangles section names- containing periods.+ """Section-name parsing splits only on the first period (split('.', 1)).- The parser does: section_name = line.split(".")[1].strip()- This means "1. U.S. Policy" -> ["1", " U", "S", " Policy"] -> [1] = " U"+ The parser does: section_name = line.split(".", 1)[1].strip(), so section+ names containing periods (e.g. "1. U.S. Policy") are preserved intact."""@pytest.fixture@@ -619,23 +618,22 @@ class TestSplitDotBug:generator = IntegratedReportGenerator(llm=mock_llm)yield generator- def test_period_in_section_name_bug(self, report_generator):- """'1. U.S. Policy' is mangled to 'U' by split('.')[1]."""+ def test_period_in_section_name_preserved(self, report_generator):+ """'1. U.S. Policy' keeps periods after the section number (split('.', 1))."""response = "STRUCTURE\n1. U.S. Policy\nEND_STRUCTURE"report_generator.model.invoke.return_value = MagicMock(content=response)findings = {"current_knowledge": "Test " * 100}structure = report_generator._determine_report_structure(findings, "q")assert len(structure) == 1- # Documents the current buggy behavior:- assert structure[0]["name"] == "U"+ assert structure[0]["name"] == "U.S. Policy"- def test_abbreviation_in_section_name_bug(self, report_generator):- """'1. IPv4 vs. IPv6' is mangled to 'IPv4 vs' by split('.')[1]."""+ def test_abbreviation_in_section_name_preserved(self, report_generator):+ """'1. IPv4 vs. IPv6' keeps the trailing abbreviation (split('.', 1))."""response = "STRUCTURE\n1. IPv4 vs. IPv6\nEND_STRUCTURE"report_generator.model.invoke.return_value = MagicMock(content=response)findings = {"current_knowledge": "Test " * 100}structure = report_generator._determine_report_structure(findings, "q")- assert structure[0]["name"] == "IPv4 vs"+ assert structure[0]["name"] == "IPv4 vs. IPv6"def test_double_digit_section_number(self, report_generator):"""'10. Conclusion' parses correctly since split('.')[1] = ' Conclusion'."""diff --git a/tests/test_report_generator_edge_cases.py b/tests/test_report_generator_edge_cases.pyindex fbb9f99a24..0f445c6bf6 100644--- a/tests/test_report_generator_edge_cases.py+++ b/tests/test_report_generator_edge_cases.py@@ -53,22 +53,35 @@ class TestDetermineReportStructureNoDelimiters:class TestDetermineReportStructureSectionWithoutPeriod:- """Verify section line without period (e.g. '1 Section Name') causes IndexError.+ """A numbered section line without a period is skipped gracefully (no IndexError)."""- BUG DISCOVERED: line.split('.')[1] at report_generator.py:139 has no guard- for section lines without a period separator. This test documents the bug.- """-- def test_section_without_period_raises_index_error(self, generator):- """'1 Section Name' (no period) → split('.')[1] raises IndexError (unhandled bug)."""+ def test_section_without_period_is_skipped(self, generator):+ """'1 Section Name' (no period) is skipped rather than raising IndexError."""generator.model.invoke.return_value = Mock(content=("STRUCTURE\n1 Section Without Period\nEND_STRUCTURE"))findings = {"current_knowledge": "Some knowledge."}- # This is a real bug: line.split(".")[1] with no "." raises IndexError- with pytest.raises(IndexError):- generator._determine_report_structure(findings, "test query")+ # Previously line.split(".")[1] raised IndexError; now the line is skipped.+ structure = generator._determine_report_structure(+ findings, "test query"+ )+ assert structure == []++ def test_valid_and_dotless_lines_mixed(self, generator):+ """A valid numbered line still parses even when a dotless one precedes it."""+ generator.model.invoke.return_value = Mock(+ content=(+ "STRUCTURE\n1 No Period Here\n2. Real Section\nEND_STRUCTURE"+ )+ )++ findings = {"current_knowledge": "Some knowledge."}+ structure = generator._determine_report_structure(+ findings, "test query"+ )+ assert len(structure) == 1+ assert structure[0]["name"] == "Real Section"class TestDetermineReportStructureSubsectionBeforeAnySection: