Conversation
Author
|
Contributor
Fix PR for #50663 (z.ai peak-hour 429s). Note the root cause is most likely upstream Z.ai throttling keyed on client signature, so this spoofs an OpenCode identity rather than fixing a Hermes-side defect. Related to #47685 (phrase-triggered 429 when the system prompt contains "Hermes Agent"). |
Author
|
The proper fix is to spoof Zcode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes Z.ai/Zhipu peak-hour 429s by applying an OpenCode-shaped client identity only for Z.ai endpoints.
For
api.z.aiandopen.bigmodel.cn, includinghttps://api.z.ai/api/coding/paas/v4andhttps://open.bigmodel.cn/api/coding/paas/v4, Hermes now sendsUser-Agent: opencode/1.17.9and strips SDKX-Stainless-*fingerprint headers from final outbound requests.This is scoped to Z.ai/Zhipu hosts and covers the main OpenAI-compatible client path, auxiliary OpenAI/AsyncOpenAI clients, and Z.ai Anthropic-compatible clients. User
model.default_headersstill wins as the manual override. The implementation intentionally does not send Hermes session ids or parent session ids as third-party headers.Related Issue
Fixes #50663
Type of Change
Changes Made
agent/provider_client_identity.pyfor Z.ai host detection, OpenCode UA defaults, case-safe header merging, and finalX-Stainless-*stripping hooks.agent/agent_init.pyandrun_agent.pyso main OpenAI-compatible Z.ai clients receive the Z.ai identity behavior.agent/auxiliary_client.pyso auxiliary OpenAI and AsyncOpenAI clients use the same Z.ai identity behavior.agent/anthropic_adapter.pyso Z.ai Anthropic-compatible clients preserve Anthropic beta headers while stripping SDK fingerprint headers.gateway/run.py,tui_gateway/server.py, andacp_adapter/server.pyto keep local session context propagation correct.tests/agent/test_zai_opencode_identity.py.User-Agentoverrides and session context propagation.How to Test
uv run --extra dev python -m pytest -p no:enabler tests/agent/test_zai_opencode_identity.py tests/agent/test_auxiliary_client.py tests/agent/test_auxiliary_named_custom_providers.py tests/agent/test_auxiliary_user_default_headers.py tests/agent/test_anthropic_adapter.py tests/run_agent/test_provider_attribution_headers.py tests/run_agent/test_create_openai_client_proxy_env.py tests/run_agent/test_session_id_env.py tests/gateway/test_session_env.py tests/test_tui_gateway_server.py --tb=shortUser-Agent: opencode/1.17.9andX-Stainless-*headers are stripped.model.default_headerscan override the Z.ai UA.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) - or N/Acli-config.yaml.exampleif I added/changed config keys - or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows - or N/AScreenshots / Logs
Targeted test suite passed:
764 passed in 38.08sAdditional checks passed:
python -m py_compile ...git diff --check