fix(sse): append synthetic user turn for GLM-family upstreams (400 [1214]) - #11209
Merged
diegosouzapw merged 2 commits intoAug 23, 2026
Merged
Conversation
…ouzapw#1214) Z.AI/Zhipu console gateways (opencode-go, opencode-zen, glm-* targets) reject any chat.completions payload whose messages array has no role:"user" turn with 400 [1214] 'The messages parameter is illegal'. Claude Code agent loops legitimately produce that shape: every inbound user turn carries only tool_result blocks (translated to role:"tool") and context compression can evict the original prompt, leaving the translated payload as system + assistant* + tool* only. translateRequest now flags GLM-family providers (_ensureUserTurn) and claudeToOpenAIRequest appends a minimal synthetic user turn when none survives conversion. Appending at the end keeps earlier bytes identical for upstream prompt caches; non-GLM providers keep byte-identical bodies. Verified live against the opencode-go upstream on 2026-08-23: - system + assistant(tool_calls) + tool -> 1214 - same + trailing user -> 200 - assistant content:null/"" with a user present -> 200
The new covering unit test was missing from the mutation-testing tap.testFiles allowlist, failing the strict Fast Quality Gates check.
diegosouzapw
merged commit Aug 23, 2026
e66181b
into
diegosouzapw:release/v3.8.50
11 of 16 checks passed
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
Claude Code sessions routed through OmniRoute to
opencode-gointermittently fail with:The error text originates entirely from the upstream Z.AI/Zhipu console gateway — OmniRoute just forwards it.
Root cause (verified live against the upstream, 2026-08-23)
GLM-family gateways reject any
messagesarray that contains norole:"user"turn:system + assistant(tool_calls) + toolusercontent:null/""with a user presentClaude Code agent loops legitimately produce the failing shape: every inbound user turn carries only
tool_resultblocks (translated torole:"tool"), and context compression can evict the original prompt — leaving the translated payload assystem + assistant* + tool*with zero user turns.Fix
translateRequestflags GLM-family upstreams (opencode-go,opencode-zen,glm/zhipu/z-aimodel ids) with a transient_ensureUserTurncredential marker (same pattern as_copilotClient/_preserveCacheControl).claudeToOpenAIRequestappends a minimal synthetic user turn ({role:"user", content:"(continue)"}) when no user message survives conversion.Appending at the end keeps every earlier byte identical for upstream prompt caches; non-GLM providers keep byte-identical request bodies.
Testing
tests/unit/claude-to-openai-glm-user-turn.test.ts(red→green; injection only when flagged, no duplicate when a user exists, unchanged body without the flag)eslintclean on touched files;npm run typecheck:corecleanPOST /v1/messagesreturns 200 with model output