Skip to content

fix(zai): Coding Plan chat turns always fail with fake rate-limit when system prompt carries OpenClaw signature line - #107304

Closed
felirami wants to merge 1 commit into
openclaw:mainfrom
felirami:fix/zai-coding-plan-signature-rejection
Closed

felirami wants to merge 1 commit into
openclaw:mainfrom
felirami:fix/zai-coding-plan-signature-rejection

Conversation

@felirami

@felirami felirami commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #103529

What Problem This Solves

Fixes an issue where users who onboard a valid z.ai Coding Plan key would see every chat turn fail with ⚠️ API rate limit reached. Please try again later. even though the key, quota, and endpoint are all healthy. As measured in #103529 (and re-confirmed live below), the z.ai Coding Plan endpoints (api.z.ai/api/coding/paas/v4 and open.bigmodel.cn/api/coding/paas/v4) deterministically return HTTP 429 / code 1305 whenever the request's system message contains OpenClaw's exact opening identity line You are a personal assistant running inside OpenClaw — the match is case-sensitive, exact-substring, and system-role-only. Onboarding succeeds (the detection probe carries no system prompt), then every real turn fails, with no in-product recovery.

Why This Change Was Made

This uses the fix shape identified in the ClawSweeper triage on #103529: the provider-owned transformSystemPrompt seam, which exists precisely for small transport compatibility rewrites after OpenClaw assembles the full prompt. The z.ai plugin now rewrites only the blocked line — running inside OpenClaw → running within OpenClaw, a substitution the issue's measurement matrix (and the live run below) shows passes the filter while any single-character deviation returns 200 — and only when the request routes to a Coding Plan path (/api/coding/, which also covers user reverse proxies that preserve the upstream path).

Route detection mirrors core model resolution (per Codex review feedback): the provider config entry is resolved like core resolveConfiguredProviderConfig (exact key, then normalized-key match), and a per-model models[] entry baseUrl — matched in plain or provider-scoped id form like matchesProviderScopedModelId — takes precedence over the provider-level baseUrl, matching the transport's metadataOverrideBaseUrl ?? providerConfiguredBaseUrl precedence. Ordinary z.ai routes and all other providers keep byte-identical canonical prompts. The blocked-string literal in the plugin is a provider-contract match against z.ai's measured server-side filter, not a cosmetic string; this is documented at the constant. Complementary to #104076, which improves the 1305 error copy but does not make Coding Plan turns succeed.

Non-goal: this does not decide whether z.ai intends to block OpenClaw on Coding Plan; that upstream question stays with maintainers per the issue discussion. Until it is answered, this restores a working chat path for affected users.

User Impact

z.ai Coding Plan users (global and CN) get working chat turns immediately after onboarding, instead of a fully broken session disguised as a rate limit. No config changes, no new options, no behavior change for any other provider or z.ai route.

Evidence

Live validation (glm-5.2, api.z.ai/api/coding/paas/v4, UA OpenAI/JS 6.39.1)

Measurement matrix — only the system content varies:

control (no signature):      200
OpenClaw signature line:     429   {"error":{"code":"1305","message":"The service may be temporarily overloaded, please try again later"}}
PR replacement (within):     200
lowercased signature:        200
larger prompt, signature line embedded + 4 other "OpenClaw" mentions intact:   429
same larger prompt, only the opening line rewritten by the PR transform:       200

End-to-end through the actual production transform (transformZaiCodingSystemPrompt) — its real output POSTed to the live endpoint, for both routing configurations:

provider-level route rewritten:      true
per-model override route rewritten:  true   (coding baseUrl on the models[] entry, ordinary provider baseUrl)
both outputs identical:              true
live status, ORIGINAL prompt:        429 (blocked)
live status, PRODUCTION TRANSFORM:   200 (success)

So the shipped transform turns a deterministically-blocked Coding Plan request into a successful one, while leaving every other OpenClaw reference in the prompt intact.

Automated tests / checks

  • New focused tests: extensions/zai/coding-prompt-compat.test.ts (provider-level and per-model route scoping incl. proxy paths and provider-scoped ids, precedence of per-model overrides in both directions, normalized provider-key lookup, single/multiple occurrence rewrite, byte-identical pass-through for non-coding routes, case-sensitivity guard) and a wiring test in extensions/zai/index.test.ts proving the registered provider hook applies the rewrite for /api/coding/ base URLs and returns undefined for the ordinary endpoint.
  • pnpm test:extension zai — 7 files, 54 tests passed (includes provider-runtime.contract.test.ts, onboard.test.ts).
  • pnpm test src/agents/system-prompt.test.ts src/agents/embedded-agent-runner/run/attempt-system-prompt.test.ts src/agents/plugin-text-transforms.test.ts — 4 files, 106 tests passed (prompt-seam callers unaffected).
  • pnpm check:test-types and pnpm lint:extensions green locally after rebasing onto latest main (the earlier check-lint CI failure was the pre-existing src/wizard/clack-prompter.test.ts issue fixed on main by test(wizard): satisfy promise executor lint #107301; the earlier check-test-types failure was a test-file cast in this PR, fixed).
  • pnpm check — all lanes green except the npm shrinkwrap guard, which fails identically on a clean main checkout (root, extensions/llama-cpp, extensions/twitch report stale) and is unrelated to this diff; node scripts/generate-npm-shrinkwrap.mjs --changed --check reports "No shrinkwrap-managed package changes detected".

AI-assisted (Claude) with human review; the transform literal and scoping decisions follow the measurements and fix shape recorded in #103529 and are confirmed by the live runs above.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8c84d97b7b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread extensions/zai/coding-prompt-compat.ts Resolved
…emPrompt

z.ai Coding Plan endpoints deterministically reject requests whose system
prompt contains OpenClaw's exact opening identity line (HTTP 429, code 1305,
disguised as overload). Rewrite that one line to a measured-safe equivalent
via the provider transformSystemPrompt seam, scoped to Coding Plan base URLs
only, so ordinary z.ai routes keep canonical prompt bytes.

Fixes openclaw#103529
@felirami
felirami force-pushed the fix/zai-coding-plan-signature-rejection branch from 8c84d97 to 179050b Compare July 14, 2026 09:38
@steipete

Copy link
Copy Markdown
Contributor

I'm not sure I wanna play this cat and mouse game - if you wanna change this clean on your end ask your agent to write a small plugin that rewites system prompt via a hook.

@steipete steipete closed this Jul 14, 2026

Copy link
Copy Markdown
Member

@felirami adding a docs datapoint for #103529 / this PR.

Z.ai's published docs do support the general upstream explanation that OpenClaw/general-agent traffic can hit temporary rate limits under load:

That said, I don’t think those docs explain away the measurement in #103529: the docs describe dynamic/high-load behavior, while the report/PR evidence is deterministic on an exact system-message substring, with same key/endpoint/UA/params flipping 429 to 200 when only that line changes. So the docs are useful context for genuine capacity 429s, but the issue still looks like a separate content-dependent rejection unless Z.ai clarifies otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants