Skip to content

Commit 999ec63

Browse files
committed
refactor(blocks): align subagent output methods with peer guards, add cap test
1 parent 0f7e049 commit 999ec63

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/pythinker_code/ui/shell/visualize/_blocks.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ def set_subagent_metadata(self, agent_id: str, subagent_type: str) -> None:
518518
def mark_sub_execution_started(self, tool_call_id: str) -> None:
519519
if tool_call_id not in self._ongoing_subagent_tool_calls:
520520
return
521+
if tool_call_id in self._subagent_execution_started:
522+
return
521523
self._subagent_execution_started.add(tool_call_id)
522524
self._renderable = self._compose()
523525

@@ -526,6 +528,8 @@ def append_sub_output_part(
526528
) -> None:
527529
if tool_call_id not in self._ongoing_subagent_tool_calls:
528530
return
531+
if not text:
532+
return
529533
parts = self._subagent_output_parts.setdefault(tool_call_id, [])
530534
parts.append(text)
531535
if stream == "stderr":

tests/ui_and_conv/test_tool_call_block.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ def test_append_sub_output_part_caps_buffer_at_200_chars():
199199
assert len(combined) <= 200
200200

201201

202+
def test_append_sub_output_part_caps_buffer_across_multiple_appends():
203+
block = _ToolCallBlock(_tool_call("Agent", '{"description":"scan"}'))
204+
call = _tool_call_with_id("sub-1", "Bash", '{"command":"ls"}')
205+
block.append_sub_tool_call(call)
206+
for _ in range(30):
207+
block.append_sub_output_part("sub-1", "x" * 10) # 300 chars total, 10 at a time
208+
combined = "".join(block._subagent_output_parts["sub-1"])
209+
assert len(combined) <= 200
210+
211+
202212
def test_append_sub_output_part_tracks_stderr():
203213
block = _ToolCallBlock(_tool_call("Agent", '{"description":"scan"}'))
204214
call = _tool_call_with_id("sub-1", "Bash", '{"command":"cat missing"}')
@@ -222,9 +232,6 @@ def test_mark_sub_execution_started_discards_unknown_id():
222232

223233

224234
def test_finish_sub_tool_call_cleans_up_output_state():
225-
from pythinker_code.wire.types import ToolResult
226-
from pythinker_core.tooling import ToolOk
227-
228235
block = _ToolCallBlock(_tool_call("Agent", '{"description":"scan"}'))
229236
call = _tool_call_with_id("sub-1", "Bash", '{"command":"ls"}')
230237
block.append_sub_tool_call(call)

0 commit comments

Comments
 (0)