zai-org / zai-org/feedback

[Bug] 自定义 OpenAI-compatible 模型将 context window 误用为 max_tokens,导致 Ollama GLM-5.2 400

Open
#96 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: P2
Dominant language
No language data
Stars
22
Forks
1
PR merge metrics
No merged PRs in 30d

Description

提交前确认 · Pre-submission checklist
  • 我已搜索过现有 issue,确认这不是重复 / I searched existing issues and confirmed this isn't a duplicate.
  • 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.
问题类别 · Category

模型设置 / 切换 · Model config

涉及的 Agent 框架 · Agent framework

ZCode Agent(自研)

严重程度 · Severity

阻塞使用 · Blocking

复现频率 · Reproducibility

必现 · Always

问题描述 · Description

在 ZCode Desktop 的 Model settings 中添加自定义 OpenAI chat completions (/v1/chat/completions) provider,接入本地 Ollama OpenAI-compatible endpoint 的 glm-5.2:cloud 时,如果按模型真实能力把 Context window 配成 2000001000000,ZCode 会向 provider 发出过大的 max_tokens,导致请求被 Ollama 拒绝:

Provider rejected the model request.
Turn execution failed
Bad Request
provider=a9fb69dd-4c38-46b0-a9b4-74f10a9f3969 model=glm-5.2:cloud request=072b98c6-8e78-4d99-a6e4-d9fd03716c3f reason=invalid_request status=400 retryable=false

这看起来是模型设置里的 Context window 被用于输出上限 max_tokens 了。GLM-5.2 的上下文窗口约 976K/1M,但单次最大输出是 131072;二者不应共用同一个字段。

相关但不重复:#94 请求支持自定义 Payload。本 issue 更具体,指向现有模型设置字段到请求参数的映射 bug。

复现步骤 · Steps to reproduce
  1. 打开 ZCode Desktop → Settings → Model settings。
  2. Add provider:
    • Name: Ollama GLM
    • Base URL: http://localhost:11434/v1
    • API key: ollama
    • API format: OpenAI chat completions (/v1/chat/completions)
  3. Add model:
    • Model ID: glm-5.2:cloud
    • Context window: 2000001000000
  4. 在 ZCode Agent 中选择该 custom provider/model,发送任意 prompt。
  5. 看到 provider 400 / invalid_request
期望表现 · Expected behavior

ZCode 应该区分:

{
  "limit": {
    "context": 1000000,
    "output": 120000
  }
}

或在 UI 中分别提供:

  • Context window / input context limit:例如 1000000
  • Max output tokens:例如 64000120000,且不超过 provider/model 输出上限 131072

请求 /v1/chat/completions 时,max_tokens 应来自 output limit,而不是 context window。

如果使用 /v1/responses,也应使用 max_output_tokens 表示输出上限;context window 仍不应直接映射到 max_output_tokens

实际表现 · Actual behavior

当 model 的 Context window 设置为 200000 时,底层 OpenAI-compatible endpoint 返回:

max_tokens (200000) exceeds model's maximum output tokens (131072) for model glm-5.2

当设置为 1000000 时同理:

max_tokens (1000000) exceeds model's maximum output tokens (131072) for model glm-5.2

本地将 ZCode 配置手动改为同时包含 contextoutput 后可绕过:

"glm-5.2:cloud": {
  "limit": {
    "context": 1000000,
    "output": 120000
  },
  "modalities": {
    "input": ["text"],
    "output": ["text"]
  }
}
ZCode 版本 · ZCode version
  • ZCode Desktop: log shows current app initialized as 3.1.3; updater downloaded 3.2.5 during the same run.
  • bundled ZCode CLI: 0.15.0
设备 / 系统 / 浏览器 · Device / OS / Browser
  • macOS 26.3, Apple Silicon
  • ZCode Desktop App
  • Ollama OpenAI-compatible endpoint at http://localhost:11434/v1
截图 / 录屏 / 日志 · Screenshots / Recordings / Logs

ZCode log excerpt:

{
  "event": "model.request.failed",
  "baseURL": "http://localhost:11434/v1",
  "modelId": "glm-5.2:cloud",
  "providerId": "a9fb69dd-4c38-46b0-a9b4-74f10a9f3969",
  "providerKind": "openai-compatible",
  "requestId": "072b98c6-8e78-4d99-a6e4-d9fd03716c3f",
  "reason": "invalid_request",
  "statusCode": 400,
  "statusMessage": "Provider rejected the model request."
}

Local minimal reproduction against Ollama OpenAI-compatible endpoint:

POST http://localhost:11434/v1/chat/completions
model=glm-5.2:cloud
max_tokens=200000 -> 400
max_tokens=131072 -> 200
max_tokens=120000 -> 200

/v1/responses also works, but has the same output-token cap:

POST http://localhost:11434/v1/responses
model=glm-5.2:cloud
max_output_tokens=200000 -> 400
max_output_tokens=131072 -> 200
max_output_tokens=120000 -> 200

References:

Suggested fix:

  1. Add a separate output-token field in custom model settings, or infer a safe output cap from model metadata.
  2. Store both limit.context and limit.output for custom provider models.
  3. For OpenAI-compatible chat completions, map only limit.output to max_tokens.
  4. For OpenAI Responses API, map only limit.output to max_output_tokens.
  5. Keep limit.context for model/context budgeting and UI display, not as a request output limit.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the ZCode Desktop Model settings and the OpenAI-compatible /v1/chat/completions and /v1/responses request paths described in the report. Trace how custom model limits are stored and mapped; done means context and output limits remain distinct and requests use only the output limit for max_tokens or max_output_tokens, with the reported Ollama reproduction passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
ollama
Domain
api, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.