fix(api): send tool progress as custom SSE event to prevent model corruption#7500
Merged
Conversation
…ruption (#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 #6972
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.
Summary
Tool progress markers (
⏰ terminal,🔍 web_search) were injected directly intodelta.contentchunks in the SSE stream. OpenAI-compatible frontends (Open WebUI, LobeChat, LibreChat) storedelta.contentverbatim as assistant messages and send them back — polluting conversation history and potentially causing models to imitate the markers instead of calling tools.Sends tool progress as custom
event: hermes.tool.progressSSE events instead. Per SSE spec, clients that don't understand custom events silently ignore them. Clients that do can render them as progress UI.Changes
gateway/platforms/api_server.py:_on_tool_progresspushes tagged tuples, new_emit()helper routes to custom SSE eventtests/gateway/test_api_server.py: Tests verify markers appear as custom events and do NOT leak intodelta.contentTest results
106 API server tests passing
Salvaged from #7014 (@Bartok9). Fixes #6972.