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(kompress): skip the local model download when a remote endpoint is set (#4234)

Tejas Chopraff3693165344
diff --git a/headroom/proxy/server.py b/headroom/proxy/server.py
index 231deefcd..0edd8e1c5 100644
--- a/headroom/proxy/server.py
+++ b/headroom/proxy/server.py
@@ -2229,7 +2229,10 @@ class HeadroomProxy(
# Log component status
if self._kompress_status == "enabled":
- logger.info("Kompress: ENABLED (ModernBERT token compressor)")
+ if eager_status.get("kompress_backend") == "remote":
+ logger.info("Kompress: ENABLED (remote endpoint; no local model)")
+ else:
+ logger.info("Kompress: ENABLED (ModernBERT token compressor)")
elif self._kompress_status == "deferred":
if self._start_kompress_background_warmup():
logger.info("Kompress: DEFERRED (warming in the background after startup)")
diff --git a/headroom/proxy/warmup.py b/headroom/proxy/warmup.py
index 9c66ab36a..895b6fdfd 100644
--- a/headroom/proxy/warmup.py
+++ b/headroom/proxy/warmup.py
@@ -111,21 +111,27 @@ class WarmupRegistry:
``error`` statuses must be set explicitly by the caller.
"""
- def _apply(slot: WarmupSlot, value: str | None) -> None:
+ def _apply(slot: WarmupSlot, value: str | None, **info: Any) -> None:
if value is None:
return
v = value.strip().lower()
if v in {"enabled", "ready"} or v.startswith("loaded"):
# Preserve whatever handle/info was set already.
if slot.status != "loaded":
- slot.mark_loaded(handle=slot.handle, source_status=value)
+ slot.mark_loaded(handle=slot.handle, source_status=value, **info)
else:
slot.info.setdefault("source_status", value)
else:
if slot.status != "loaded":
slot.info["source_status"] = value
- _apply(self.kompress, status.get("kompress"))
+ # A remote endpoint is ready at startup; /readyz reports its backend.
+ kompress_backend = status.get("kompress_backend")
+ _apply(
+ self.kompress,
+ status.get("kompress"),
+ **({"backend": kompress_backend} if kompress_backend == "remote" else {}),
+ )
_apply(self.magika, status.get("magika"))
_apply(self.code_aware, status.get("code_aware"))
_apply(self.tree_sitter, status.get("tree_sitter"))
diff --git a/headroom/transforms/content_router.py b/headroom/transforms/content_router.py
index 0ff77f423..9d56c87f6 100644
--- a/headroom/transforms/content_router.py
+++ b/headroom/transforms/content_router.py
@@ -5198,7 +5198,12 @@ class ContentRouter(Transform):
if self.config.enable_kompress:
compressor = self._get_kompress()
if compressor:
- if not hasattr(compressor, "preload"):
+ if compressor is self._get_remote_kompress():
+ # HEADROOM_KOMPRESS_ENDPOINT runs the model; there is no
+ # local model to download or warm.
+ status["kompress"] = "enabled"
+ status["kompress_backend"] = "remote"
+ elif not hasattr(compressor, "preload"):
status["kompress"] = "enabled"
status["kompress_backend"] = "unknown"
else:
diff --git a/tests/test_proxy_health.py b/tests/test_proxy_health.py
index b45cb42ad..d931eeb28 100644
--- a/tests/test_proxy_health.py
+++ b/tests/test_proxy_health.py
@@ -323,3 +323,29 @@ def test_readyz_kompress_state_matrix(monkeypatch, slot_status, compressor, disa
payload = TestClient(app).get("/readyz").json()["checks"]["kompress"]
assert payload == expected
+
+
+def test_remote_kompress_endpoint_skips_local_model_at_startup(monkeypatch):
+ """With HEADROOM_KOMPRESS_ENDPOINT set, startup neither fetches nor warms the
+ local model, and /readyz still names the remote backend."""
+ import threading
+
+ monkeypatch.setenv("HEADROOM_SKIP_UPSTREAM_CHECK", "1")
+ monkeypatch.setenv("HEADROOM_KOMPRESS_ENDPOINT", "https://kompress.example.test")
+ monkeypatch.setenv("HEADROOM_KOMPRESS_WARMUP", "1")
+ monkeypatch.setenv("HEADROOM_KOMPRESS_WARMUP_DELAY_SECONDS", "3600")
+ prefetched: list[str] = []
+ monkeypatch.setattr(
+ kompress_compressor,
+ "ensure_background_prefetch",
+ lambda model_id: (prefetched.append(model_id), True)[1],
+ )
+ app = create_app(ProxyConfig(optimize=True, cache_enabled=False, rate_limit_enabled=False))
+
+ with TestClient(app) as client:
+ app.state.proxy.http_client = object()
+ payload = client.get("/readyz").json()
+
+ assert prefetched == []
+ assert not any(t.name == "kompress-warmup" for t in threading.enumerate())
+ assert payload["checks"]["kompress"]["backend"] == "remote"