fix: emit guardrail halt message to client before closing stream
When the tool loop guardrail fires (max_tool_failures, etc.), the turn exits with guardrail_halt but no final assistant message was emitted to the client. The SSE stream closed silently — indistinguishable from a crash. The stream_delta_callback(None) before tool execution is a display flush, not a hard close. After generating the halt response, emit it through both _safe_print (CLI) and stream_delta_callback (SSE) so clients see the explanation. Fixes #30770
This commit is contained in:
@@ -3470,6 +3470,19 @@ def run_conversation(
|
|||||||
f"⚠️ Tool guardrail halted {decision.tool_name}: {decision.code}"
|
f"⚠️ Tool guardrail halted {decision.tool_name}: {decision.code}"
|
||||||
)
|
)
|
||||||
messages.append({"role": "assistant", "content": final_response})
|
messages.append({"role": "assistant", "content": final_response})
|
||||||
|
# Emit the halt message to the client so it's not
|
||||||
|
# indistinguishable from a crash. The stream display
|
||||||
|
# was flushed (callback(None)) before tool execution,
|
||||||
|
# but the callback is still alive — fire the text
|
||||||
|
# through it so SSE/TUI clients see the explanation.
|
||||||
|
if final_response:
|
||||||
|
agent._safe_print(f"\n{final_response}\n")
|
||||||
|
if agent.stream_delta_callback:
|
||||||
|
try:
|
||||||
|
agent.stream_delta_callback(final_response)
|
||||||
|
agent.stream_delta_callback(None)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
break
|
break
|
||||||
|
|
||||||
# Reset per-turn retry counters after successful tool
|
# Reset per-turn retry counters after successful tool
|
||||||
|
|||||||
Reference in New Issue
Block a user