fix(engine): use user role for sub-agent completion runtime message#2057
Open
h3c-hexin wants to merge 1 commit into
Open
fix(engine): use user role for sub-agent completion runtime message#2057h3c-hexin wants to merge 1 commit into
h3c-hexin wants to merge 1 commit into
Conversation
The sub-agent completion hand-off injected into the parent turn used role "system". Some OpenAI-compatible backends apply a strict chat template (e.g. vLLM serving Qwen3) that requires any system message to be messages[0]; a system message appended mid-conversation makes the template raise "System message must be at the beginning", returned as a 400 BadRequest that breaks the entire sub-agent hand-off in the parent turn. Switch the role to "user". The internal-event framing is already carried by the `visibility="internal"` tag and the surrounding text, so the role change costs no semantics — it only removes the template incompatibility. Updates the colocated unit test to pin the new role. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request changes the role of subagent completion runtime messages from 'system' to 'user' in crates/tui/src/core/engine/turn_loop.rs. This modification addresses compatibility issues with OpenAI-compatible backends, such as vLLM serving Qwen3, which require system messages to be positioned at the start of a conversation. Corresponding unit tests were updated to reflect this change. I have no feedback to provide.
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
subagent_completion_runtime_messagebuilds the sub-agent completion hand-off that gets appended into the parent turn withrole: "system". That message is injected mid-conversation (not at the front).Some OpenAI-compatible backends apply a strict chat template that requires any
systemmessage to bemessages[0]. The clearest case is vLLM serving Qwen3 — its chat template raises:vLLM returns this as a 400 BadRequest, which fails the request that carries the sub-agent result back to the parent. The whole sub-agent hand-off breaks on these backends.
Fix
Switch the role of this single internal runtime message from
systemtouser.The "this is an internal runtime event, not user input" framing is already carried by the
visibility="internal"tag and the surrounding instruction text, so the role itself carries no semantic weight to the model here — it only determines chat-template placement. Usinguserkeeps the message valid mid-conversation on strict templates while reading identically to lenient ones (Anthropic / OpenAI proper).Scope
subagent_completion_runtime_message, plus a rationale comment.subagent_completion_handoff_is_internal_user_message) to pin the new role.Test
🤖 Generated with Claude Code