Skip to content

[Bug] /new session creation fails with ZAI/GLM: provider rejects system-only messages (400) #73688

Description

@AhmedFayala

Bug Description

/new slash command and fresh session creation fails with ZAI (GLM) provider when the default model is any GLM variant (glm-5.1, glm-5-turbo, etc.). The error surfaces as:

⚠️ Something went wrong while processing your request. Please try again, or use /new to start a fresh session.

The gateway logs show:

embedded run agent end: LLM request failed: provider rejected the request schema or tool payload.
rawError: 400 The messages parameter is illegal. Please check the documentation.
providerRuntimeFailureKind: schema
failoverReason: format

Root Cause

The ZAI/GLM API (https://api.z.ai/api/coding/paas/v4/chat/completions) rejects requests where the messages array contains only a system message without a trailing user message (HTTP 400, error code 1214). The same rejection occurs for assistant messages with empty content.

When /new creates a fresh session, OpenClaw constructs the initial LLM request with the full system prompt (workspace context files, agent config, skills, etc.) but apparently does not include a valid user message in the messages array — or includes an empty one. The ZAI API rejects this payload before the model can respond.

Direct API Reproduction

All three scenarios return 400 {"error":{"code":"1214","message":"The messages parameter is illegal. Please check the documentation."}}:

1. System-only messages (the /new scenario):

{
  "model": "glm-5.1",
  "messages": [{"role": "system", "content": "You are a helpful assistant."}],
  "max_tokens": 10,
  "thinking": {"type": "disabled"}
}

2. Empty assistant content:

{
  "model": "glm-5.1",
  "messages": [
    {"role": "system", "content": "You are helpful."},
    {"role": "assistant", "content": ""}
  ],
  "max_tokens": 10,
  "thinking": {"type": "disabled"}
}

3. Null/missing user content also rejected (code 1210/1213).

Control (works correctly):

{
  "model": "glm-5.1",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "hi"}
  ],
  "max_tokens": 10,
  "thinking": {"type": "disabled"}
}

→ Returns 200 with valid response.

Affected Models

Tested and confirmed on both glm-5.1 and glm-5-turbo. Likely affects all GLM models on the ZAI Coding Plan endpoint (/api/coding/paas/v4).

Environment

Component Value
OpenClaw 2026.4.26 (be8c246)
Node.js v22.22.2
OS Ubuntu 24.04 LTS (kernel 6.8.0-110-generic, x64)
Provider ZAI (zai)
Endpoint https://api.z.ai/api/coding/paas/v4 (Coding Plan Global)
API type openai-completions
Default model zai/glm-5.1
Channel Telegram (DM)

Gateway Log Evidence

2026-04-28T18:06:05.043+02:00 [diagnostic] stuck session: sessionId=unknown sessionKey=agent:main:telegram:slash:5868868997 state=processing age=168s queueDepth=1

2026-04-28T18:06:07.152+02:00 [agent/embedded] embedded run agent end: runId=38f7cd2a-77c5-4f4a-9c76-3c0b0e62bba5 isError=true model=glm-5.1 provider=zai error=LLM request failed: provider rejected the request schema or tool payload. rawError=400 The messages parameter is illegal. Please check the documentation.

2026-04-28T18:06:07.177+02:00 [agent/embedded] embedded run failover decision: runId=38f7cd2a-77c5-4f4a-9c76-3c0b0e62bba5 stage=assistant decision=surface_error reason=format from=zai/glm-5.1 profile=sha256:118886372c36 rawError=400 The messages parameter is illegal. Please check the documentation.

The error is persistent — every /new attempt fails with the same error. The session gets stuck for ~170s before surfacing the error to the user.

Workaround

Setting a per-session model override to a non-ZAI provider (e.g., via /model) avoids the issue for existing sessions, but /new still fails because it creates a new session with the default model (zai/glm-5.1).

Suggested Fix

OpenClaw should ensure that the messages array sent to the LLM API always contains at least one non-empty user message after the system message(s). This could be:

  1. Append a placeholder user message (e.g., the /new command text itself or a minimal initialization prompt) when constructing the initial request for a fresh session.
  2. Validate the messages array before sending to providers known to reject system-only payloads, and inject a synthetic user turn if needed.
  3. Provider-level message sanitization in the ZAI/OpenAI-completions adapter to strip or pad messages that would trigger this rejection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions