Skip to content

fix(credential_pool): sync provider endpoints from auth state - #21413

Closed
DanielLSM wants to merge 1 commit into
NousResearch:mainfrom
DanielLSM:fix/provider-endpoint-sync-and-commands
Closed

fix(credential_pool): sync provider endpoints from auth state#21413
DanielLSM wants to merge 1 commit into
NousResearch:mainfrom
DanielLSM:fix/provider-endpoint-sync-and-commands

Conversation

@DanielLSM

@DanielLSM DanielLSM commented May 7, 2026

Copy link
Copy Markdown
Contributor

Problem

When a provider has multiple API surfaces (e.g. Z.AI regular vs coding-plan endpoints), the pool entry's base_url can become stale after runtime endpoint detection finds a different working URL. The entry stays exhausted on the wrong endpoint indefinitely, even though auth.json contains the correct detected endpoint.

Changes

agent/credential_pool.py

  • Add _sync_endpoint_from_provider_state(): generalized method that checks provider_state.<provider>.detected_endpoint in auth.json and adopts a newer endpoint when the cached base_url differs from the pool entry. Clears exhaustion immediately so the entry can be retried.
  • Re-probe on cooldown expiry: after clear_expired resets an exhausted entry, call the provider's endpoint detection to verify the cached base_url is still valid. If the endpoint changed, update it. If no endpoint works, keep the entry exhausted and preserve the original error context.
  • The sync pattern is provider-agnostic (currently enabled for zai; extensible to any provider that caches detected_endpoint in provider_state).

Related Issues

Test Plan

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

All tests pass.

@DanielLSM
DanielLSM force-pushed the fix/provider-endpoint-sync-and-commands branch 2 times, most recently from df5af44 to fbd7628 Compare May 7, 2026 16:34
## Problem

When a provider has multiple API surfaces (e.g. Z.AI regular vs coding-plan
endpoints), the pool entry's base_url can become stale after runtime endpoint
detection finds a different working URL. The entry stays exhausted on the wrong
endpoint indefinitely, even though auth.json contains the correct detected endpoint.

## Changes

### agent/credential_pool.py
- Add _sync_endpoint_from_provider_state(): generalized method that checks
  provider_state.<provider>.detected_endpoint in auth.json and adopts a newer
  endpoint when the cached base_url differs from the pool entry. Clears
  exhaustion immediately so the entry can be retried.
- Re-probe on cooldown expiry: after clear_expired resets an exhausted entry,
  call the provider's endpoint detection to verify the cached base_url is still
  valid. If the endpoint changed, update it. If no endpoint works, keep the
  entry exhausted and preserve the original error context.
- The sync pattern is provider-agnostic (currently enabled for zai; extensible
  to any provider that caches detected_endpoint in provider_state).

## Related Issues

- Fixes credential pool exhaustion causing wrong endpoint fallback (pattern
  similar to NousResearch#5668 transient-auth cooldown issues and NousResearch#19083 custom-provider
  key mix-ups).

## Test Plan

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

All tests pass.
@DanielLSM
DanielLSM force-pushed the fix/provider-endpoint-sync-and-commands branch from fbd7628 to cfa6b9e Compare May 7, 2026 16:34
@DanielLSM DanielLSM changed the title fix(credential_pool,commands): sync provider endpoints from auth state and register /costs command fix(credential_pool): sync provider endpoints from auth state May 7, 2026
@DanielLSM

Copy link
Copy Markdown
Contributor Author

Closing to reopen with clean commit history.

@DanielLSM DanielLSM closed this May 7, 2026
@DanielLSM
DanielLSM deleted the fix/provider-endpoint-sync-and-commands branch May 7, 2026 16:48
@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 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 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