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(proxy): warn when --compressor selection matches no built-in (#2385)

Zhenjia ZHOUa84b28af0e87
diff --git a/headroom/proxy/server.py b/headroom/proxy/server.py
index 26f1ed90d..3e734310e 100644
--- a/headroom/proxy/server.py
+++ b/headroom/proxy/server.py
@@ -683,9 +683,10 @@ def _apply_compressor_selection(
keeps its dataclass default, so behavior is byte-identical to today. When a
selection is given, each recognized built-in in :data:`BUILTIN_COMPRESSOR_FLAGS`
is enabled iff it (or the wildcard ``"*"``) was selected, and disabled
- otherwise. Unrecognized names are ignored (reserved for the compressor
- registry). This maps a selection onto the existing flags without adding any
- dispatch logic.
+ otherwise. Unrecognized names select no flag (reserved for the compressor
+ registry) but are surfaced with a warning, because a typo'd selection is
+ otherwise indistinguishable from "compress nothing" (#2384). This maps a
+ selection onto the existing flags without adding any dispatch logic.
"""
if compressors is None:
return
@@ -693,6 +694,23 @@ def _apply_compressor_selection(
if not selected:
return
select_all = "*" in selected
+ unmatched = sorted(selected - set(BUILTIN_COMPRESSOR_FLAGS) - {"*"})
+ if unmatched:
+ if select_all or selected & set(BUILTIN_COMPRESSOR_FLAGS):
+ logger.warning(
+ "compressor selection: %s match no built-in compressor "
+ "(assumed registry names); built-ins: %s",
+ ", ".join(unmatched),
+ ", ".join(sorted(BUILTIN_COMPRESSOR_FLAGS)),
+ )
+ else:
+ logger.warning(
+ "compressor selection %s matches no built-in compressor — every "
+ "built-in compressor is now disabled. If this is a typo, valid "
+ "names are: %s (or '*' for all).",
+ ", ".join(unmatched),
+ ", ".join(sorted(BUILTIN_COMPRESSOR_FLAGS)),
+ )
for name, flag in BUILTIN_COMPRESSOR_FLAGS.items():
setattr(router_config, flag, select_all or name in selected)
diff --git a/tests/test_compressor_selection.py b/tests/test_compressor_selection.py
index e1eea1a8e..a2eb7b8ba 100644
--- a/tests/test_compressor_selection.py
+++ b/tests/test_compressor_selection.py
@@ -14,6 +14,7 @@ Covers the two behavior-safe halves of the router/registry integration:
from __future__ import annotations
import dataclasses
+import logging
import pytest
@@ -144,6 +145,44 @@ def test_unrecognized_names_are_ignored_but_recognized_still_apply() -> None:
# No crash / no spurious flag creation for the unknown name.
+# ────────────────── unmatched-name warning (#2384, no behavior change) ────────
+
+
+def test_only_unmatched_selection_warns_that_builtins_are_disabled(
+ caplog: pytest.LogCaptureFixture,
+) -> None:
+ """A typo'd selection must be diagnosable from the startup log."""
+ config = ContentRouterConfig()
+ with caplog.at_level(logging.WARNING, logger="headroom.proxy"):
+ _apply_compressor_selection(config, {"smart_krusher"})
+ # Behavior is unchanged — the opt-in "exactly these" contract still holds.
+ assert not any(_enable_flags(config).values())
+ text = " ".join(r.getMessage() for r in caplog.records)
+ assert "smart_krusher" in text
+ assert "disabled" in text.lower()
+ assert "smart_crusher" in text # valid names listed for the typo case
+
+
+def test_mixed_selection_warns_only_about_unmatched_names(
+ caplog: pytest.LogCaptureFixture,
+) -> None:
+ config = ContentRouterConfig()
+ with caplog.at_level(logging.WARNING, logger="headroom.proxy"):
+ _apply_compressor_selection(config, {"kompress", "does_not_exist"})
+ assert _enable_flags(config)["enable_kompress"] is True
+ text = " ".join(r.getMessage() for r in caplog.records)
+ assert "does_not_exist" in text
+ assert "disabled" not in text.lower() # built-ins were not all turned off
+
+
+def test_matched_selection_emits_no_warning(caplog: pytest.LogCaptureFixture) -> None:
+ for selection in ({"kompress"}, {"*"}):
+ config = ContentRouterConfig()
+ with caplog.at_level(logging.WARNING, logger="headroom.proxy"):
+ _apply_compressor_selection(config, selection)
+ assert not caplog.records
+
+
# ─────────────────────────── ProxyConfig field ───────────────────────────────