From 1aac903e3df30f7733a432de6f4fbce12a45a1d4 Mon Sep 17 00:00:00 2001 From: Jesse Turner Date: Fri, 24 Apr 2026 09:11:27 -0400 Subject: [PATCH] fix: buffer streaming text to avoid per-token log lines in GitHub Actions Each text delta from the harness was printed individually with flush, creating a separate log line per token. Now text is buffered and flushed as complete lines at block boundaries. --- .github/scripts/python/harness_review.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/scripts/python/harness_review.py b/.github/scripts/python/harness_review.py index 75655df6..fbfd0b0f 100644 --- a/.github/scripts/python/harness_review.py +++ b/.github/scripts/python/harness_review.py @@ -97,7 +97,7 @@ def print_stream(http_response): tool_input = "" tool_start = 0.0 in_group = False - had_text = False + text_buffer = "" def close_group(): nonlocal in_group @@ -105,6 +105,13 @@ def close_group(): print("::endgroup::", flush=True) in_group = False + def flush_text(): + nonlocal text_buffer + if text_buffer: + for line in text_buffer.splitlines(): + print(f"{DIM}{line}{RESET}", flush=True) + text_buffer = "" + for event_type, payload in parse_events(http_response): if event_type == "contentBlockStart": @@ -119,13 +126,12 @@ def close_group(): delta = payload.get("delta", {}) if "text" in delta: close_group() - print(flush=True) - print(f"{DIM}{delta['text']}{RESET}", end="", flush=True) - had_text = True + text_buffer += delta["text"] if "toolUse" in delta: tool_input += delta["toolUse"].get("input", "") elif event_type == "contentBlockStop": + flush_text() if tool_name: elapsed = time.time() - tool_start try: @@ -134,9 +140,6 @@ def close_group(): parsed = tool_input close_group() - if had_text: - print("\n", flush=True) - had_text = False cmd = parsed.get("command") if isinstance(parsed, dict) else None header = f"{CYAN}[{iteration}]{RESET} {YELLOW}{tool_name}{RESET} {DIM}({elapsed:.1f}s){RESET}" @@ -155,6 +158,7 @@ def close_group(): tool_input = "" elif event_type == "messageStop": + flush_text() close_group() if payload.get("stopReason") == "end_turn": total = time.time() - start_time