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.

refactor: remove test-only compatibility helpers in rollout and agent_savings (#4089)

Tejas Chopra310c108c24ca
diff --git a/headroom/agent_savings.py b/headroom/agent_savings.py
index 0c9271407..000464c1a 100644
--- a/headroom/agent_savings.py
+++ b/headroom/agent_savings.py
@@ -5,7 +5,7 @@ from __future__ import annotations
import logging
import os
from collections.abc import MutableMapping
-from dataclasses import dataclass, replace
+from dataclasses import dataclass
from typing import Protocol
logger = logging.getLogger(__name__)
@@ -408,18 +408,3 @@ def seed_proxy_env_defaults(
# already in the env and otherwise falls back to DEFAULT_PROFILE (coding).
apply_agent_savings_env_defaults(target)
return frozenset(key for key in target if key not in before)
-
-
-def with_target_savings(
- profile: AgentSavingsProfile,
- target_savings: float,
-) -> AgentSavingsProfile:
- """Return a copy of ``profile`` adjusted to a specific savings target."""
-
- if not 0 < target_savings < 1:
- raise ValueError("target_savings must be between 0 and 1")
- return replace(
- profile,
- target_savings=target_savings,
- target_ratio=round(1 - target_savings, 4),
- )
diff --git a/headroom/rollout.py b/headroom/rollout.py
index ea381ba2f..d1764dc55 100644
--- a/headroom/rollout.py
+++ b/headroom/rollout.py
@@ -478,26 +478,3 @@ def _resolve_snapshot(
config=config,
decisions=tuple(decisions),
)
-
-
-def current_rollout(environ: Mapping[str, str] | None = None) -> RolloutSnapshot:
- """Compatibility name for resolving a snapshot at a composition boundary."""
-
- return resolve_rollout(environ)
-
-
-def feature_enabled(
- feature: str,
- *,
- explicit: bool = False,
- environ: Mapping[str, str] | None = None,
-) -> bool:
- """Compatibility helper for composition roots; do not use in deep components."""
-
- requested = (feature,) if explicit else ()
- return resolve_rollout(environ, requested=requested).is_enabled(feature)
-
-
-# The PR was never released, but this narrow source alias keeps in-branch callers
-# importable while the correction migrates them. It is intentionally undocumented.
-Rollout = RolloutSnapshot
diff --git a/tests/test_agent_savings.py b/tests/test_agent_savings.py
index e9dd76eb8..11e8b049d 100644
--- a/tests/test_agent_savings.py
+++ b/tests/test_agent_savings.py
@@ -17,7 +17,6 @@ from headroom.agent_savings import (
get_agent_savings_profile,
proxy_pipeline_kwargs,
seed_proxy_env_defaults,
- with_target_savings,
)
from headroom.cli import wrap as wrap_module
from headroom.cli.main import main
@@ -210,13 +209,6 @@ def test_unknown_agent_savings_profile_falls_back_to_default(
assert DEFAULT_PROFILE in caplog.text
-def test_with_target_savings_recomputes_target_ratio() -> None:
- profile = with_target_savings(get_agent_savings_profile("balanced"), 0.85)
-
- assert profile.target_savings == 0.85
- assert profile.target_ratio == 0.15
-
-
def test_agent_savings_cli_renders_shell_exports() -> None:
result = CliRunner().invoke(main, ["agent-savings", "--profile", "agent-90"])
diff --git a/tests/test_rollout.py b/tests/test_rollout.py
index c7209c0c2..21db2b2ca 100644
--- a/tests/test_rollout.py
+++ b/tests/test_rollout.py
@@ -16,8 +16,6 @@ from headroom.rollout import (
RolloutChannel,
RolloutConfigurationError,
RolloutSnapshot,
- current_rollout,
- feature_enabled,
registry_digest,
resolve_rollout,
)
@@ -323,8 +321,8 @@ def test_worker_rollout_handoff_rejects_non_object_state() -> None:
RolloutSnapshot.from_internal_dict([]) # type: ignore[arg-type]
-def test_snapshot_query_and_compatibility_helpers() -> None:
- snapshot = current_rollout(
+def test_snapshot_query_helpers() -> None:
+ snapshot = resolve_rollout(
{
"HEADROOM_ROLLOUT_CHANNEL": "canary",
"HEADROOM_FEATURES": "tool_result_interceptors",
@@ -335,12 +333,11 @@ def test_snapshot_query_and_compatibility_helpers() -> None:
assert snapshot.is_available("tool-result-interceptors") is True
assert snapshot.enabled == frozenset({"tool_result_interceptors"})
assert snapshot.disabled == frozenset({"read_maturation"})
- assert feature_enabled(
- "tool_result_interceptors",
- explicit=True,
- environ={"HEADROOM_ROLLOUT_CHANNEL": "canary"},
- )
- assert not feature_enabled("tool_result_interceptors", environ={})
+ assert resolve_rollout(
+ {"HEADROOM_ROLLOUT_CHANNEL": "canary"},
+ requested=("tool_result_interceptors",),
+ ).is_enabled("tool_result_interceptors")
+ assert not resolve_rollout({}).is_enabled("tool_result_interceptors")
with pytest.raises(KeyError, match="missing"):
snapshot.decision("missing")