fix(auxiliary): resolve named provider credentials when base_url is set#16727
Open
thapecroth wants to merge 3 commits into
Open
fix(auxiliary): resolve named provider credentials when base_url is set#16727thapecroth wants to merge 3 commits into
thapecroth wants to merge 3 commits into
Conversation
…ool use (NousResearch#15275) Architectural fix inspired by Claude Code's SocketPool pattern. Replaces eager import-time MCP server spawning with lazy initialization: - discover_mcp_tools(lazy=True): registers tool stubs from cache without connecting to MCP servers - ensure_mcp_initialized(): thread-safe singleton that connects all configured MCP servers on first actual tool call (no-op thereafter) - _register_mcp_tool_stubs(): loads cached tool schemas from ~/.hermes/cache/mcp_tools/ so the model sees MCP tools at session start without subprocess overhead - _save_cached_tool_definitions(): persists tool schemas after successful discovery for future lazy loads Key difference from env var guard (PR NousResearch#15796): this prevents duplicates by design — no consumer needs to remember to set an env var. Multiple importers of model_tools in the same process share the same lazy pool. MCP servers only spawn when a tool is actually invoked. 11 new tests cover: lazy discovery, ensure_mcp_initialized idempotency, cache persistence, and slash_worker import safety.
Add real subprocess test that verifies importing model_tools does NOT call register_mcp_servers at import time (the core NousResearch#15275 fix). This catches regressions even if the mock-based tests pass.
…et (NousResearch#16290) When auxiliary.vision.provider is set to a named provider (e.g. 'zai') with a custom base_url, the credential pool was not consulted for that provider's API key. Instead, the provider was silently forced to 'custom' and only OPENAI_API_KEY was checked, causing 401 errors. Root cause: _resolve_task_provider_model() forced provider='custom' whenever cfg_base_url was set, discarding the original named provider. resolve_vision_provider_client() then only looked up credentials from the 'custom' pool. Fix: - _resolve_task_provider_model: when both cfg_provider and cfg_base_url are set, preserve the named provider instead of forcing 'custom'. - resolve_vision_provider_client: when a named provider accompanies a base_url, resolve credentials from that provider's pool via the new _resolve_provider_api_key() helper before falling back to 'custom'. - Added 8 tests covering the new behavior and edge cases. Fixes NousResearch#16290
Collaborator
9c1ed00 to
2e6f3d7
Compare
19 tasks
This was referenced May 12, 2026
This was referenced May 25, 2026
1 task
13 tasks
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
Fixes #16290
When
auxiliary.vision.provideris set to a named provider (e.g.zai) with a custombase_url, the credential pool was not consulted for that provider's API key. The provider was silently forced tocustomand onlyOPENAI_API_KEYwas checked, causing 401 errors.Root Cause
_resolve_task_provider_model()forcedprovider='custom'whenevercfg_base_urlwas set, discarding the original named provider.resolve_vision_provider_client()then only looked up credentials from thecustompool.Changes
_resolve_task_provider_model()— when bothcfg_providerandcfg_base_urlare set, preserve the named provider instead of forcing'custom'resolve_vision_provider_client()— when a named provider accompanies a base_url, resolve credentials from that provider's pool via the new_resolve_provider_api_key()helper_resolve_provider_api_key()— new helper that consultsPROVIDER_REGISTRY+resolve_api_key_provider_credentials()to get the right key for a named providerTest Coverage
8 new tests in
test_vision_provider_base_url_credentials.py:All 96 existing auxiliary tests continue to pass.
Reproduction (before fix)
Previously: 401 error. After fix:
ZAI_API_KEYfrom.envis used.