Repository navigation
fix: merge injected system block into the first system message - #1
nicksosnovsky wants to merge 1 commit into
Conversation
The plugin appended a second system message via experimental.chat.system.transform, which proxies like litellm/vLLM reject with 'System message must be at the beginning' (400). Append the block to the existing system message instead.
sehaxe
left a comment
There was a problem hiding this comment.
Reviewed against opencode source + the live plugin.
Verdict: correct diagnosis, correct fix — merged (adapted).
Confirmed the root cause in opencode's session/llm/request.ts: the system prompt starts as system = [header], and after the transform hook opencode only coalesces when system.length > 2. Pushing a 2nd element yields exactly two system messages, which litellm/vLLM reject. Your curl repro against api-llm.novacom.by matches this exactly.
Applied to master with two changes:
- Reconciled a conflict — the branch was based on an older master. It used
systemBlock()with no arg, which would have reverted the sessionID threading (systemBlock(input?.sessionID)) that the role-resume fix depends on. Kept the sessionID arg, applied your merge logic on top. - Added the missing test — all existing transform tests initialize
output.system = [], so they exercised thepushfallback and never the merge path. Added a test assertingsystem.length === 1when starting from a non-empty header.
Minor note (no action): the else output.system.push(block) branch is dead in production — opencode always passes a non-empty system (it holds the header). It's kept only so tests with system: [] still exercise the injection. Fine to keep.
60 tests green. Thank you for the fix — it directly affects the corp LiteLLM proxy.
|
Merged to master (adapted, with sessionID conflict reconciled + test added). Thanks! |
Problem
Every request fails with
litellm.BadRequestError: OpenAIException - System message must be at the beginning(HTTP 400) when using OpenAI-compatible proxies backed by litellm/vLLM (e.g. qwen via a litellm proxy).Root cause
The
experimental.chat.system.transformhook appended the memory/goal/rules block as a second system message:opencode sends every element of
output.systemas a separate{role: "system"}message. Some servers reject more than one system message even when they are all at the beginning.Repro
->
400 System message must be at the beginning. Removing the second system message fixes it.Fix
Append the block to the existing first system message instead of pushing a new one:
Verification
bun test bulba.test.ts: 45 pass / 1 fail (the failingsearch_memorytest also fails on clean master - Windows environment, unrelated to this change).system: []array, which still works via thepushfallback.