You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
repair_message_sequence aggressively merges separate user messages (v0.16.0+) #45560
The model sees a single blob of text and picks the earliest question to answer, completely unaware the user has moved on. The user must wait for each agent reply before sending the next message, or the agent will keep chasing old questions forever. This is especially painful on instant messaging platforms like QQ where users naturally send quick follow-ups.
This looks genuine. repair_message_sequence (agent/agent_runtime_helpers.py) joins consecutive user messages with \n\n into a single turn. That's needed to satisfy strict role-alternation providers (Anthropic/OpenAI reject back-to-back user turns), but it erases the boundary between semantically distinct messages — so when a user fires several follow-ups (common on IM platforms before the agent replies), the model receives one blob and tends to answer the earliest question, exactly as you describe.
The text content is preserved (the merge is honest about that), but the turn structure isn't, and it appears amplified by the context-compaction interactions in #44837 and #43062 (both closed, same "user messages merged into single turn" symptom) and the open #43066. A fix probably wants to keep the original message objects in session history and only collapse for the wire copy at API-call time (or use an explicit boundary marker), so alternation is satisfied without losing per-message semantics. PR-able.
Hi everyone, I recently ran into this exact same issue while deploying Hermes Agent via the Telegram adapter connected to vLLM (Gemma 4). I want to share my debugging findings and a working hotfix that resolves both the message boundary destruction and the DB cursor desync.
The Context & Root Cause:
When users interact via IM platforms (like Telegram or Discord), they frequently send multiple short, consecutive messages (e.g., Msg 1: "Is the server up?", Msg 2: "Check the cron jobs").
In agent/agent_runtime_helpers.py, the repair_message_sequence function attempts to enforce strict role alternation (to prevent 400 Bad Request from strict providers like Anthropic or vLLM). In Pass 2, it merges consecutive user messages using string concatenation.
While this satisfies the API provider, it destroys the semantic boundaries of the user's distinct prompts. Furthermore, because the array length shrinks during this merge, it breaks the database flush cursor (which relates to Issue #43066), causing subsequent assistant replies to be dropped from the session history.
The Workaround (Hotfix):
Instead of aggressively merging the user messages and shrinking the array, we can safely bypass the provider's strict alternation check by injecting a "dummy" empty assistant message between consecutive user messages.
Here is the modification I made in agent/agent_runtime_helpers.py (inside Pass 2):
# Pass 2: Merge consecutive user messages -> CHANGED: Inject dummy assistant messagemerged: List[Dict] = []
formsginfiltered:
if (
mergedandisinstance(msg, dict)
andmsg.get("role") =="user"andisinstance(merged[-1], dict)
andmerged[-1].get("role") =="user"
):
# Inject a dummy assistant turn to satisfy strict alternation without mergingmerged.append({"role": "assistant", "content": "\u200B"})
merged.append(msg)
repairs+=1else:
merged.append(msg)
Four PRs were compared, but only #46459 and #63298 directly address #45560. #46459 adds textual boundary markers while still collapsing canonical turns; #63298 preserves separate prompts through FIFO queueing, canonical history, and SessionDB, then intentionally strips source metadata and merges adjacent users only in the transient provider copy with a boundary marker, while #31496 and #66027 fix different gateway merge defects.
fix: preserve queued prompt boundaries end to end #63298best fix — (+1937/-267) — fixes: Replaces the TUI single merged slot with an identity-preserving FIFO, retains separate source turns in canonical history and SessionDB, and merges only a copied provider payload with an explicit [Next user message] marker after stripping source metadata. The keep_open review on fix: preserve queued prompt boundaries end to end #63298 identified a steer-mode regression, but the later diff and contributor evidence explicitly restore accepted steering plus rejected/unavailable-steer fallback queueing, with the reported PR head clean and all required checks passing.
#46459 and #63298 overlap on #45560 and the provider-visible boundary-marker concept, but #63298 is the comprehensive superseding implementation; #31496 and #66027 are related only through gateway message merging and are not duplicates.
Suggested consolidation
Merge #63298 after final maintainer review: it addresses both destructive canonical user-turn merging and the TUI busy-queue source-boundary loss, while preserving strict-provider compatibility through a wire-only merge with a textual marker—not source identity in provider serialization. Close #46459 as superseded by #63298 despite its keep_open review because its diff leaves canonical turns collapsed and omits the TUI queue root cause; keep #31496 and #66027 triaged separately rather than closing them as duplicates.
Complex graph
flowchart LR
classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
classDef best stroke-width:3px,stroke:#b45309
classDef target stroke-width:3px,stroke:#4338ca
I45560(["issue #45560 (open)"])
subgraph Dup46459 ["PRs duplicating each other"]
P46459["PR #46459 (open)"]
P63298["PR #63298 (open)"]
end
P46459 -.->|partial| I45560
P63298 -->|best fix| I45560
class I45560 open
class I45560 target
class P46459 open
class P63298 open
class P63298 best
click I45560 "https://github.com/NousResearch/hermes-agent/issues/45560"
click P46459 "https://github.com/NousResearch/hermes-agent/pull/46459"
click P63298 "https://github.com/NousResearch/hermes-agent/pull/63298"
Loading
Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed or no verify verdict yet (state tag in the node label).
Cross-PR triage: Reviewed 4 pull requests and 1 issue in this complex. Each diff was read against this issue; Assessment working set: 168 kB of PR diffs, 10 kB of issue/PR text, 14 kB of discussion (18 comments), 6 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.
Activity
AIalliAI commentedon Jun 13, 2026
This looks genuine.
repair_message_sequence(agent/agent_runtime_helpers.py) joins consecutive user messages with\n\ninto a single turn. That's needed to satisfy strict role-alternation providers (Anthropic/OpenAI reject back-to-back user turns), but it erases the boundary between semantically distinct messages — so when a user fires several follow-ups (common on IM platforms before the agent replies), the model receives one blob and tends to answer the earliest question, exactly as you describe.The text content is preserved (the merge is honest about that), but the turn structure isn't, and it appears amplified by the context-compaction interactions in #44837 and #43062 (both closed, same "user messages merged into single turn" symptom) and the open #43066. A fix probably wants to keep the original message objects in session history and only collapse for the wire copy at API-call time (or use an explicit boundary marker), so alternation is satisfied without losing per-message semantics. PR-able.
kairosys commentedon Jun 28, 2026
Hi everyone, I recently ran into this exact same issue while deploying Hermes Agent via the Telegram adapter connected to vLLM (Gemma 4). I want to share my debugging findings and a working hotfix that resolves both the message boundary destruction and the DB cursor desync.
The Context & Root Cause:
When users interact via IM platforms (like Telegram or Discord), they frequently send multiple short, consecutive messages (e.g., Msg 1: "Is the server up?", Msg 2: "Check the cron jobs").
In
agent/agent_runtime_helpers.py, therepair_message_sequencefunction attempts to enforce strict role alternation (to prevent400 Bad Requestfrom strict providers like Anthropic or vLLM). In Pass 2, it merges consecutive user messages using string concatenation.While this satisfies the API provider, it destroys the semantic boundaries of the user's distinct prompts. Furthermore, because the array length shrinks during this merge, it breaks the database flush cursor (which relates to Issue #43066), causing subsequent assistant replies to be dropped from the session history.
The Workaround (Hotfix):
Instead of aggressively merging the user messages and shrinking the array, we can safely bypass the provider's strict alternation check by injecting a "dummy" empty assistant message between consecutive user messages.
Here is the modification I made in
agent/agent_runtime_helpers.py(insidePass 2):GottZ commentedon Jul 28, 2026
Summary
Four PRs were compared, but only #46459 and #63298 directly address #45560. #46459 adds textual boundary markers while still collapsing canonical turns; #63298 preserves separate prompts through FIFO queueing, canonical history, and SessionDB, then intentionally strips source metadata and merges adjacent users only in the transient provider copy with a boundary marker, while #31496 and #66027 fix different gateway merge defects.
Related pull requests
unrelated— (+67/-8) — unrelated: Fixes a three-sender queue-mode collision that can drop an event, but it does not address repair_message_sequence or preservation of separate user turns. Despite the keep_open review on fix(gateway): prevent third-sender message drop in queue-mode debounce #31496, that review supports keeping it as a separate delivery-loss fix and also blocks its current cross-sender merge because it misattributes C under A.partial— (+51/-26) — partial fix: Adds an explicit later-message marker to runtime, Anthropic, and gateway text merges, improving model-visible boundaries, but repair_message_sequence still destructively collapses canonical user objects and the TUI busy queue remains uncovered. Despite the keep_open review on fix(agent): preserve later user message boundaries #46459, fix: preserve queued prompt boundaries end to end #63298 supersedes its repair_message_sequence aggressively merges separate user messages (v0.16.0+) #45560 scope by preserving canonical turns and covering the TUI FIFO path rather than only marking already-merged text.best fix— (+1937/-267) — fixes: Replaces the TUI single merged slot with an identity-preserving FIFO, retains separate source turns in canonical history and SessionDB, and merges only a copied provider payload with an explicit [Next user message] marker after stripping source metadata. The keep_open review on fix: preserve queued prompt boundaries end to end #63298 identified a steer-mode regression, but the later diff and contributor evidence explicitly restore accepted steering plus rejected/unavailable-steer fallback queueing, with the reported PR head clean and all required checks passing.unrelated— (+346/-8) — unrelated: Refreshes Telegram merged-event trigger, reply, and provenance metadata so replies anchor to the latest follow-up, but it continues merging text and does not change canonical turn preservation or provider-wire repair. Its keep_open review confirms this distinct Telegram metadata scope rather than a repair_message_sequence aggressively merges separate user messages (v0.16.0+) #45560 implementation.Duplicates
#46459 and #63298 overlap on #45560 and the provider-visible boundary-marker concept, but #63298 is the comprehensive superseding implementation; #31496 and #66027 are related only through gateway message merging and are not duplicates.
Suggested consolidation
Merge #63298 after final maintainer review: it addresses both destructive canonical user-turn merging and the TUI busy-queue source-boundary loss, while preserving strict-provider compatibility through a wire-only merge with a textual marker—not source identity in provider serialization. Close #46459 as superseded by #63298 despite its keep_open review because its diff leaves canonical turns collapsed and omits the TUI queue root cause; keep #31496 and #66027 triaged separately rather than closing them as duplicates.
Complex graph
flowchart LR classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937 classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151 classDef best stroke-width:3px,stroke:#b45309 classDef target stroke-width:3px,stroke:#4338ca I45560(["issue #45560 (open)"]) subgraph Dup46459 ["PRs duplicating each other"] P46459["PR #46459 (open)"] P63298["PR #63298 (open)"] end P46459 -.->|partial| I45560 P63298 -->|best fix| I45560 class I45560 open class I45560 target class P46459 open class P63298 open class P63298 best click I45560 "https://github.com/NousResearch/hermes-agent/issues/45560" click P46459 "https://github.com/NousResearch/hermes-agent/pull/46459" click P63298 "https://github.com/NousResearch/hermes-agent/pull/63298"Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed or no verify verdict yet (state tag in the node label).
Cross-PR triage: Reviewed 4 pull requests and 1 issue in this complex. Each diff was read against this issue; Assessment working set: 168 kB of PR diffs, 10 kB of issue/PR text, 14 kB of discussion (18 comments), 6 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.