@@ -151,6 +151,9 @@ def __init__(
151151 # Fatal error detection - 检测到致命错误后立即中断
152152 self ._fatal_error_occurred = False # 致命错误标志
153153
154+ # Interruption state - suppress output after user interruption until next response
155+ self ._interrupted = False # 打断状态标志,防止重复消息块
156+
154157 # Native image input rate limiting
155158 self ._last_native_image_time = 0.0 # 上次原生图片输入时间戳
156159
@@ -586,6 +589,9 @@ async def handle_interruption(self):
586589
587590 logger .info ("Handling interruption" )
588591
592+ # Mark as interrupted to suppress any remaining output until next response
593+ self ._interrupted = True
594+
589595 # 1. Cancel the current response
590596 if self ._current_response_id :
591597 await self .cancel_response ()
@@ -664,6 +670,7 @@ async def handle_messages(self) -> None:
664670 elif event_type == "response.created" :
665671 self ._current_response_id = event .get ("response" , {}).get ("id" )
666672 self ._is_responding = True
673+ self ._interrupted = False # Clear interruption flag on new response
667674 self ._is_first_text_chunk = self ._is_first_transcript_chunk = True
668675 # 清空转录 buffer,防止累积旧内容
669676 self ._output_transcript_buffer = ""
@@ -690,7 +697,7 @@ async def handle_messages(self) -> None:
690697 self ._print_input_transcript = False
691698 self ._output_transcript_buffer = ""
692699
693- if not self ._skip_until_next_response :
700+ if not self ._skip_until_next_response and not self . _interrupted :
694701 if event_type in ["response.text.delta" , "response.output_text.delta" ]:
695702 if self .on_text_delta :
696703 if "glm" not in self .model :
0 commit comments