Skip to content

fix: redact brand string for z.ai provider to avoid content-filter 429 (#60118) - #60140

Open
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/zai-brand-string-filter
Open

fix: redact brand string for z.ai provider to avoid content-filter 429 (#60118)#60140
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/zai-brand-string-filter

Conversation

@AlexFucuson9

Copy link
Copy Markdown
Contributor

Summary

z.ai (GLM Coding Plan) silently rejects system prompts containing the literal string "Hermes Agent", returning HTTP 429 with code 1305 (mislabeled content-filter rejection). Every Hermes request injects this brand string, so every request fails with a fake "rate limit" error.

Root Cause

z.ai's content filter trips on "Hermes Agent" in the system prompt. The 429/1305 response is mislabeled — it's not a rate limit, it's a content filter. The account has quota, the key works, and removing the brand string makes requests succeed.

Changes

  • Add _is_zai provider detection flag in build_api_kwargs()
  • When z.ai is detected, sanitize system messages to replace:
    • "Hermes Agent" → "the assistant"
    • "Hermes agent" → "the assistant"
    • "Nous Research" → "the development team"
  • Only system messages are affected; user/assistant messages are untouched

Precedent

The Anthropic adapter already does the same thing (line 2545): it replaces "Hermes Agent" → "Claude Code" for Anthropic's content filters. This is the same pattern applied to z.ai.

Test Plan

  • Syntax check passes
  • Requests to z.ai with the brand string no longer return 429/1305
  • Requests to other providers are unaffected (sanitization is z.ai-only)
  • System prompt functionality is preserved (agent identity is generic but functional)

Fixes #60118

…ch#60118)

z.ai (GLM Coding Plan) silently rejects system prompts containing the
literal string "Hermes Agent", returning HTTP 429 with code 1305
(mislabeled content-filter rejection). Because every Hermes request
injects this brand string into the system prompt, every request to
z.ai fails — and the 429 is treated as a transient throttle, so it
retries 3x before surfacing as "rate limiting".

Add brand-string redaction in build_api_kwargs() for the z.ai provider
path, replacing "Hermes Agent" → "the assistant" and "Nous Research"
→ "the development team" in system messages only. This follows the
same pattern used by the Anthropic adapter (line 2545) which replaces
"Hermes Agent" → "Claude Code" for Anthropic's content filters.

Fixes NousResearch#60118
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/zai ZAI provider P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jul 7, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #59975 (earliest open, same site agent/chat_completion_helpers.py, same mechanism: redacting the Hermes Agent/Nous Research brand strings from z.ai system messages at the chat/completions API boundary). #59975 is the more comprehensive version (dedicated agent/zai_prompt_policy.py module, preserves prompt caching). Related: #53006 (same fix at the build_system_prompt() chokepoint — different site), #56823 (different trigger substring — plain-text skill_view() syntax), and issues #60118 / #53002 (the z.ai 1305 false-overload family). Human to consolidate the z.ai sanitizer cluster.

@teknium1 teknium1 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.

Thanks for isolating the Z.AI prompt trigger. The reported source condition is still present on current main, but this implementation does not reach the normal direct Z.AI path.

Problems

  • The new if _is_zai block is below the legacy no-profile branch in the PR diff. zai is a registered ZaiProfile (plugins/model-providers/zai/__init__.py:111-127), and build_api_kwargs() returns from the provider-profile path before the added block (agent/chat_completion_helpers.py:998-1028).
  • Non-Codex iteration-limit summaries bypass _build_api_kwargs() and send api_messages directly (agent/chat_completion_helpers.py:1836-1847), leaving that request path uncovered.
  • The PR has no regression tests for the registered Z.AI path or input/cache preservation.

Suggested changes

  • Sanitize a per-request message copy before provider-profile dispatch, and add the same handling to the direct summary request path.
  • Add focused tests for registered zai, system-only replacement, unchanged source messages, and non-Z.AI passthrough.

Automated hermes-sweeper review.

# z.ai (GLM Coding Plan) silently rejects system prompts containing
# "Hermes Agent" — returns HTTP 429 code 1305 (mislabeled content
# filter). Redact brand strings in system messages so the provider
# doesn't trip its filter. See issue #60118.

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.

This block is in the legacy no-profile branch. Direct zai resolves to the registered ZaiProfile, whose earlier return bypasses this code entirely; move a copy-only sanitizer before provider-profile dispatch or to the outbound request-construction boundary.

@teknium1 teknium1 added sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users labels Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists provider/zai ZAI provider sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: z.ai (GLM Coding Plan) rejects system prompts containing "Hermes Agent" — surfaces as a fake HTTP 429 / code 1305

3 participants