diff --git a/agent/turn_summary.py b/agent/turn_summary.py index b542daa0ea40..f4440afb50aa 100644 --- a/agent/turn_summary.py +++ b/agent/turn_summary.py @@ -151,7 +151,13 @@ def _extract_line_deltas(tool_name: str, result: Any) -> tuple[int, int] | None: diff = payload.get("diff") if not isinstance(diff, str) or not diff.strip(): return None - return _count_diff_lines(diff) + added, removed = _count_diff_lines(diff) + # A diff that carries no +/- content lines (e.g. a bare hunk header) tells + # us nothing — report it as unknown rather than rendering a misleading + # "+0 -0" next to a real edit. + if added == 0 and removed == 0: + return None + return added, removed class TurnSummaryCollector: diff --git a/tests/agent/test_turn_summary.py b/tests/agent/test_turn_summary.py index 786a53abaa9c..b3d96f85433c 100644 --- a/tests/agent/test_turn_summary.py +++ b/tests/agent/test_turn_summary.py @@ -344,3 +344,28 @@ def test_turn_summary_config_defaults_present(): display = DEFAULT_CONFIG["display"] assert display["turn_summary"] is True assert display["spinner_token_flow"] is True + + +def test_content_free_diff_reports_unknown_not_zero_zero(): + """A diff with no +/- content lines (bare hunk header) must render as an + edit with UNKNOWN deltas, never a misleading '+0 -0'. + + Found by E2E-rendering the collector against realistic tool payloads: the + unit suite only fed diffs that had real content lines. + """ + from agent.turn_summary import TurnSummaryCollector + + c = TurnSummaryCollector() + c.begin() + c.record_tool("patch", result={"success": True, "diff": "@@ -1,3 +1,15 @@"}) + line = c.render(3.0) + assert "edited 1 file" in line + assert "+0 -0" not in line + + real = TurnSummaryCollector() + real.begin() + real.record_tool( + "patch", + result={"success": True, "diff": "--- a/x\n+++ b/x\n@@ -1 +1,2 @@\n-old\n+new\n+extra\n"}, + ) + assert "+2 -1" in real.render(1.0)