Skip to content

Commit 814ffa3

Browse files
gglucassclaudeJerrettDavis
authored
fix(proxy): wire --compression-max-workers / HEADROOM_COMPRESSION_MAX_WORKERS (headroomlabs-ai#1632)
## Description `ProxyConfig.compression_max_workers` is documented as settable via `--compression-max-workers` / `HEADROOM_COMPRESSION_MAX_WORKERS` and is consumed by `HeadroomProxy.__init__` to bound the dedicated compression threadpool. But the proxy CLI never defined the option and never passed the value into `ProxyConfig`, so the field was permanently `None` and always resolved to the `min(32, (cpu_count or 1) * 4)` default. Neither the flag nor the env var had any effect. This matters under concurrent sessions: the compression pool runs CPU-bound Kompress work that releases the GIL, so `cpu*4` oversubscribes cores and there was no way to cap it despite the docs promising one. Closes # ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Performance improvement - [ ] Code refactoring (no functional changes) ## Changes Made - Added the `--compression-max-workers` click option (with `envvar="HEADROOM_COMPRESSION_MAX_WORKERS"`) to the `proxy` command, mirroring the existing `--anthropic-pre-upstream-concurrency` wiring. - Added the `compression_max_workers` parameter to the `proxy()` signature and passed it into the `ProxyConfig(...)` construction. - No change to `HeadroomProxy` — it already reads `config.compression_max_workers` and clamps `< 1` to 1. ## Testing - [x] Unit tests pass (`pytest`) - [x] Linting passes (`ruff check .`) - [x] Type checking passes (`mypy headroom`) - [x] New tests added for new functionality - [ ] Manual testing performed ### Test Output ```text $ pytest tests/test_cli_proxy_improvements.py::TestCompressionMaxWorkers -q 3 passed in 1.50s $ pytest tests/test_cli_proxy_improvements.py -q 48 passed in 5.04s $ ruff check headroom/cli/proxy.py tests/test_cli_proxy_improvements.py All checks passed! $ mypy headroom/cli/proxy.py Success: no issues found in 1 source file ``` ## Real Behavior Proof - Environment: macOS, Python 3.10.18, branch off upstream/main @ 0.28.0 - Exact command / steps: new tests assert the value reaches `ProxyConfig` via both `--compression-max-workers 3` (flag) and `HEADROOM_COMPRESSION_MAX_WORKERS=5` (env), and that it stays `None` when unset. - Observed result: flag -> `config.compression_max_workers == 3`; env -> `== 5`; unset -> `is None`. - Not tested: end-to-end proxy run under real concurrent load (the pool-sizing effect itself is already covered by existing `test_proxy_compression_executor.py`). ## Review Readiness - [x] I have performed a self-review - [x] This PR is ready for human review ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] I have updated the CHANGELOG.md if applicable ## Additional Notes CHANGELOG left untouched: this makes existing documented behavior actually work rather than adding new surface. N/A: manual testing (covered by unit tests + existing executor tests). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
1 parent 4bf7f92 commit 814ffa3

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

headroom/cli/proxy.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,18 @@ def dashboard(port: int, no_open: bool) -> None:
417417
"Env: HEADROOM_ANTHROPIC_PRE_UPSTREAM_MEMORY_CONTEXT_TIMEOUT_SECONDS."
418418
),
419419
)
420+
@click.option(
421+
"--compression-max-workers",
422+
type=int,
423+
default=None,
424+
envvar="HEADROOM_COMPRESSION_MAX_WORKERS",
425+
help=(
426+
"Bound the dedicated compression threadpool (CPU-bound Kompress work). "
427+
"Default (unset): min(32, (cpu_count or 1) * 4). Lower it to reduce CPU "
428+
"oversubscription under concurrent sessions; a value < 1 is clamped to 1. "
429+
"Env: HEADROOM_COMPRESSION_MAX_WORKERS."
430+
),
431+
)
420432
@click.option(
421433
"--log-file",
422434
default=None,
@@ -843,6 +855,7 @@ def proxy(
843855
anthropic_pre_upstream_concurrency: int | None,
844856
anthropic_pre_upstream_acquire_timeout_seconds: float | None,
845857
anthropic_pre_upstream_memory_context_timeout_seconds: float | None,
858+
compression_max_workers: int | None,
846859
log_file: str | None,
847860
log_messages: bool,
848861
codex_wire_debug: bool,
@@ -1167,6 +1180,7 @@ def proxy(
11671180
# Precedence: CLI > env > auto-compute (click's ``envvar``
11681181
# handles the env-var fallback).
11691182
anthropic_pre_upstream_concurrency=anthropic_pre_upstream_concurrency,
1183+
compression_max_workers=compression_max_workers,
11701184
anthropic_pre_upstream_acquire_timeout_seconds=(
11711185
anthropic_pre_upstream_acquire_timeout_seconds
11721186
if anthropic_pre_upstream_acquire_timeout_seconds is not None

tests/test_cli_proxy_improvements.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,34 @@ def test_mode_invalid_value_error(self, runner: CliRunner) -> None:
448448
result = runner.invoke(main, ["proxy", "--mode", "bogus_mode_xyz"])
449449
assert result.exit_code != 0
450450
assert "invalid" in result.output.lower() or "choice" in result.output.lower()
451+
452+
453+
class TestCompressionMaxWorkers:
454+
"""--compression-max-workers / HEADROOM_COMPRESSION_MAX_WORKERS must reach ProxyConfig.
455+
456+
Regression: the field was documented in ProxyConfig and consumed by the
457+
server, but the CLI never defined the option or passed it through, so it
458+
was permanently None (always resolving to the min(32, cpu*4) default).
459+
"""
460+
461+
def test_flag_reaches_config(self, runner: CliRunner, mock_run_server: dict) -> None:
462+
result = runner.invoke(
463+
main, ["proxy", "--compression-max-workers", "3"], catch_exceptions=False
464+
)
465+
assert result.exit_code == 0, result.output
466+
assert mock_run_server["config"].compression_max_workers == 3
467+
468+
def test_env_reaches_config(self, runner: CliRunner, mock_run_server: dict) -> None:
469+
result = runner.invoke(
470+
main,
471+
["proxy"],
472+
env={"HEADROOM_COMPRESSION_MAX_WORKERS": "5"},
473+
catch_exceptions=False,
474+
)
475+
assert result.exit_code == 0, result.output
476+
assert mock_run_server["config"].compression_max_workers == 5
477+
478+
def test_default_is_none(self, runner: CliRunner, mock_run_server: dict) -> None:
479+
result = runner.invoke(main, ["proxy"], catch_exceptions=False)
480+
assert result.exit_code == 0, result.output
481+
assert mock_run_server["config"].compression_max_workers is None

0 commit comments

Comments
 (0)