fix: prevent consecutive same-role messages in ephemeral injections#10
Open
ramparte wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: prevent consecutive same-role messages in ephemeral injections#10ramparte wants to merge 1 commit intomicrosoft:mainfrom
ramparte wants to merge 1 commit intomicrosoft:mainfrom
Conversation
All injection paths in the orchestrator now check if the last message has the same role before appending. If so, they merge the content into the existing message instead of creating a consecutive duplicate. This is structural prevention - regardless of what role a hook requests, the orchestrator will never create consecutive messages with the same role. This fixes model confusion about user vs. system messages. Affected paths: - provider:request ephemeral injection (default path) - provider:request append_to_last_tool_result fallback - tool:post pending ephemeral injection (both paths) - orchestrator loop-limit reminder 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
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
The orchestrator blindly appends ephemeral injections as new messages with whatever role the hook requests. When a hook uses
context_injection_role="user"and the last message is alreadyuserrole, this creates consecutiveusermessages that violate role alternation and confuse models about message attribution.The loop-limit reminder had the same bug - it always appended a hardcoded
userrole message without checking what the last message was.Fix
Structural prevention across all injection paths: before appending any ephemeral injection, check if the last message has the same role. If so, merge the content into the existing message with a
\n\nseparator. This prevents ANY hook from accidentally creating role alternation violations, regardless of its configuration.Paths fixed:
provider:requestdefault injection path - merge if same roleprovider:requestappend_to_last_tool_resultfallback (when last msg isn'ttool) - merge if same roletool:postpending injection default path - merge if same roletool:postpending injection fallback (when last msg isn'ttool) - merge if same roleusermessage instead of always appending new oneRelated
Companion PR in amplifier-module-hooks-status-context fixes the hook itself to use
append_to_last_tool_result=True.Testing
amplifier_core.llm_errorsnot yet published) unrelated to this change🤖 Generated with Amplifier