Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

refactor: inline close logic into wrappers, delete close_llm utility

LearningCircuitb12202df61d9
diff --git a/src/local_deep_research/config/llm_config.py b/src/local_deep_research/config/llm_config.py
index 282b7efc6e..fab453f336 100644
--- a/src/local_deep_research/config/llm_config.py
+++ b/src/local_deep_research/config/llm_config.py
@@ -1032,11 +1032,23 @@ def wrap_llm_without_think_tags(
return getattr(self.base_llm, name)
def close(self):
- """Close underlying HTTP clients held by this LLM. Idempotent."""
- try:
- from ..utilities.llm_utils import close_llm
+ """Close underlying HTTP clients held by this LLM. Idempotent.
- close_llm(self.base_llm)
+ Only ChatOllama creates per-instance httpx.Client objects that
+ need explicit close(). ChatAnthropic uses @lru_cache'd shared
+ httpx clients that must NOT be closed.
+ """
+ try:
+ base = self.base_llm
+ ollama_client = getattr(base, "_client", None)
+ if ollama_client is not None:
+ if not type(ollama_client).__module__.startswith("ollama"):
+ return
+ httpx_client = getattr(ollama_client, "_client", None)
+ if httpx_client is not None and hasattr(
+ httpx_client, "close"
+ ):
+ httpx_client.close()
except Exception:
pass
diff --git a/src/local_deep_research/utilities/llm_utils.py b/src/local_deep_research/utilities/llm_utils.py
index 5b3a3252de..e8a400b84a 100644
--- a/src/local_deep_research/utilities/llm_utils.py
+++ b/src/local_deep_research/utilities/llm_utils.py
@@ -12,32 +12,6 @@ from typing import Any, Optional, Dict
from ..config.thread_settings import get_setting_from_snapshot
-def close_llm(llm):
- """Close underlying HTTP clients held by LLM instances.
-
- Only ChatOllama creates per-instance httpx.Client objects that need
- explicit close(). ChatAnthropic uses @lru_cache'd shared httpx
- clients that must NOT be closed.
- """
- try:
- # Unwrap ProcessingLLMWrapper
- base = getattr(llm, "base_llm", llm)
- # ChatOllama path: base._client is ollama.Client,
- # base._client._client is httpx.Client
- ollama_client = getattr(base, "_client", None)
- if ollama_client is not None:
- # Only close Ollama clients — Anthropic's are @lru_cache'd and shared.
- # This relies on ollama's module structure; if the ollama package
- # reorganises its internals this guard may need updating.
- if not type(ollama_client).__module__.startswith("ollama"):
- return
- httpx_client = getattr(ollama_client, "_client", None)
- if httpx_client is not None and hasattr(httpx_client, "close"):
- httpx_client.close()
- except Exception:
- pass
-
-
def get_ollama_base_url(
settings_snapshot: Optional[Dict[str, Any]] = None,
) -> str:
diff --git a/src/local_deep_research/web_search_engines/rate_limiting/llm/wrapper.py b/src/local_deep_research/web_search_engines/rate_limiting/llm/wrapper.py
index a1d879599f..21a74852ca 100644
--- a/src/local_deep_research/web_search_engines/rate_limiting/llm/wrapper.py
+++ b/src/local_deep_research/web_search_engines/rate_limiting/llm/wrapper.py
@@ -199,11 +199,23 @@ def create_rate_limited_llm_wrapper(base_llm, provider: Optional[str] = None):
return getattr(self.base_llm, name)
def close(self):
- """Close underlying HTTP clients held by this LLM. Idempotent."""
- try:
- from local_deep_research.utilities.llm_utils import close_llm
+ """Close underlying HTTP clients held by this LLM. Idempotent.
- close_llm(self.base_llm)
+ Only ChatOllama creates per-instance httpx.Client objects that
+ need explicit close(). ChatAnthropic uses @lru_cache'd shared
+ httpx clients that must NOT be closed.
+ """
+ try:
+ base = self.base_llm
+ ollama_client = getattr(base, "_client", None)
+ if ollama_client is not None:
+ if not type(ollama_client).__module__.startswith("ollama"):
+ return
+ httpx_client = getattr(ollama_client, "_client", None)
+ if httpx_client is not None and hasattr(
+ httpx_client, "close"
+ ):
+ httpx_client.close()
except Exception:
pass