The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): limit the turn-level streamed guard to interrupted results (#65666)
kshitijk4poorb0516ca60c41
diff --git a/hermes_cli/cli_chat_turn_mixin.py b/hermes_cli/cli_chat_turn_mixin.pyindex 9a86e8180ca..9f6b27b750d 100644--- a/hermes_cli/cli_chat_turn_mixin.py+++ b/hermes_cli/cli_chat_turn_mixin.py@@ -106,7 +106,7 @@ class CLIChatTurnMixin:# Not part of _reset_stream_state: must persist across intermediate turn# boundaries (tool-calling loops), reset once per user turn.self._reasoning_shown_this_turn = False- self._response_streamed_this_turn = False+ self._streamed_text_this_turn = ""self._chat_setup_turn_audio(turn, message, voice_input)# Per-prompt elapsed timer — frozen when the agent thread finishes.self._prompt_start_time = time.time()@@ -681,9 +681,15 @@ class CLIChatTurnMixin:_resp_text = _maybe_remap_for_light_mode("#FFF8DC")is_error_response = turn.result and (turn.result.get("failed") or turn.result.get("partial"))+ # An interrupted reply that streamed before a tool-call boundary reset the segment+ # state is already on screen (#65666). Only suppress when the response IS that text:+ # unstreamed interrupt/status messages and completed replies still get their Panel.+ _interrupted_streamed = bool(+ self._last_turn_interrupted and response.strip()+ and " ".join(response.split()) in " ".join(self._streamed_text_this_turn.split())+ )already_streamed = (- (self._stream_started and self._stream_box_opened)- or getattr(self, "_response_streamed_this_turn", False)+ (self._stream_started and self._stream_box_opened) or _interrupted_streamed) and not is_error_responseif turn.use_streaming_tts and turn.box_opened and not is_error_response:# Text already printed sentence-by-sentence; just close the box.diff --git a/hermes_cli/cli_init_mixin.py b/hermes_cli/cli_init_mixin.pyindex adb51f2130b..26f9970e7d7 100644--- a/hermes_cli/cli_init_mixin.py+++ b/hermes_cli/cli_init_mixin.py@@ -86,6 +86,7 @@ class CLIInitMixin:self._stream_buf = "" # partial line bufferself._reasoning_preview_buf = "" # coalesces tiny reasoning chunksself._stream_started = self._stream_box_opened = self._stream_box_live = False+ self._streamed_text_this_turn = ""self._held_status_lines: list[str] = [] # agent status lines parked while a box streams# Possible markdown-table lines held until the block ends for wcwidth-aware re-padding.self._stream_table_buf: list[str] = []diff --git a/hermes_cli/cli_stream_mixin.py b/hermes_cli/cli_stream_mixin.pyindex ab1709f592e..afc428e9b83 100644--- a/hermes_cli/cli_stream_mixin.py+++ b/hermes_cli/cli_stream_mixin.py@@ -428,8 +428,6 @@ class CLIStreamMixin:if not text:returnself._stream_box_opened = True- # Turn-level: survives _reset_stream_state at tool-call boundaries (#65666).- self._response_streamed_this_turn = Trueself._stream_box_live = True # header drawn; cleared at the footertry:from hermes_cli.skin_engine import get_active_skin@@ -450,6 +448,9 @@ class CLIStreamMixin:fill = w - 2 - HermesCLI._status_bar_display_width(label)_cprint(f"\n{_ACCENT}╭─{label}{'─' * max(fill - 1, 0)}╮{_RST}")+ # Turn-level record of what actually reached the screen; survives _reset_stream_state at+ # tool-call boundaries so an interrupted reply isn't re-rendered as a Panel (#65666).+ self._streamed_text_this_turn = getattr(self, "_streamed_text_this_turn", "") + textself._stream_buf += textwhile "\n" in self._stream_buf:line, self._stream_buf = self._stream_buf.split("\n", 1)diff --git a/tests/hermes_cli/test_status_lines_held_during_stream_box.py b/tests/hermes_cli/test_status_lines_held_during_stream_box.pyindex 6ff5fec9bb2..4a67daedd5e 100644--- a/tests/hermes_cli/test_status_lines_held_during_stream_box.py+++ b/tests/hermes_cli/test_status_lines_held_during_stream_box.py@@ -76,12 +76,44 @@ def test_status_line_prints_immediately_outside_a_box(cli_stub):assert not getattr(cli, "_held_status_lines", [])-def test_streamed_flag_survives_tool_call_boundary(cli_stub):- """#65666: the chat-turn 'already streamed' guard must still see the reply after a tool-call- boundary resets per-segment stream state, or an interrupted reply is re-rendered as a Panel."""[email protected]("response, expect_panel", [+ ("Partial answer.", False), # the streamed text itself: already on screen+ ("Operation interrupted: waiting for model response (3.0s elapsed).", True), # never streamed+])+def test_interrupted_reply_panel_after_tool_call_boundary(cli_stub, monkeypatch, response, expect_panel):+ """#65666: an interrupted reply streamed before a tool-call boundary reset per-segment stream+ state must not be re-rendered as a Panel, but an unstreamed interrupt status message still is."""+ from types import SimpleNamespace+ import cli as climod+cli, _ = cli_stub- cli._response_streamed_this_turn = False+ printed = []+ monkeypatch.setattr(climod, "ChatConsole", lambda: SimpleNamespace(print=printed.append))+ cli._streamed_text_this_turn = ""cli._stream_delta("Partial answer.\n")cli._stream_delta(None) # tool-call boundary: flush + per-segment reset- assert cli._stream_box_opened is False- assert cli._response_streamed_this_turn is True+ cli._last_turn_interrupted = True+ turn = SimpleNamespace(use_streaming_tts=False, box_opened=False,+ result={"interrupted": True, "final_response": response})+ cli._chat_print_response_panel(turn, response)+ assert bool(printed) is expect_panel, printed+++def test_unstreamed_final_reply_after_streamed_segment_still_prints_panel(cli_stub, monkeypatch):+ """#65666 scope: the turn-level streamed record only suppresses the Panel for interrupted results.+ A turn that streamed text A, crossed a tool boundary, then returned an unstreamed final B must+ still render B."""+ from types import SimpleNamespace+ import cli as climod++ cli, _ = cli_stub+ printed = []+ monkeypatch.setattr(climod, "ChatConsole", lambda: SimpleNamespace(print=printed.append))+ cli._streamed_text_this_turn = ""+ cli._stream_delta("Looking that up.\n")+ cli._stream_delta(None) # tool-call boundary+ cli._last_turn_interrupted = False+ turn = SimpleNamespace(use_streaming_tts=False, box_opened=False,+ result={"completed": True, "final_response": "Final B"})+ cli._chat_print_response_panel(turn, "Final B")+ assert len(printed) == 1