Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(startup): move HF/httpx log suppression before sentence_transformers init (#622)

Patrick A176d4c772a7c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 37a89d993..33f2c5c10 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Bug Fixes
+
* **deps:** move `gunicorn` to `[proxy-prod]` extra with `sys_platform != 'win32'` guard; removed from `[proxy]` to avoid forcing a Unix-only package on dev, CI, and Windows users ([#537](https://github.com/chopratejas/headroom/pull/537))
* **startup:** suppress proxy startup log noise — litellm banner, trafilatura parse errors, HuggingFace Hub unauthenticated warnings, tiktoken fallback warning, and httpx INFO lines from sentence_transformers HEAD checks. Affected files: `headroom/providers/litellm.py`, `headroom/transforms/html_extractor.py`, `headroom/memory/adapters/embedders.py`, `headroom/providers/anthropic.py`, `headroom/providers/registry.py`, `headroom/image/onnx_router.py`, `headroom/transforms/kompress_compressor.py`.
diff --git a/headroom/cli/proxy.py b/headroom/cli/proxy.py
index f0c478adc..361e8cc7b 100644
--- a/headroom/cli/proxy.py
+++ b/headroom/cli/proxy.py
@@ -1,7 +1,9 @@
"""Proxy server CLI commands."""
+import logging
import os
import sys
+import warnings
from typing import Any, Literal, cast
import click
@@ -12,6 +14,40 @@ from headroom.proxy.modes import PROXY_MODE_TOKEN, normalize_proxy_mode
from .main import main
+# ---------------------------------------------------------------------------
+# Startup log suppression.
+#
+# sentence_transformers makes HEAD/GET requests to HuggingFace Hub on every
+# worker startup to validate the model manifest. Each request produces an
+# INFO-level httpx record and a WARNING from huggingface_hub about a missing
+# HF_TOKEN. With 8 workers this generates ~50 noisy lines per startup.
+#
+# Placing the suppression here (module-level in the first CLI module imported)
+# ensures it is in place before sentence_transformers, huggingface_hub, or
+# httpx are initialised by any downstream import or worker fork.
+#
+# The env vars silence the warnings.warn() path ("unauthenticated requests"
+# message) which bypasses the logging system entirely.
+# ---------------------------------------------------------------------------
+
+# Env-var knobs are read by huggingface_hub before its logger hierarchy forms.
+os.environ.setdefault("HF_HUB_DISABLE_IMPLICIT_TOKEN", "1")
+os.environ.setdefault("HF_HUB_DISABLE_PROGRESS_BARS", "1")
+
+# Logger-level suppression: httpx HEAD/GET manifest checks + HF advisory msgs.
+logging.getLogger("httpx").setLevel(logging.WARNING)
+logging.getLogger("huggingface_hub").setLevel(logging.ERROR)
+logging.getLogger("huggingface_hub.utils._http").setLevel(logging.ERROR)
+logging.getLogger("sentence_transformers").setLevel(logging.WARNING)
+
+# warnings.warn() path: huggingface_hub emits UserWarning for missing tokens.
+warnings.filterwarnings("ignore", message=".*unauthenticated.*", category=UserWarning)
+warnings.filterwarnings("ignore", message=".*HF_TOKEN.*", category=UserWarning)
+warnings.filterwarnings("ignore", message=".*huggingface.*token.*", category=UserWarning)
+warnings.filterwarnings("ignore", category=UserWarning, module="huggingface_hub")
+
+# ---------------------------------------------------------------------------
+
_CONTEXT_TOOL_ENV = "HEADROOM_CONTEXT_TOOL"
_CONTEXT_TOOL_RTK = "rtk"
_CONTEXT_TOOL_LEAN_CTX = "lean-ctx"