diff --git a/run_agent.py b/run_agent.py index 13278d94c04..717c26b4a7d 100644 --- a/run_agent.py +++ b/run_agent.py @@ -1389,6 +1389,7 @@ class AIAgent: content = re.sub(r'.*?', '', content, flags=re.DOTALL | re.IGNORECASE) content = re.sub(r'.*?', '', content, flags=re.DOTALL) content = re.sub(r'.*?', '', content, flags=re.DOTALL) + content = re.sub(r'\s*', '', content, flags=re.IGNORECASE) return content def _looks_like_codex_intermediate_ack( diff --git a/tests/test_run_agent.py b/tests/test_run_agent.py index 7ea3a63fe23..aa74164a754 100644 --- a/tests/test_run_agent.py +++ b/tests/test_run_agent.py @@ -230,6 +230,27 @@ class TestStripThinkBlocks: assert "line1" not in result assert "visible" in result + def test_orphaned_closing_think_tag(self, agent): + result = agent._strip_think_blocks("some reasoningactual answer") + assert "" not in result + assert "actual answer" in result + + def test_orphaned_closing_thinking_tag(self, agent): + result = agent._strip_think_blocks("reasoninganswer") + assert "" not in result + assert "answer" in result + + def test_orphaned_opening_think_tag(self, agent): + result = agent._strip_think_blocks("orphaned reasoning without close") + assert "" not in result + + def test_mixed_orphaned_and_paired_tags(self, agent): + text = "straypaired reasoning visible" + result = agent._strip_think_blocks(text) + assert "" not in result + assert "" not in result + assert "visible" in result + class TestExtractReasoning: def test_reasoning_field(self, agent):