Skip to content

Error with unsloth/Qwen3.5-27B-GGUF:Q3_K_S #5

Closed

Description

@julitroalves

When running unsloth/Qwen3.5-27B-GGUF:Q3_K_S model I'm getting this error:

srv    operator(): got exception: {"error":{"code":500,"message":"\n------------\nWhile executing CallExpression at line 85, column 32 in source:\n...first %}↵            {{- raise_exception('System message must be at the beginnin...\n                                           ^\nError: Jinja Exception: System message must be at the beginning.","type":"server_error"}}
srv  log_server_r: done request: POST /v1/chat/completions 127.0.0.1 500
srv    operator(): got exception: {"error":{"code":500,"message":"\n------------\nWhile executing CallExpression at line 85, column 32 in source:\n...first %}↵            {{- raise_exception('System message must be at the beginnin...\n                                           ^\nError: Jinja Exception: System message must be at the beginning.","type":"server_error"}}
srv  log_server_r: done request: POST /v1/chat/completions 127.0.0.1 500

My params:

llama-server \
    -hf unsloth/Qwen3.5-27B-GGUF:Q3_K_M \
    -ngl 90 \
    -fit on \
    --cache-ram 2056 \
    --parallel 1 \
    --ctx-size 62536 \
    --temp 0.6 \
    --top-p 0.95 \
    --top-k 20 \
    --min-p 0.00 \
    --cache-type-k q4_0 --cache-type-v q4_0 \
    --flash-attn on \
    --kv-unified \
    --fit-target 100 \
    --reasoning off --threads 16 --jinja -ctxcp 5

Activity

  1. ualtinok commented on Apr 10, 2026

    @ualtinok
    Contributor

    Could you give more information? Are you trying to use QWEN as your main model or historian, dreamer etc? Also what error you're getting? Your configs and logs would be also valuable.

    bunx @cortexkit/opencode-magic-context@latest doctor
    output also

  2. julitroalves commented on Apr 10, 2026

    @julitroalves
    Author
    ➜  opencode npx @cortexkit/opencode-magic-context@latest doctor
    ┌  Magic Context Doctor
    │
    ◆  OpenCode installed
    │
    ◆  OpenCode config: /home/julio/.config/opencode/opencode.json
    │
    ◆  Magic Context config: /home/julio/.config/opencode/magic-context.jsonc
    │
    ◆  Plugin registered in opencode.json
    │
    ◆  No conflicts detected (compaction, DCP, OMO hooks)
    │
    ◆  TUI sidebar plugin configured
    │
    ◆  Plugin cache up to date (v0.8.6)
    │
    ●  Log file: /tmp/magic-context.log (242 KB)
    
    │
    └  Everything looks good! ✨
    
  3. julitroalves commented on Apr 10, 2026

    @julitroalves
    Author

    magic-context.jsonc:

    {
      "$schema": "https://raw.githubusercontent.com/cortexkit/opencode-magic-context/master/assets/magic-context.schema.json",
      "historian": {
        "model": "unsloth/Qwen3.5-27B-GGUF:Q3_K_S"
      },
      "dreamer": {
        "enabled": true,
        "model": "claude-haiku-4-5"
      },
      "sidekick": {
        "enabled": true,
        "model": "unsloth/Qwen3.5-27B-GGUF:Q3_K_S"
      }
    }
    
  4. julitroalves commented on Apr 10, 2026

    @julitroalves
    Author

    Yeah, QWEN is my main local model. I'm using it as a historian.

  5. julitroalves commented on Apr 10, 2026

    @julitroalves
    Author

    I'm think is something related to --jinja template thing because of this message: Error: Jinja Exception: System message must be at the beginning.","type":"server_error"}}

  6. ualtinok commented on Apr 11, 2026

    @ualtinok
    Contributor

    (Answer from MagicContext Agent)

    Thanks for the detailed repro — I traced this and it's a real interaction, but not strictly a magic-context bug. Here's what I found:

    Root cause

    Qwen3.5's Jinja chat template enforces a strict "exactly one system message at position 0" rule. When llama-server is run with --jinja, it renders the actual template, which walks the messages list and raises the exception you're seeing the moment it encounters a second role: "system" message.

    The problem is that OpenCode sends two system messages to the provider when any plugin modifies the system prompt:

    • system[0]: the agent base prompt (kept separate so Anthropic prompt caching stays stable across plugin changes)
    • system[1]: plugin-injected content rejoined into one message

    That logic lives in opencode/packages/opencode/src/session/llm.ts:122-163:

    // rejoin to maintain 2-part structure for caching if header unchanged
    if (system.length > 2 && system[0] === header) {
      const rest = system.slice(1)
      system.length = 0
      system.push(header, rest.join("\n"))
    }
    // ...
    const messages = [
      ...system.map((x): ModelMessage => ({ role: "system", content: x })),
      ...input.messages,
    ]

    Magic-context uses the supported experimental.chat.system.transform hook to inject per-agent guidance, project docs, user profile, and pinned key files. Each push produces extra entries in system[], which OpenCode then rejoins down to exactly 2 messages. Qwen3.5's template accepts the first but raises on the second.

    So without magic-context, OpenCode sends 1 system message and Qwen is happy. With magic-context (or any plugin that modifies system prompt), OpenCode sends 2 and Qwen rejects.

    Quick confirmation

    You can verify this is the exact cause by temporarily disabling the magic-context plugin in opencode.json (remove the plugin entry or comment it out) and running the same historian call. If it succeeds with 1 system message and fails with 2, that confirms the chain.

    Workarounds (pick one)

    1. Drop --jinja from your llama-server command (easiest)

    Without --jinja, llama.cpp uses its built-in ChatML rendering, which is permissive about system message placement. You'll lose Qwen3.5-specific template features but the historian should work.

    2. Override the chat template

    Pass --chat-template chatml (or a custom permissive template) to llama-server. This replaces Qwen's strict template with one that accepts multiple system messages.

    3. Use a different local model for historian

    Any model whose template doesn't enforce strict single-system placement will work. Most GGUF models with ChatML-style templates are fine.

    4. Proxy your llama-server through something that merges system messages

    A thin proxy that joins consecutive system messages into one before forwarding to llama-server would work cleanly, but it's more setup than the other options.

    Longer-term fix

    The real fix belongs upstream in OpenCode: detect providers/templates that require a single system message and consolidate before sending. I'll note this for a potential OpenCode issue, but given that it affects the prompt-caching structure for Anthropic, it needs careful handling.

    I can also consider adding a config flag to magic-context to suppress the system-prompt injection entirely for users on strict-template local models — that would get you magic-context's core functionality (historian, dreamer, ctx tools) without the system prompt side. Let me know if that would be useful.

    For now I'd recommend workaround #1 (drop --jinja) as the quickest unblocker. Please confirm whether that gets you running.

  7. added a commit that references this issue on May 3, 2026
  8. 13 remaining items

  9. added a commit that references this issue on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions