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(install/apply): add --no-rate-limit flag, persist in proxy_args (#1350) (#1365)

Peter Lodri31d03449910f
diff --git a/headroom/cli/install.py b/headroom/cli/install.py
index e8bd77bb8..f5a7141c3 100644
--- a/headroom/cli/install.py
+++ b/headroom/cli/install.py
@@ -437,6 +437,7 @@ def _build_deployment_manifest(
extra_env: dict[str, str] | None = None,
supervisor_kind: str | None = None,
extra_base_env: dict[str, str] | None = None,
+ no_rate_limit: bool = False,
) -> DeploymentManifest:
manifest = build_manifest(
profile=profile,
@@ -452,6 +453,7 @@ def _build_deployment_manifest(
proxy_mode=proxy_mode,
memory_enabled=memory,
telemetry_enabled=telemetry and not no_telemetry,
+ no_rate_limit=no_rate_limit,
image=image,
no_http2=no_http2,
code_aware=code_aware,
@@ -620,6 +622,18 @@ def _echo_installed(manifest: DeploymentManifest, *, prefix: str = "Installed pe
is_flag=True,
help="Force anonymous telemetry off in the runtime (already the default).",
)
+ "--no-rate-limit",
+ "no_rate_limit",
+ is_flag=True,
+ default=False,
+ help=(
+ "Disable the proxy's built-in rate limiter (default: 60 req/min). "
+ "Recommended for always-on agentic targets (Claude Code, Codex) that "
+ "burst above the default threshold. The flag is persisted in the "
+ "deployment manifest so reinstalls don't silently reintroduce throttling."
+ ),
+)
@click.option(
"--image",
default="ghcr.io/headroomlabs-ai/headroom:latest",
@@ -691,6 +705,7 @@ def install_apply(
memory: bool,
telemetry: bool,
no_telemetry: bool,
+ no_rate_limit: bool,
image: str,
no_http2: bool,
code_aware: bool | None,
@@ -737,6 +752,7 @@ def install_apply(
memory=memory,
telemetry=telemetry,
no_telemetry=no_telemetry,
+ no_rate_limit=no_rate_limit,
image=image,
no_http2=no_http2,
code_aware=code_aware,
diff --git a/headroom/install/planner.py b/headroom/install/planner.py
index a545ffd01..6bdd3700b 100644
--- a/headroom/install/planner.py
+++ b/headroom/install/planner.py
@@ -133,6 +133,7 @@ def build_manifest(
memory_enabled: bool,
telemetry_enabled: bool,
image: str,
+ no_rate_limit: bool = False,
no_http2: bool = False,
code_aware: bool | None = None,
intercept_tool_results: bool = False,
@@ -231,6 +232,11 @@ def build_manifest(
backend,
]
proxy_args.append("--telemetry" if telemetry_enabled else "--no-telemetry")
+ # Agentic CLI targets (Claude Code, Codex) burst well above 60 req/min.
+ # Persist the flag so reinstalls don't silently reintroduce throttling.
+ # (see: https://github.com/headroomlabs-ai/headroom/issues/1350)
+ if no_rate_limit:
+ proxy_args.append("--no-rate-limit")
if memory_enabled:
proxy_args.append("--memory")
# `_paths.memory_db_path()` resolves against the HOST home. A container
diff --git a/tests/test_install_apply_no_rate_limit.py b/tests/test_install_apply_no_rate_limit.py
new file mode 100644
index 000000000..799681813
--- /dev/null
+++ b/tests/test_install_apply_no_rate_limit.py
@@ -0,0 +1,102 @@
+"""Tests that --no-rate-limit is wired through install apply to proxy_args.
+
+Regression for https://github.com/headroomlabs-ai/headroom/issues/1350:
+agentic CLI targets (Claude Code, Codex) burst above the 60 req/min default,
+causing the proxy to self-throttle instead of forwarding to Anthropic.
+--no-rate-limit on `headroom proxy` existed, but `headroom install apply`
+had no flag to persist it — reinstalls silently reintroduced throttling.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from headroom.install.planner import build_manifest
+
+_BASE_KWARGS = {
+ "profile": "default",
+ "preset": "persistent-service",
+ "runtime_kind": "python",
+ "scope": "user",
+ "provider_mode": "auto",
+ "targets": [],
+ "port": 8787,
+ "backend": "anthropic",
+ "anyllm_provider": None,
+ "region": None,
+ "proxy_mode": "token",
+ "memory_enabled": False,
+ "telemetry_enabled": False,
+ "image": "ghcr.io/chopratejas/headroom:latest",
+}
+
+
+def test_no_rate_limit_false_by_default() -> None:
+ """Default manifest must NOT include --no-rate-limit in proxy_args."""
+ manifest = build_manifest(**_BASE_KWARGS)
+ assert "--no-rate-limit" not in manifest.proxy_args
+
+
+def test_no_rate_limit_true_appends_flag() -> None:
+ """no_rate_limit=True must append --no-rate-limit to proxy_args."""
+ manifest = build_manifest(**_BASE_KWARGS, no_rate_limit=True)
+ assert "--no-rate-limit" in manifest.proxy_args
+
+
+def test_no_rate_limit_flag_position() -> None:
+ """--no-rate-limit must appear after --no-telemetry in proxy_args
+ so the manifest is deterministic and diffable."""
+ manifest = build_manifest(**_BASE_KWARGS, no_rate_limit=True)
+ args = manifest.proxy_args
+ assert "--no-telemetry" in args
+ assert args.index("--no-rate-limit") > args.index("--no-telemetry")
+
+
+def test_no_rate_limit_idempotent_on_reinstall() -> None:
+ """Rebuilding the manifest with the same flag must not duplicate it."""
+ manifest1 = build_manifest(**_BASE_KWARGS, no_rate_limit=True)
+ manifest2 = build_manifest(**_BASE_KWARGS, no_rate_limit=True)
+ assert manifest1.proxy_args.count("--no-rate-limit") == 1
+ assert manifest2.proxy_args.count("--no-rate-limit") == 1
+
+
+def test_cli_flag_wired_through_install_apply() -> None:
+ """headroom install apply --no-rate-limit must produce a manifest
+ with --no-rate-limit in proxy_args (integration: CLI → planner)."""
+ from unittest.mock import patch
+
+ pytest.importorskip("fastapi")
+ from click.testing import CliRunner
+
+ from headroom.cli.install import install_apply
+
+ runner = CliRunner()
+ # --dry-run or equivalent: we just check the manifest is built correctly.
+ # Since install_apply does real side-effects, we patch the heavy parts.
+
+ built_manifests = []
+
+ def capture_manifest(**kwargs):
+ m = build_manifest(**kwargs)
+ built_manifests.append(m)
+ return m
+
+ with (
+ patch("headroom.cli.install.build_manifest", side_effect=capture_manifest),
+ patch("headroom.cli.install.load_manifest", return_value=None),
+ patch("headroom.cli.install.apply_mutations", return_value=[]),
+ patch("headroom.cli.install.install_supervisor", return_value=[]),
+ patch("headroom.cli.install.save_manifest"),
+ patch("headroom.cli.install._start_deployment"),
+ patch("headroom.cli.install.click.echo"),
+ ):
+ runner.invoke(
+ install_apply,
+ ["--no-rate-limit", "--scope", "user"],
+ catch_exceptions=False,
+ )
+
+ assert built_manifests, "build_manifest was never called"
+ assert "--no-rate-limit" in built_manifests[0].proxy_args, (
+ f"--no-rate-limit not in proxy_args: {built_manifests[0].proxy_args}"
+ )