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.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
fix(install): make install status agree with doctor when the proxy is reachable (#3072) (#3141)
Vishal Veera Reddy05431b264f4f
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 8122375f3..1bc498a48 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -438,6 +438,32 @@ jobs:token: ${{ secrets.CODECOV_TOKEN }}fail_ci_if_error: false+ # Keep a small but real pytest lane on Darwin. The full four-shard suite is+ # intentionally Linux-only for cost, but platform-gated CLI/proxy code must+ # execute somewhere on macOS; otherwise Darwin regressions can merge green+ # while being unreachable in every pytest job (#3065).+ test-macos:+ needs: changes+ if: needs.changes.outputs.code == 'true'+ runs-on: macos-latest+ timeout-minutes: 20+ steps:+ - uses: actions/checkout@v7+ - uses: actions/setup-python@v6+ with:+ python-version: ${{ env.PY_VERSION }}+ - name: Install package and focused test dependencies+ run: |+ python -m pip install --upgrade pip+ pip install -e '.[proxy]' pytest pytest-asyncio numpy+ - name: Run macOS CLI and install tests+ run: |+ pytest \+ tests/test_cli \+ tests/test_cli_*.py \+ tests/test_install \+ --tb=short -q+test-extras:needs: [changes, build-wheel]if: needs.changes.outputs.code == 'true'diff --git a/headroom/cli/install.py b/headroom/cli/install.pyindex 154fb407c..e272634fc 100644--- a/headroom/cli/install.py+++ b/headroom/cli/install.py@@ -1166,14 +1166,20 @@ def install_status(profile: str) -> None:manifest = _require_manifest(profile)payload = probe_json(manifest.health_url.replace("/readyz", "/health"))+ healthy = probe_ready(manifest.health_url)+ # The health endpoint is the authoritative process signal. Detached runtimes+ # can outlive a missing/stale PID file (for example after cleanup or a+ # supervisor restart), while Docker's local CLI view can also be temporarily+ # unavailable. Never report a reachable, ready proxy as "stopped" (#3072).+ status = "running" if healthy else runtime_status(manifest)click.echo(f"Profile: {manifest.profile}")click.echo(f"Preset: {manifest.preset}")click.echo(f"Runtime: {manifest.runtime_kind}")click.echo(f"Supervisor: {manifest.supervisor_kind}")click.echo(f"Scope: {manifest.scope}")click.echo(f"Port: {manifest.port}")- click.echo(f"Status: {runtime_status(manifest)}")- click.echo(f"Healthy: {'yes' if probe_ready(manifest.health_url) else 'no'}")+ click.echo(f"Status: {status}")+ click.echo(f"Healthy: {'yes' if healthy else 'no'}")if payload and isinstance(payload, dict):click.echo(f"Health URL: {manifest.health_url.replace('/readyz', '/health')}")# `config` may be a non-dict (null / string / list) if a different ordiff --git a/tests/test_cli/test_install_cli.py b/tests/test_cli/test_install_cli.pyindex 2183d4058..b7ff101f1 100644--- a/tests/test_cli/test_install_cli.py+++ b/tests/test_cli/test_install_cli.py@@ -497,6 +497,42 @@ def test_install_status_includes_protocol_targets_from_health_probe(assert secret not in result.output+def test_install_status_treats_ready_proxy_as_running(monkeypatch) -> None:+ """Health wins when PID/container bookkeeping incorrectly says stopped.++ Regression for #3072 bug 2: status previously printed the contradictory+ pair ``Status: stopped`` and ``Healthy: yes`` while doctor correctly+ reported the same proxy as running.+ """+ manifest = _status_manifest("default")+ monkeypatch.setattr(inst, "load_manifest", lambda profile: manifest)+ monkeypatch.setattr(inst, "probe_json", lambda url: None)+ monkeypatch.setattr(inst, "probe_ready", lambda url: True)+ monkeypatch.setattr(inst, "runtime_status", lambda deployment: "stopped")++ result = CliRunner().invoke(main, ["install", "status"])++ assert result.exit_code == 0, result.output+ assert "Status: running" in result.output+ assert "Healthy: yes" in result.output+ assert "Status: stopped" not in result.output+++def test_install_status_keeps_runtime_status_when_not_ready(monkeypatch) -> None:+ """An unhealthy live process remains distinguishable from a stopped one."""+ manifest = _status_manifest("default")+ monkeypatch.setattr(inst, "load_manifest", lambda profile: manifest)+ monkeypatch.setattr(inst, "probe_json", lambda url: None)+ monkeypatch.setattr(inst, "probe_ready", lambda url: False)+ monkeypatch.setattr(inst, "runtime_status", lambda deployment: "running")++ result = CliRunner().invoke(main, ["install", "status"])++ assert result.exit_code == 0, result.output+ assert "Status: running" in result.output+ assert "Healthy: no" in result.output++@pytest.mark.parametrize("payload",[@@ -604,7 +640,7 @@ def test_install_status_probes_live_health_response(assert result.exit_code == 0, result.outputassert requests == ["/health", "/readyz"]- assert "Status: stopped" in result.output+ assert "Status: running" in result.outputassert "Healthy: yes" in result.outputassert "Default backend: anthropic" in result.outputassert f"Anthropic target: {anthropic_target}" in result.outputdiff --git a/tests/test_cli/test_wrap_persistent.py b/tests/test_cli/test_wrap_persistent.pyindex 7b36a8950..d471beb79 100644--- a/tests/test_cli/test_wrap_persistent.py+++ b/tests/test_cli/test_wrap_persistent.py@@ -1,11 +1,14 @@from __future__ import annotationsimport errno+from types import SimpleNamespaceimport clickimport pytestimport headroom.cli.wrap as wrap_cli+import headroom.install.health as install_health+import headroom.install.runtime as install_runtime@pytest.fixture(autouse=True)@@ -17,6 +20,13 @@ def _no_attached_wrappers(monkeypatch: pytest.MonkeyPatch) -> None:flaky. Individual tests override this to simulate attached wrappers."""monkeypatch.setattr(wrap_cli, "_live_proxy_clients", lambda *a, **kw: [])+ # These recovery tests control readiness through the health probe; process+ # identity and launchd ownership have their own runtime-level coverage.+ monkeypatch.setattr(+ install_runtime,+ "runtime_ready",+ lambda manifest: install_health.probe_ready(manifest.health_url),+ )for name in ("ANTHROPIC_TARGET_API_URL","OPENAI_TARGET_API_URL",@@ -35,9 +45,18 @@ class _Manifest:preset = "persistent-service"supervisor_kind = "service"health_url = "http://127.0.0.1:8787/readyz"+ runtime_kind = "python"+[email protected](params=["darwin", "linux", "win32"])+def runtime_platform(monkeypatch: pytest.MonkeyPatch, request) -> None:+ # Replace only this module's sys reference, never the process-wide object.+ monkeypatch.setattr(install_runtime, "sys", SimpleNamespace(platform=request.param))-def test_ensure_proxy_recovers_matching_persistent_deployment(monkeypatch) -> None:++def test_ensure_proxy_recovers_matching_persistent_deployment(+ monkeypatch, runtime_platform+) -> None:calls: list[str] = []monkeypatch.setattr(wrap_cli, "_check_proxy", lambda port: False)@@ -66,7 +85,9 @@ def test_ensure_proxy_recovers_matching_persistent_deployment(monkeypatch) -> Noassert calls == ["start:default"]-def test_ensure_proxy_recovers_persistent_deployment_when_socket_is_bound(monkeypatch) -> None:+def test_ensure_proxy_recovers_persistent_deployment_when_socket_is_bound(+ monkeypatch, runtime_platform+) -> None:calls: list[str] = []monkeypatch.setattr(wrap_cli, "_check_proxy", lambda port: True)@@ -303,14 +324,14 @@ def test_find_persistent_manifest_prefers_default_profile(monkeypatch) -> None:assert manifest.profile == "default"-def test_recover_persistent_proxy_reuses_healthy_deployment(monkeypatch) -> None:+def test_recover_persistent_proxy_reuses_healthy_deployment(monkeypatch, runtime_platform) -> None:monkeypatch.setattr(wrap_cli, "_find_persistent_manifest", lambda port: _Manifest())monkeypatch.setattr("headroom.install.health.probe_ready", lambda url: True)assert wrap_cli._recover_persistent_proxy(8787) is True-def test_recover_persistent_proxy_warns_for_task_deployment(monkeypatch) -> None:+def test_recover_persistent_proxy_warns_for_task_deployment(monkeypatch, runtime_platform) -> None:class TaskManifest(_Manifest):supervisor_kind = "task"