mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(run_agent): prevent _create_openai_client from mutating caller kwargs
Shallow-copy client_kwargs at the top of _create_openai_client() to prevent in-place mutation from leaking back into self._client_kwargs. Defensive fix that locks the contract for future httpx/transport work. Cherry-picked from #10978 by @taeuk178.
This commit is contained in:
parent
31a72bdbf2
commit
896e7b03e8
2 changed files with 44 additions and 0 deletions
|
|
@ -4340,6 +4340,15 @@ class AIAgent:
|
|||
|
||||
def _create_openai_client(self, client_kwargs: dict, *, reason: str, shared: bool) -> Any:
|
||||
from agent.auxiliary_client import _validate_base_url, _validate_proxy_env_urls
|
||||
# Treat client_kwargs as read-only. Callers pass self._client_kwargs (or shallow
|
||||
# copies of it) in; any in-place mutation leaks back into the stored dict and is
|
||||
# reused on subsequent requests. #10933 hit this by injecting an httpx.Client
|
||||
# transport that was torn down after the first request, so the next request
|
||||
# wrapped a closed transport and raised "Cannot send a request, as the client
|
||||
# has been closed" on every retry. The revert resolved that specific path; this
|
||||
# copy locks the contract so future transport/keepalive work can't reintroduce
|
||||
# the same class of bug.
|
||||
client_kwargs = dict(client_kwargs)
|
||||
_validate_proxy_env_urls()
|
||||
_validate_base_url(client_kwargs.get("base_url"))
|
||||
if self.provider == "copilot-acp" or str(client_kwargs.get("base_url", "")).startswith("acp://copilot"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue