mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(cli): treat an empty HEADROOM_COMPRESS_USER_MESSAGES as unset
`headroom proxy` parsed the variable with its local helper, which maps an empty value to False, while `python -m headroom.proxy.server` and the uvicorn factory map it to None. HEADROOM_COMPRESS_USER_MESSAGES= (empty) therefore turned user-message compression off on one entry point and followed the profile on the others. Use the server's optional-bool parser in the CLI too, so empty means unset everywhere. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1147,6 +1147,7 @@ def proxy(
|
||||
# Import here to avoid slow startup
|
||||
from headroom.proxy.server import (
|
||||
ProxyConfig,
|
||||
_get_env_optional_bool,
|
||||
_parse_csv_tools,
|
||||
_parse_exclude_tools,
|
||||
_parse_tool_profiles,
|
||||
@@ -1346,7 +1347,8 @@ def proxy(
|
||||
rate_limit_enabled=not no_rate_limit,
|
||||
rate_limit_requests_per_minute=rpm if rpm is not None else 60,
|
||||
rate_limit_tokens_per_minute=tpm,
|
||||
compress_user_messages=_get_env_bool_optional("HEADROOM_COMPRESS_USER_MESSAGES"),
|
||||
# Same parse as the server entry points: empty means unset (profile).
|
||||
compress_user_messages=_get_env_optional_bool("HEADROOM_COMPRESS_USER_MESSAGES"),
|
||||
periodic_malloc_trim_enabled=_get_env_bool(
|
||||
"HEADROOM_MALLOC_TRIM", default_periodic_malloc_trim()
|
||||
),
|
||||
|
||||
@@ -292,11 +292,16 @@ class TestCLIProxyEnvVars:
|
||||
assert captured_config["config"].min_tokens_to_crush == 120
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("env", "expected"), [({"HEADROOM_COMPRESS_USER_MESSAGES": "0"}, False), ({}, True)]
|
||||
("env", "expected"),
|
||||
[
|
||||
({"HEADROOM_COMPRESS_USER_MESSAGES": "0"}, False),
|
||||
({"HEADROOM_COMPRESS_USER_MESSAGES": ""}, True),
|
||||
({}, True),
|
||||
],
|
||||
)
|
||||
def test_compress_user_messages_env_off_overrides_profile(self, runner, env, expected):
|
||||
"""HEADROOM_COMPRESS_USER_MESSAGES=0 must turn off the coding profile's
|
||||
user-message compression; unset keeps the profile default (on)."""
|
||||
user-message compression; unset or empty keeps the profile default (on)."""
|
||||
from headroom.agent_savings import proxy_pipeline_kwargs
|
||||
|
||||
captured_config = {}
|
||||
@@ -798,6 +803,20 @@ class TestCLIProxyEnvVars:
|
||||
assert captured["kwargs"].get("print_banner") is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("value", "expected"), [("0", False), ("", True), (None, True)])
|
||||
def test_proxy_config_from_env_compress_user_messages(monkeypatch, value, expected):
|
||||
"""The uvicorn factory and `python -m headroom.proxy.server` read
|
||||
HEADROOM_COMPRESS_USER_MESSAGES the same way `headroom proxy` does."""
|
||||
from headroom.agent_savings import proxy_pipeline_kwargs
|
||||
from headroom.proxy.server import _proxy_config_from_env
|
||||
|
||||
if value is not None:
|
||||
monkeypatch.setenv("HEADROOM_COMPRESS_USER_MESSAGES", value)
|
||||
|
||||
kwargs = proxy_pipeline_kwargs(_proxy_config_from_env())
|
||||
assert kwargs["compress_user_messages"] is expected
|
||||
|
||||
|
||||
class TestCLIProxyBackend:
|
||||
"""Test that litellm-* backends are accepted by the CLI."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user