fix(credential_pool,commands): recover Z.AI exhausted entries and register /costs command - #21404
Closed
DanielLSM wants to merge 2 commits into
Closed
fix(credential_pool,commands): recover Z.AI exhausted entries and register /costs command#21404DanielLSM wants to merge 2 commits into
DanielLSM wants to merge 2 commits into
Conversation
added 2 commits
May 6, 2026 22:42
…ntries Z.AI has two API surfaces (regular /api/paas/v4 and coding /api/coding/paas/v4). An account may only have quota on one. When a zai pool entry is marked exhausted after a 429, the fallback path uses the provider registry's default base_url — which is the regular endpoint — causing permanent failure even when the coding endpoint still works. This change adds two mechanisms: 1. _sync_zai_entry_from_auth_store(): when a zai entry is exhausted, check provider_state.zai.detected_endpoint in auth.json. If runtime resolution detected a different working endpoint, adopt it and clear exhaustion immediately. 2. Re-probe on cooldown expiry: when clear_expired resets an exhausted zai entry after its cooldown, call detect_zai_endpoint() to verify the cached base_url is still valid. If the endpoint changed, update it. If no endpoint works, keep the entry exhausted. Mirrors the existing sync patterns for anthropic, nous, and openai-codex. Fixes: credential pool exhaustion causing wrong zai endpoint fallback
Contributor
Author
|
Closing in favor of #21413 which generalizes this fix and references related issues more comprehensively. |
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.
Summary
This PR fixes two independent but related issues:
Z.AI credential pool exhaustion recovery: When a Z.AI pool entry is marked
exhaustedafter a 429, the fallback path uses the provider registry's defaultbase_url(the regular endpoint). For accounts with quota only on the coding-plan endpoint, this causes permanent failure even though the coding endpoint still works.Missing
/costscommand registration: Theusagecommand was registered but notcostsorcredits, causing Telegram/gateway to not recognize/costsas a slash command.Changes
agent/credential_pool.py_sync_zai_entry_from_auth_store(): when a Z.AI entry is exhausted, checkprovider_state.zai.detected_endpointinauth.json. If runtime resolution detected a different working endpoint, adopt it and clear exhaustion immediately.clear_expiredresets an exhausted Z.AI entry after its cooldown, calldetect_zai_endpoint()to verify the cachedbase_urlis still valid. If the endpoint changed, update it. If no endpoint works, keep the entry exhausted (preserving the original error context).anthropic,nous, andopenai-codex.hermes_cli/commands.pycostsas the canonical command withusageandcreditsas aliases.should_bypass_active_sessioncomment to referencecosts.cli.py,gateway/run.pycanonical == "costs"instead of"usage".Tests
tests/agent/test_credential_pool.py: add 3 regression tests for Z.AI endpoint recovery, re-probe on expiry, and failed re-probe keeping entry unavailable.tests/hermes_cli/test_commands.py: add regression tests forcostscanonical resolution, gateway known commands, and Telegram menu exposure.Test Plan
All tests pass locally.
Related
/costsslash command not being recognized by Telegram/gateway.