[codex] fix(zai): sanitize GLM system prompt at runtime - #59975
[codex] fix(zai): sanitize GLM system prompt at runtime#59975RyderFreeman4Logos wants to merge 1 commit into
Conversation
teknium1
left a comment
There was a problem hiding this comment.
Thanks for isolating the outbound-prompt approach and for preserving the cached message objects.
Problems
agent/zai_prompt_policy.py:28rewrites bareHermescase-insensitively. Current prompts contain operational~/.hermes/...profile paths atagent/system_prompt.py:397-409; this rule changes those paths for Z.AI users.agent/zai_prompt_policy.py:40enables the policy for everyglm-*model. Current main explicitly treats arbitrary local/private GLM endpoints differently from direct provider identity (run_agent.py:1527-1547), so model-name-only gating is too broad.- Current chat-completions conversion is centralized at
agent/transports/chat_completions.py:331-338; move normal-request policy there and retain explicit coverage for the direct summary call atagent/chat_completion_helpers.py:1761-1764.
Suggested changes
- Preserve bare CLI/path/environment identifiers and test
~/.hermes/...content. - Gate on explicit provider identity or parsed direct Z.AI hostnames, with a localhost GLM regression test.
Automated hermes-sweeper review.
| (r"hermes-agent", "local-agent"), | ||
| (r"\bHermes\b", "the local assistant"), | ||
| (r"Nous Research", "the platform provider"), | ||
| (r"\bHERMES_[A-Z0-9_]+\b", "LOCAL_AGENT_ENV"), |
There was a problem hiding this comment.
Please keep this replacement set narrow. With re.IGNORECASE, this rule rewrites the hermes segment of current system-prompt paths such as ~/.hermes/profiles/... (agent/system_prompt.py:397-409), making profile-isolation instructions point to a nonexistent path. Preserve bare operational identifiers and add a regression test for them.
| return ( | ||
| provider in {"zai", "z-ai", "z.ai", "glm", "zhipu"} | ||
| or model.startswith("glm-") | ||
| or "api.z.ai" in base_url |
There was a problem hiding this comment.
A glm-* model name does not establish a direct Z.AI endpoint. Current main deliberately distinguishes Ollama-hosted GLM from arbitrary local/private endpoints (run_agent.py:1527-1547). Restrict this to explicit Z.AI/Zhipu provider identity or parsed direct Z.AI hostnames, and cover a custom localhost GLM case.
Summary
Root Cause
Z.AI GLM-5.x can reject the normal Hermes-branded system prompt at the provider boundary, returning overloaded/rate-limit style failures even for tiny non-streaming requests. Direct testing showed the request succeeds when the triggering Hermes Agent branding phrase is removed, so this patch rewrites only the API-boundary copy sent to Z.AI/GLM endpoints.
This preserves per-conversation prompt caching because the cached system prompt and conversation history are not modified.
This is intentionally scoped to the prompt sanitizer path. It does not duplicate the retry/backoff work from #59523.
Validation
/usr/local/share/uv/tools/bin/pytest tests/agent/test_zai_prompt_policy.py/home/obj/.hermes/hermes-agent/venv/bin/python -m py_compile agent/zai_prompt_policy.py agent/chat_completion_helpers.py agent/conversation_loop.py tests/agent/test_zai_prompt_policy.py