Fix: Bridge-worker silently drops assistant replies from state.db (31269) - #31291
Closed
dskwe wants to merge 2 commits into
Closed
Fix: Bridge-worker silently drops assistant replies from state.db (31269)#31291dskwe wants to merge 2 commits into
dskwe wants to merge 2 commits into
Conversation
Several exit paths (partial_stream_recovery, fallback_prior_turn_content, max_iterations) set final_response but break without appending a structured assistant message dict to the messages list. _persist_session then writes messages as-is, silently dropping the assistant reply from state.db. Add a safety net before _persist_session that injects final_response as an assistant message when the messages tail doesn't already contain it. Fixes NousResearch#31269
…ore _persist_session 6 tests covering _ensure_final_response_in_messages: - injects when messages has no assistant tail - skips when tail already matches - skips empty/whitespace/placeholder/(empty) - injects even when tail has different assistant content
8 tasks
Contributor
|
Automated hermes-sweeper review: current Evidence:
The PR's proposed |
This was referenced Jul 1, 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 chatting through the TypeScript WebUI (Agent Bridge path), assistant replies are silently missing from
state.db. The response is correctly streamed to the frontend and saved in the WebUI's own session-store, but never written to Hermes Agent's SQLite session store. This causes data inconsistency: the Python WebUI (8787) shows incomplete history for sessions created via the TypeScript WebUI.Root Cause
In
run_conversation(), several exit paths setfinal_responseas a plain string but break out of the loop without appending a structured{"role": "assistant", "content": ...}message dict tomessages:partial_stream_recovery— recovers text from partial SSE chunksfallback_prior_turn_content— falls back to previous turn contentmax_iterations— iteration limit reachedThe normal
text_responsepath already appends at ~L3833, so it works fine. But the edge-case exit paths skip that append, and_persist_session(messages, ...)writes whatever is inmessages— which lacks the assistant reply.Fix
Before
_persist_session(), check iffinal_responseis a non-empty string and the messages tail doesn't already contain it. If not, inject{"role": "assistant", "content": final_response}. This is a safety net that covers all exit paths without modifying each one individually.The check:
final_responseis empty or"(empty)"(preserves existing empty-response handling by_drop_trailing_empty_response_scaffolding)text_responsepath)Changes
agent/conversation_loop.py: Add assistant response injection before_persist_session()call (~L3962)How to test
state.dbmessages before/after — assistant replies should now be persisted