fix: emit guardrail halt message to client before closing stream#30807
Open
annguyenNous wants to merge 1 commit into
Open
fix: emit guardrail halt message to client before closing stream#30807annguyenNous wants to merge 1 commit into
annguyenNous wants to merge 1 commit into
Conversation
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 NousResearch#30770
Collaborator
|
Competing fix: PRs #30808 and #30813 also address #30770. #30813 is the most comprehensive (covers stream delta, flush, and interim message channels with a reusable helper + 473-line test suite). #30808 is the cleanest minimal fix (reuses |
This was referenced May 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the tool loop guardrail fires (max_tool_failures, repeated failures, etc.), the turn exits with
guardrail_haltbut no final assistant message is emitted to the client. The SSE stream closes silently — from the user's perspective (especially via API/SSE clients like Open WebUI), the conversation just goes silent with no explanation. Indistinguishable from a crash.Fixes #30770
Root Cause
In
agent/conversation_loop.py, the guardrail halt path (line ~3429):final_responsevia_toolguard_controlled_halt_response(decision)messageshistoryBut the
stream_delta_callback(None)at line 3423 (display flush before tool execution) already closed the display stream. Thefinal_responsewas never emitted to the client — only stored in internal history.Fix
After generating the halt message, emit it through both channels:
agent._safe_print()— for CLI/TUI usersagent.stream_delta_callback(final_response)— for SSE/API clients (Open WebUI, etc.)The
stream_delta_callback(None)is a display flush, not a hard close — the callback is still alive and can accept new text.Before vs After
Tests
python -m py_compile agent/conversation_loop.py✓