[PR #5766] [MERGED] fix(llm): keep GLM 5.3 reasoning mandatory on every provider path #6923

Closed
opened 2026-10-23 04:14:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5766
Author: @Romuromylus
Created: 9/2/2026
Status: ✅ Merged
Merged: 9/2/2026
Merged by: @Romuromylus

Base: staging ← Head: fix/5765-glm-53-mandatory-reasoning


📝 Commits (8)

  • 117105e fix(llm): keep GLM 5.3 reasoning mandatory on every provider path (#5765)
  • 2b06ad4 style(llm): format the GLM 5.3 compat import per Prettier
  • d653755 test(regressions): drop an unrelated reformat from the provider-compat harness
  • b61af1b fix(llm): keep the explicit reasoning disable for GLM 5.3 on local inference hosts
  • 398b22c Merge branch 'staging' into fix/5765-glm-53-mandatory-reasoning
  • 0915d23 Merge branch 'staging' into fix/5765-glm-53-mandatory-reasoning
  • 62d8320 Merge remote-tracking branch 'pasta/staging' into fix/5765-glm-53-mandatory-reasoning
  • b75c71c fix(llm): forward a configured GLM 5.3 effort on remote custom gateways

📊 Changes

4 files changed (+233 additions, -16 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/services/llm/providers/glm-request-compat.ts (+66 -4)
📝 packages/server/src/services/llm/providers/openai.provider.ts (+17 -4)
📝 scripts/regressions/provider-compat.regression.ts (+149 -8)

📄 Description

Linked issue

Closes #5765

Why this change

Agent runs on a GLM 5.3 connection fail with Custom OpenAI-compatible endpoint error 400: This model always engages in thinking and cannot be disabled; please use low, high, or max (Z.AI) or NanoGPT API error 400: GLM 5.3 always thinks and does not support disabling reasoning. (NanoGPT), no matter which reasoning effort the user picks.

Root cause: JSON agents ask for reasoning off (jsonResponseReasoningOverride in packages/server/src/services/agents/agent-executor.ts sets reasoningEffort: "none" and forces the send-switch on, which is why the reporter's low/high attempts made no difference). #5582 taught the provider layer that GLM 5.3 Flash cannot honor that, but the guard (isGlm53FlashMandatoryReasoningModel) matched only the Flash name, so plain glm-5.3 / z-ai/glm-5.3 still received a disable:

  • native Z.AI endpoints got enable_thinking: false (applyGlmThinkingParameters),
  • NanoGPT got enable_thinking: false,
  • OpenRouter got reasoning: { effort: "none" } (supportsOpenRouterReasoningDisable allowed every z-ai/glm-* except Flash),
  • a generic custom connection on any other gateway got reasoning_effort: "none".

Z.AI documents that GLM-5.3 and GLM-5.3-Flash always reason, that thinking.type: "disabled" is no longer supported, and that only the low, high, and max effort levels are accepted (their migration note says to send enabled + reasoning_effort: "low" where an app used to disable). Chat generation only appeared to work because the chat path sends nothing for a GLM model on a custom connection unless the user explicitly turns reasoning off.

What changed

  • packages/server/src/services/llm/providers/glm-request-compat.ts
    • isGlm53MandatoryReasoningModel replaces the Flash-only guard and matches every GLM 5.3 variant (glm-5.3, glm-5.3-flash, provider prefixes and :free-style suffixes; glm-5.30, glm-5.2 and friends do not match).
    • New glm53ReasoningEffort maps Marinara's effort onto the three accepted levels: none/minimal/low → low, medium/high → high, xhigh/max → max, no effort → provider default.
    • applyGlmThinkingParameters now handles GLM 5.3 first: native Z.AI endpoints send the documented thinking: { type: "enabled" } plus the mapped reasoning_effort (instead of the legacy enable_thinking flag), NanoGPT sends enable_thinking: true plus the mapped effort. GLM 5.2 and older GLM models keep their existing bodies.
  • packages/server/src/services/llm/providers/openai.provider.ts
    • The OpenRouter and NanoGPT reasoning-disable gates use the wider guard, so z-ai/glm-5.3 keeps the provider's mandatory-reasoning default.
    • A generic custom connection sends reasoning_effort: "low" instead of "none" for GLM 5.3 on a remote non-native gateway (glm53CustomGatewayReasoningEffort); a local inference host (loopback / LAN / .local, per isLocalInferenceBaseUrl) keeps "none" plus the existing enable_thinking: false template kwarg, because self-hosted GLM 5.3 weights can really turn thinking off. Every other model still sends "none" everywhere.
  • scripts/regressions/provider-compat.regression.ts: pins for the model guard (incl. glm-5.30 negative), the effort map, native Z.AI off/default/medium bodies, NanoGPT and OpenRouter non-Flash GLM 5.3 requests through the real provider, the custom-gateway substitution pinned on a remote and a local base URL, and a non-GLM control that still sends "none".
  • CHANGELOG.md: Unreleased → Fixed entry.

Not in scope: the JSON-agent reasoning-off policy itself (it is still the right default for every model that can honor it), and the model catalog entries for GLM 5.3.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Provider contract, probed directly against NanoGPT with z-ai/glm-5.3 and z-ai/glm-5.3-flash: enable_thinking: false, reasoning_effort: "none", and thinking.type: "disabled" all return HTTP 400 reasoning_required; enable_thinking: true with reasoning_effort low/high/max returns 200 with content. Z.AI's GLM-5.3 docs and thinking-mode guide state the same contract for the native endpoint.
  • Live, on my production deploy (pre-fix image): pointed the World State agent at a NanoGPT connection on z-ai/glm-5.3, disabled the agent fallback connection, ran Retry Failed Agents on a roleplay chat → NanoGPT API error 400: GLM 5.3 always thinks and does not support disabling reasoning.
  • Live, same setup on the fix build: the same retry succeeds on the primary connection (no fallback event), World State returns a parsed game_state_update.
  • node ./scripts/run-regressions.mjs --filter scripts/regressions/provider-compat.regression.ts passes; tsc --noEmit on @marinara-engine/server is clean.
  • Not verified against a native Z.AI key (I do not have one); the native body follows Z.AI's published GLM-5.3 migration guidance verbatim, and the regression pins lock it.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

Not applicable (server request shaping only).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed agent and chat requests using GLM 5.3 that previously failed with a “thinking cannot be disabled” error.
    • GLM 5.3 now uses supported reasoning levels across native Z.AI, NanoGPT, OpenRouter, and custom gateways.
    • Requests with reasoning disabled now use the lightest supported reasoning level where required, while local inference servers retain existing behavior.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5766 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 9/2/2026 **Status:** ✅ Merged **Merged:** 9/2/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `staging` ← **Head:** `fix/5765-glm-53-mandatory-reasoning` --- ### 📝 Commits (8) - [`117105e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/117105ec2b4d2f18ff626052d2f3d29c97a9dd5c) fix(llm): keep GLM 5.3 reasoning mandatory on every provider path (#5765) - [`2b06ad4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2b06ad4af6c82f44707bd34dfef2213308d646ec) style(llm): format the GLM 5.3 compat import per Prettier - [`d653755`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d6537559e475c4cc4d4caf0f74486909abd9975c) test(regressions): drop an unrelated reformat from the provider-compat harness - [`b61af1b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b61af1be8d539c543245028295229aaac557ed36) fix(llm): keep the explicit reasoning disable for GLM 5.3 on local inference hosts - [`398b22c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/398b22c03a67b49cfeaa57094dacc82bc5fb31dd) Merge branch 'staging' into fix/5765-glm-53-mandatory-reasoning - [`0915d23`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0915d23bf19f7765e0533972ccea544324ca6d73) Merge branch 'staging' into fix/5765-glm-53-mandatory-reasoning - [`62d8320`](https://github.com/Pasta-Devs/Marinara-Engine/commit/62d8320ccca08f881ed34a8341eaedde0776fd9a) Merge remote-tracking branch 'pasta/staging' into fix/5765-glm-53-mandatory-reasoning - [`b75c71c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b75c71cb236bf7d6e62a815dee77e45467370c16) fix(llm): forward a configured GLM 5.3 effort on remote custom gateways ### 📊 Changes **4 files changed** (+233 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/services/llm/providers/glm-request-compat.ts` (+66 -4) 📝 `packages/server/src/services/llm/providers/openai.provider.ts` (+17 -4) 📝 `scripts/regressions/provider-compat.regression.ts` (+149 -8) </details> ### 📄 Description ## Linked issue Closes #5765 ## Why this change Agent runs on a GLM 5.3 connection fail with `Custom OpenAI-compatible endpoint error 400: This model always engages in thinking and cannot be disabled; please use low, high, or max` (Z.AI) or `NanoGPT API error 400: GLM 5.3 always thinks and does not support disabling reasoning.` (NanoGPT), no matter which reasoning effort the user picks. Root cause: JSON agents ask for reasoning off (`jsonResponseReasoningOverride` in `packages/server/src/services/agents/agent-executor.ts` sets `reasoningEffort: "none"` and forces the send-switch on, which is why the reporter's low/high attempts made no difference). #5582 taught the provider layer that GLM 5.3 **Flash** cannot honor that, but the guard (`isGlm53FlashMandatoryReasoningModel`) matched only the Flash name, so plain `glm-5.3` / `z-ai/glm-5.3` still received a disable: - native Z.AI endpoints got `enable_thinking: false` (`applyGlmThinkingParameters`), - NanoGPT got `enable_thinking: false`, - OpenRouter got `reasoning: { effort: "none" }` (`supportsOpenRouterReasoningDisable` allowed every `z-ai/glm-*` except Flash), - a generic custom connection on any other gateway got `reasoning_effort: "none"`. Z.AI documents that GLM-5.3 and GLM-5.3-Flash always reason, that `thinking.type: "disabled"` is no longer supported, and that only the `low`, `high`, and `max` effort levels are accepted (their migration note says to send `enabled` + `reasoning_effort: "low"` where an app used to disable). Chat generation only appeared to work because the chat path sends nothing for a GLM model on a custom connection unless the user explicitly turns reasoning off. ## What changed - `packages/server/src/services/llm/providers/glm-request-compat.ts` - `isGlm53MandatoryReasoningModel` replaces the Flash-only guard and matches every GLM 5.3 variant (`glm-5.3`, `glm-5.3-flash`, provider prefixes and `:free`-style suffixes; `glm-5.30`, `glm-5.2` and friends do not match). - New `glm53ReasoningEffort` maps Marinara's effort onto the three accepted levels: `none`/`minimal`/`low` → `low`, `medium`/`high` → `high`, `xhigh`/`max` → `max`, no effort → provider default. - `applyGlmThinkingParameters` now handles GLM 5.3 first: native Z.AI endpoints send the documented `thinking: { type: "enabled" }` plus the mapped `reasoning_effort` (instead of the legacy `enable_thinking` flag), NanoGPT sends `enable_thinking: true` plus the mapped effort. GLM 5.2 and older GLM models keep their existing bodies. - `packages/server/src/services/llm/providers/openai.provider.ts` - The OpenRouter and NanoGPT reasoning-disable gates use the wider guard, so `z-ai/glm-5.3` keeps the provider's mandatory-reasoning default. - A generic custom connection sends `reasoning_effort: "low"` instead of `"none"` for GLM 5.3 on a **remote** non-native gateway (`glm53CustomGatewayReasoningEffort`); a local inference host (loopback / LAN / `.local`, per `isLocalInferenceBaseUrl`) keeps `"none"` plus the existing `enable_thinking: false` template kwarg, because self-hosted GLM 5.3 weights can really turn thinking off. Every other model still sends `"none"` everywhere. - `scripts/regressions/provider-compat.regression.ts`: pins for the model guard (incl. `glm-5.30` negative), the effort map, native Z.AI off/default/medium bodies, NanoGPT and OpenRouter non-Flash GLM 5.3 requests through the real provider, the custom-gateway substitution pinned on a remote and a local base URL, and a non-GLM control that still sends `"none"`. - `CHANGELOG.md`: Unreleased → Fixed entry. Not in scope: the JSON-agent reasoning-off policy itself (it is still the right default for every model that can honor it), and the model catalog entries for GLM 5.3. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Provider contract, probed directly against NanoGPT with `z-ai/glm-5.3` and `z-ai/glm-5.3-flash`: `enable_thinking: false`, `reasoning_effort: "none"`, and `thinking.type: "disabled"` all return HTTP 400 `reasoning_required`; `enable_thinking: true` with `reasoning_effort` `low`/`high`/`max` returns 200 with content. Z.AI's GLM-5.3 docs and thinking-mode guide state the same contract for the native endpoint. - Live, on my production deploy (pre-fix image): pointed the World State agent at a NanoGPT connection on `z-ai/glm-5.3`, disabled the agent fallback connection, ran Retry Failed Agents on a roleplay chat → `NanoGPT API error 400: GLM 5.3 always thinks and does not support disabling reasoning.` - Live, same setup on the fix build: the same retry succeeds on the primary connection (no fallback event), World State returns a parsed `game_state_update`. - `node ./scripts/run-regressions.mjs --filter scripts/regressions/provider-compat.regression.ts` passes; `tsc --noEmit` on `@marinara-engine/server` is clean. - Not verified against a native Z.AI key (I do not have one); the native body follows Z.AI's published GLM-5.3 migration guidance verbatim, and the regression pins lock it. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) Not applicable (server request shaping only). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Fixed agent and chat requests using GLM 5.3 that previously failed with a “thinking cannot be disabled” error. - GLM 5.3 now uses supported reasoning levels across native Z.AI, NanoGPT, OpenRouter, and custom gateways. - Requests with reasoning disabled now use the lightest supported reasoning level where required, while local inference servers retain existing behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:14:55 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6923
No description provided.