The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(aux): a callable key_cmd credential survives every custom-provider resolution branch (#88667)
kshitijk4poora51c65994476
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 087fbc065cf..e82ad668113 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -4737,6 +4737,13 @@ class _ResolveRequest(NamedTuple):_ResolveResult = Tuple[Optional[Any], Optional[str]]+def _explicit_key(raw: Any) -> Any:+ """A key_cmd/Entra callable passes through uncalled; strings are stripped; anything else is ''."""+ if callable(raw) and not isinstance(raw, str):+ return raw+ return str(raw or "").strip()++def _log_once_debug(seen: set, key: Any, msg: str, *args: Any) -> None:"""Debug-log ``msg`` the first time ``key`` is seen so per-call retries stay silent."""if key not in seen:@@ -4922,10 +4929,10 @@ def _resolve_custom_branch(req: _ResolveRequest) -> _ResolveResult:# SECURITY: a local-server alias never borrows OPENAI_API_KEY or the main key —# the alias means "this is my own server"; sending an OpenAI secret to whatever# host base_url names is never intended. Explicit api_key or the placeholder only.- custom_key = (req.explicit_api_key or "").strip() or "no-key-required"+ custom_key = _explicit_key(req.explicit_api_key) or "no-key-required"else:custom_key = (- (req.explicit_api_key or "").strip()+ _explicit_key(req.explicit_api_key)or _scoped_key_env("OPENAI_API_KEY")or _read_main_api_key_if_same_host(custom_base)or "no-key-required" # local servers don't need auth@@ -4939,7 +4946,7 @@ def _resolve_custom_branch(req: _ResolveRequest) -> _ResolveResult:# Re-resolution loses the provider name and falls back to OpenRouter or a wrong API-key provider —# the main agent already solved this, we just need to reuse its answer. (#45472)_main_base = str(main_runtime.get("base_url") or "").strip().rstrip("/")- _main_key = str(main_runtime.get("api_key") or "").strip()+ _main_key = _explicit_key(main_runtime.get("api_key"))if _main_base and _main_key:custom_base, custom_key = _main_base, _main_keyif custom_base and custom_key:@@ -5008,7 +5015,7 @@ def _resolve_named_custom_branch(req: _ResolveRequest) -> Optional[_ResolveResul# whatever the caller left blank, never replaces what the caller set (compression prompts carry# conversation history, so a silently swapped destination is a data-routing bug, not a nuisance).custom_base = (req.explicit_base_url or custom_entry.get("base_url") or "").strip()- custom_key = (req.explicit_api_key or "").strip() or _named_custom_api_key(custom_entry, provider, custom_base)+ custom_key = _explicit_key(req.explicit_api_key) or _named_custom_api_key(custom_entry, provider, custom_base)if custom_key == "no-key-required":logger.warning("resolve_provider_client: named custom provider %r has no resolvable ""api_key — request will be sent with placeholder no-key-required "@@ -5106,7 +5113,7 @@ def _resolve_api_key_branch(req: _ResolveRequest, pconfig: Any, resolve_creds: C# Explicit api_key override (fallback_model / custom_providers entry) lets callers# authenticate where no built-in credential is registered for this alias.if req.explicit_api_key:- api_key = req.explicit_api_key.strip() or api_key+ api_key = _explicit_key(req.explicit_api_key) or api_keyraw_base_url = str(creds.get("base_url", "")).strip().rstrip("/") or pconfig.inference_base_urlif req.explicit_base_url:raw_base_url = req.explicit_base_url.strip().rstrip("/")