fix(zai): restore request-local prompt policy - #63622
aider4ryder wants to merge 1 commit into
Conversation
Fresh current-main replacement for the closed #52976 (request assembly moved into |
89dcd2b to
21cedc1
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thank you for moving the compatibility policy to the current request-assembly layer and preserving the cached prompt.
Problems
agent/zai_prompt_policy.py:60prefixes each multipart text block independently. Sincesanitize_zai_system_prompt()prepends_ZAI_SYSTEM_PREFIXfor every nonempty block (agent/zai_prompt_policy.py:45-49), two text blocks produce two identity prefixes. The added multipart test exercises only one block.- The policy is not transport-consistent for Zhipu's supported Anthropic route:
tests/run_agent/test_anthropic_third_party_oauth_guard.py:103-112configuresglmathttps://open.bigmodel.cn/api/anthropic, while the iteration summary dispatchesanthropic_messagesviaagent/chat_completion_helpers.py:1906-1914. The ordinary route remains unsanitized, but the new summary hook changes that summary request.
Suggested changes
- Sanitize multipart branding per part but add the neutral prefix once per system message, with a multi-text-part regression test.
- Either cover the Anthropic transport too or constrain this policy explicitly to Chat Completions, including the summary path.
Automated hermes-sweeper review.
| if not isinstance(part, dict): | ||
| continue | ||
| if isinstance(part.get("text"), str): | ||
| part["text"] = sanitize_zai_system_prompt(part["text"]) |
There was a problem hiding this comment.
sanitize_zai_system_prompt() prepends _ZAI_SYSTEM_PREFIX to every nonempty string, so a multipart system message with multiple text blocks gets the prefix repeated once per block. Preserve per-part replacement, but insert the neutral prefix once at message scope and add a two-text-part regression test.
21cedc1 to
3b0d8f8
Compare
Summary
Restore a request-local prompt compatibility policy for direct Z.AI endpoints on current
main.This is a fresh, current-main replacement for the closed #52976 carried patch. The request assembly code has since moved into
ChatCompletionsTransport, so the old commit no longer applies cleanly.Motivation
Direct Z.AI Coding Plan requests have intermittently returned HTTP 429 with provider code
1305when the full Hermes/Nous identity prompt is sent. The failure is not reliably deterministic—an exact failed payload can succeed later—so this change is deliberately narrow and fail-safe rather than treating every GLM model as affected.What changed
api.z.ai/open.bigmodel.cnhostnames;glm-*model name alone, preserving locally hosted GLM deployments;Hermes Agent/Nous Researchbranding phrases;hermes tools,~/.hermes/,.hermes.md,HERMES_HOME, andActive Hermes profile;Verification
Live checks against the configured
custom:z2Z.AI endpoint:A request-local replay of the previously failed 29k-token payload verified that the original messages remained unchanged, the outbound identity block was neutralized, and Z.AI returned HTTP 200 (
finish_reason=tool_calls). No credentials or request content are included here.Safety / scope
api.z.aiandopen.bigmodel.cnavoids substring-host spoofing.Supersedes #52976.