Skip to content

fix(credential_pool,commands): recover Z.AI exhausted entries and register /costs command - #21404

Closed
DanielLSM wants to merge 2 commits into
NousResearch:mainfrom
DanielLSM:fix-zai-credential-pool-endpoint-sync
Closed

fix(credential_pool,commands): recover Z.AI exhausted entries and register /costs command#21404
DanielLSM wants to merge 2 commits into
NousResearch:mainfrom
DanielLSM:fix-zai-credential-pool-endpoint-sync

Conversation

@DanielLSM

Copy link
Copy Markdown
Contributor

Summary

This PR fixes two independent but related issues:

  1. Z.AI credential pool exhaustion recovery: When a Z.AI pool entry is marked exhausted after a 429, the fallback path uses the provider registry's default base_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.

  2. Missing /costs command registration: The usage command was registered but not costs or credits, causing Telegram/gateway to not recognize /costs as a slash command.

Changes

agent/credential_pool.py

  • Add _sync_zai_entry_from_auth_store(): when a Z.AI 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.
  • Re-probe on cooldown expiry: when clear_expired resets an exhausted Z.AI 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 (preserving the original error context).
  • Mirrors the existing sync patterns for anthropic, nous, and openai-codex.

hermes_cli/commands.py

  • Register costs as the canonical command with usage and credits as aliases.
  • Update should_bypass_active_session comment to reference costs.

cli.py, gateway/run.py

  • Update dispatch handlers to check canonical == "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 for costs canonical resolution, gateway known commands, and Telegram menu exposure.

Test Plan

python -m pytest tests/agent/test_credential_pool.py -q
python -m pytest tests/hermes_cli/test_commands.py -q

All tests pass locally.

Related

  • Fixes credential pool exhaustion causing wrong Z.AI endpoint fallback.
  • Fixes /costs slash command not being recognized by Telegram/gateway.

Daniel 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
@DanielLSM

Copy link
Copy Markdown
Contributor Author

Closing in favor of #21413 which generalizes this fix and references related issues more comprehensively.

@DanielLSM DanielLSM closed this May 7, 2026
@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 comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery provider/zai ZAI provider P2 Medium — degraded but workaround exists labels May 7, 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 comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists provider/zai ZAI provider type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants