Skip to content

fix(credential_pool): recover exhausted entries on endpoint changes - #21422

Closed
DanielLSM wants to merge 1 commit into
NousResearch:mainfrom
DanielLSM:fix/credential-pool-endpoint-sync
Closed

DanielLSM wants to merge 1 commit into
NousResearch:mainfrom
DanielLSM:fix/credential-pool-endpoint-sync

Conversation

@DanielLSM

@DanielLSM DanielLSM commented May 7, 2026

Copy link
Copy Markdown
Contributor

Symptom

A credential pool entry can remain exhausted on a stale base_url even after runtime provider resolution has detected a different working endpoint.

The concrete case is Z.AI regular vs coding-plan API surfaces: endpoint detection can cache the working coding-plan endpoint in provider_state.zai.detected_endpoint, while the pool entry remains stuck on the regular endpoint and is skipped before that newer auth state is used.

Root cause

CredentialPool._available_entries() checks exhaustion before syncing endpoint state from auth.json. For providers with multiple API surfaces, that leaves the pool entry stranded on an endpoint that no longer reflects the provider's detected working URL.

Fix

  • Add _sync_endpoint_from_provider_state() to adopt provider_state.<provider>.detected_endpoint when it differs from the pool entry's cached base_url.
  • Clear exhaustion only when the detected endpoint actually changes, so the entry can be retried on the working endpoint immediately.
  • Re-probe provider endpoint detectors after an exhausted entry's cooldown expires, before returning the entry to callers.
  • Keep the entry exhausted if no endpoint currently works, preserving the original error context.

The sync/re-probe mechanism is provider-agnostic; Z.AI is the first opted-in detector via _PROVIDER_ENDPOINT_DETECTORS.

Related context

Test plan

pytest tests/agent/test_credential_pool.py -q

Result: 46 passed.

@DanielLSM
DanielLSM force-pushed the fix/credential-pool-endpoint-sync branch from ffa869c to 6b0d850 Compare May 7, 2026 17:04
@DanielLSM DanielLSM changed the title fix(credential_pool): sync provider endpoints from auth state fix(credential_pool): recover exhausted entries on endpoint changes May 7, 2026
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/zai ZAI provider labels May 7, 2026
When a provider has multiple API surfaces, a pool entry can stay exhausted on a stale base_url after runtime endpoint detection finds a different working endpoint. Z.AI regular vs coding-plan endpoints expose this: auth state can contain the detected working endpoint while the pool entry remains stranded on the old URL.

Changes:
- sync exhausted pool entries from provider_state.<provider>.detected_endpoint before skipping them
- re-probe configured endpoint detectors when an exhausted entry's cooldown expires
- keep the entry exhausted if no endpoint currently works, preserving the original error context

The mechanism is provider-agnostic; Z.AI is the first opted-in detector.

Related: NousResearch#5668, NousResearch#19083

Test: pytest tests/agent/test_credential_pool.py -q (46 passed)
@DanielLSM

Copy link
Copy Markdown
Contributor Author

Closing in favor of consolidated PR #22827.

@DanielLSM DanielLSM closed this May 9, 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