Repository navigation
fix(protocol): merge a Responses assistant message item into the trailing assistant turnfix(protocol): merge a Responses assistant message item into the trai… - #176
Closed
billy-yi wants to merge 1 commit into
Conversation
…ling assistant turn A Responses turn can carry its assistant text in a message item that follows the function_call items of the same turn. decodeBridgeRequest appended that item as a new bridge message, so encodeChatRequest saw an assistant message while the tool calls it belongs to were still waiting for their results and rejected the request with: messages[N]: assistant message appears before tool results for ... The text now joins the trailing assistant message, which is what the Chat and Anthropic encoders can express: one assistant turn holding content and tool_calls, followed by the tool results.
jasonxu114514
added a commit
that referenced
this pull request
Nov 16, 2026
Preserve upstream HTTP failures across transport retries, classify title requests before shaping, and rename legacy functions exactly once. Keep adjacent Responses assistant items together, including interleaved text and calls. Add opt-in prompt environment overrides with matching shell descriptions, strict validation, and WebUI round-trip preservation. Document compatibility boundaries and retain existing defaults. Include the requested test/ ignore rule. Offline zz_ regressions passed and were removed after validation as requested; vet and Windows/Linux builds passed. Refs #173, #175, #176, #178, #179, #181
Owner
|
Thanks @billy-yi. Implemented on main in 14faec7: 14faec7 . The existing appendBridgeBlock now joins adjacent assistant text, reasoning and calls, including call-text-call; user messages and tool results remain boundaries. Offline Responses-to-Chat/Anthropic regressions, vet and Windows/Linux builds passed. Operator-requested zz_ tests were removed afterward. No live upstream check. This supersedes the proposed fix; PR commits were not merged. |
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.
SymptomA client that speaks the Responses protocol and streams the assistant text after its function calls gets every such request rejected with HTTP 400:
prepare go upstream request: messages[5]: assistant message appears before tool results for call_…, call_…The model is fine and the same conversation succeeds whenever the text happens to arrive before the tool calls, so the failure looks random.## Root causeA Responses turn can carry its text in amessageitem that follows thefunction_callitems of the same turn:json{"type":"function_call","call_id":"call_a",...},{"type":"function_call","call_id":"call_b",...},{"type":"message","role":"assistant","content":[{"type":"output_text","text":"I will inspect the directory first."}]},{"type":"function_call_output","call_id":"call_a",...},{"type":"function_call_output","call_id":"call_b",...}````decodeBridgeRequest` appended that message item as a **new** bridge message, so `encodeChatRequest` saw an assistant message while the tool calls it belongs to were still waiting for their results, and rejected the request:messages[N]: assistant message appears before tool results for …````appendBridgeBlockonly merges a standalone item into the previous message when that message holds *only* tool calls or results, and amessage` item is appended directly, so the merge never happened for text.## FixThe text of an assistant `message` item now joins the trailing assistant message. That is exactly what the Chat and Anthropic encoders can express: one assistant turn holding `content` and `tool_calls`, followed by the tool results. An assistant message that starts a new turn (the previous message is a user turn or a tool result) still starts its own message.## Tests`internal/protocol/request_test.go` covers both directions:* `TestDecodeResponsesAssistantTextAfterToolCalls` — text item after the calls: one assistant bridge message holding 2 calls and 1 text block, and `encodeBridgeRequest(Chat, …)` succeeds. It fails on `main` with `got 5 bridge messages, want 4`.* `TestDecodeResponsesAssistantTextAfterToolResults` — text of the next assistant turn still gets its own message.`go vet ./internal/protocol/ && go test ./internal/protocol/` passes.## ReproductionAny Responses client that emits the assistant text after the function calls reproduces it against the Go upstream (the `/zen/go` and `/inference` lanes); sending the same items with the text before the calls returns 200.…ling assistant turnA Responses turn can carry its assistant text in a message item that follows the function_call items of the same turn. decodeBridgeRequest appended that item as a new bridge message, so encodeChatRequest saw an assistant message while the tool calls it belongs to were still waiting for their results and rejected the request with:
messages[N]: assistant message appears before tool results for ...
The text now joins the trailing assistant message, which is what the Chat and Anthropic encoders can express: one assistant turn holding content and tool_calls, followed by the tool results.