fix(api): send tool progress as custom SSE event to prevent model corruption#7014
Closed
Bartok9 wants to merge 1 commit into
Closed
fix(api): send tool progress as custom SSE event to prevent model corruption#7014Bartok9 wants to merge 1 commit into
Bartok9 wants to merge 1 commit into
Conversation
…ruption (NousResearch#6972) Tool progress markers (e.g. `⏰ list`) were injected directly into SSE delta.content chunks. OpenAI-compatible frontends (Open WebUI, LobeChat, etc.) store delta.content verbatim as the assistant message and send it back on subsequent requests. After enough turns, the model learns to emit these markers as plain text instead of issuing real tool calls — silently hallucinating tool results without ever running them. Fix: Send tool progress as a custom `event: hermes.tool.progress` SSE event instead of mixing it into delta.content. Per the SSE spec, clients that don't understand a custom event type silently ignore it, so this is backward-compatible. Frontends that want to render progress indicators can listen for the custom event without persisting it to conversation history. The /v1/runs endpoint already uses structured events — this aligns the /v1/chat/completions streaming path with the same principle. Closes NousResearch#6972
Contributor
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
Tool progress markers (e.g.
⏰ list,🔍 web_search) were injected directly into SSEdelta.contentchunks in the/v1/chat/completionsendpoint. OpenAI-compatible frontends (Open WebUI, LobeChat, LibreChat, etc.) storedelta.contentverbatim as the assistant message and send it back on subsequent requests.After enough turns (~10-15), the model learns to emit these markers as plain text instead of issuing real tool calls — silently hallucinating tool results. The user sees what looks like a working tool response, but no tool ever runs and underlying state is never modified. Smaller/local models (Gemma 26B, etc.) are especially vulnerable.
See #6972 for an excellent detailed reproduction and root cause analysis by @Swift42.
Root Cause
_on_tool_progress()inapi_server.pypushed formatted marker strings directly onto_stream_q— the same queue that feedsdelta.contentSSE chunks:Fix
Send tool progress as a custom SSE event type (
event: hermes.tool.progress) instead of mixing it intodelta.content:Per the SSE specification, clients that don't understand a custom event type silently ignore it. This means:
data:events). The corruption loop is broken.hermes.tool.progressevents to render progress indicators without persisting them./v1/chat/completionswith the same principle.Implementation
_on_tool_progress()now pushes a tagged tuple("__tool_progress__", payload)instead of a plain string_emit()helper in the SSE writer routes tagged tuples toevent: hermes.tool.progressand plain strings to normaldelta.contentchunksdelta.contentTesting
test_stream_includes_tool_progress: Verifies markers appear asevent: hermes.tool.progressand are absent from anychat.completion.chunkcontent deltatest_stream_tool_progress_skips_internal_events: Verifies internal events still suppressed, real progress uses custom event typeBackward Compatibility
/v1/chat/completionsis unaffected/v1/runsendpoint is unaffected (already uses structured events)Closes #6972