Skip to content

fix(agent): preserve later user message boundaries - #46459

Open
LeonSGP43 wants to merge 1 commit into
NousResearch:mainfrom
LeonSGP43:fix/45560-user-message-boundaries
Open

fix(agent): preserve later user message boundaries#46459
LeonSGP43 wants to merge 1 commit into
NousResearch:mainfrom
LeonSGP43:fix/45560-user-message-boundaries

Conversation

@LeonSGP43

Copy link
Copy Markdown
Contributor

Fixes #45560.

Summary

  • preserve explicit later-message boundaries when forced role-alternation repair merges consecutive user text turns
  • use the same boundary marker for queued gateway text follow-ups so bursty IM messages keep their chronology
  • keep Anthropic's same-role fallback merge aligned with the repaired runtime format

Verification

  • uv run --frozen pytest tests/run_agent/test_message_sequence_repair.py tests/gateway/test_active_session_text_merge.py tests/agent/test_anthropic_adapter.py -k "merge or merges_consecutive_user_messages"
  • uv run --frozen ruff check utils.py agent/agent_runtime_helpers.py agent/anthropic_adapter.py gateway/platforms/base.py tests/run_agent/test_message_sequence_repair.py tests/gateway/test_active_session_text_merge.py tests/agent/test_anthropic_adapter.py
  • git diff --check HEAD^ HEAD

Note

  • targeted pytest passes with one preexisting PytestUnraisableExceptionWarning from text-debounce task cleanup outside the changed merge logic.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Jun 15, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Fix for agent message boundary preservation: ensures later user message boundaries are not lost in the conversation processing pipeline.

Looks Good

  • Clean, well-scoped
  • No security or stability concerns

Reviewed by Hermes Agent

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for isolating the alternation-repair marker path. The reported behavior is still present on current main: agent/agent_runtime_helpers.py:543-555 merges adjacent user text and rewrites the live message list, called before API-copy construction at agent/conversation_loop.py:783-794.

Problems

  • This is not an end-to-end #45560 fix: source turns remain canonically collapsed before persistence. The currently linked competing PR #63298 documents the broader wire-only merge/FIFO approach.
  • tui_gateway/server.py:5074-5091 independently retains one busy queued-prompt slot and merges a second prompt with \n\n; this PR does not cover that path.
  • The changed tests calculate expected values through merge_later_user_text, so they do not assert the actual [Later user message] contract.

Suggested changes

  • Either scope the PR to the narrow textual-marker behavior, or preserve canonical turns and merge only the API copy.
  • Add direct literal-marker and empty-input tests, plus coverage for the TUI busy-queue path if retaining the #45560 linkage.

Automated hermes-sweeper review.

assert len(messages) == 1
assert messages[0]["role"] == "user"
assert messages[0]["content"] == "first\n\nsecond"
assert messages[0]["content"] == merge_later_user_text("first", "second")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This expected value is computed by the same production helper the test exercises, so it does not pin the required marker. Please add a direct assertion for the literal [Later user message] boundary (and empty-side behavior).

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit labels Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:blast-broad Sweeper blast radius: broad — a core path most sessions hit sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

repair_message_sequence aggressively merges separate user messages (v0.16.0+)

4 participants