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): distinguish protocol targets in status (#4040)

Mansurshakh Japarov79f2c2781a1e
diff --git a/docs/content/docs/persistent-installs.mdx b/docs/content/docs/persistent-installs.mdx
index eedb49c8e..93866b71b 100644
--- a/docs/content/docs/persistent-installs.mdx
+++ b/docs/content/docs/persistent-installs.mdx
@@ -90,6 +90,8 @@ headroom install remove
`apply` creates or updates a named deployment profile, stores its manifest under `~/.headroom/deploy/<profile>/manifest.json`, applies reversible configuration changes, and starts the selected runtime.
+`status` distinguishes the default backend from the Anthropic and OpenAI protocol targets. When the health response includes a target's configuration, that target is shown as `configured` or `default`. If configuration is unavailable or omits a target, that target is shown as `unknown`; this does not mean it is unset. For example, a Docker bridge peer may not pass the loopback health-config gate. Target URLs and credentials are not printed. An OpenAI-compatible deployment can therefore have `Default backend: anthropic` and `OpenAI target: configured` at the same time.
+
## Presets and runtime kinds
### Presets
diff --git a/headroom/cli/install.py b/headroom/cli/install.py
index b25c53653..870b53c24 100644
--- a/headroom/cli/install.py
+++ b/headroom/cli/install.py
@@ -1178,9 +1178,23 @@ def install_status(profile: str) -> None:
# reach `.get('backend', ...)` and crash with AttributeError. Guard on
# isinstance, mirroring wrap.py's _proxy_health_config.
config = payload.get("config")
- if not isinstance(config, dict):
+ anthropic_target = openai_target = "unknown"
+ if isinstance(config, dict):
+ anthropic_url = config.get("anthropic_api_url")
+ if "anthropic_api_url" in config and (
+ anthropic_url is None or isinstance(anthropic_url, str)
+ ):
+ anthropic_target = "configured" if anthropic_url else "default"
+ openai_url = config.get("openai_api_url")
+ if "openai_api_url" in config and (openai_url is None or isinstance(openai_url, str)):
+ openai_target = "configured" if openai_url else "default"
+ else:
+ # Network health probes may intentionally omit credential-bearing
+ # config. Missing information does not mean a target is unset.
config = {}
- click.echo(f"Backend: {config.get('backend', manifest.backend)}")
+ click.echo(f"Default backend: {config.get('backend', manifest.backend)}")
+ click.echo(f"Anthropic target: {anthropic_target}")
+ click.echo(f"OpenAI target: {openai_target}")
@install.command("start")
diff --git a/tests/test_cli/test_install_cli.py b/tests/test_cli/test_install_cli.py
index 36cc7c475..2183d4058 100644
--- a/tests/test_cli/test_install_cli.py
+++ b/tests/test_cli/test_install_cli.py
@@ -1,7 +1,9 @@
from __future__ import annotations
import json
+from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
+from threading import Thread
from types import SimpleNamespace
import click
@@ -13,6 +15,7 @@ from headroom.cli.main import main
from headroom.install.models import DeploymentManifest, ManagedMutation
from headroom.install.planner import build_tool_envs
from headroom.install.state import load_manifest as load_state_manifest
+from headroom.install.state import save_manifest_strict
def test_require_manifest_resolves_single_profile_when_default_missing(monkeypatch):
@@ -449,67 +452,165 @@ def test_install_apply_explicit_env_overrides_captured(monkeypatch) -> None:
assert captured["extra_env"]["ANTHROPIC_TARGET_API_URL"] == "https://explicit.internal/v1"
-def test_install_status_includes_backend_from_health_probe(monkeypatch) -> None:
- runner = CliRunner()
-
- class Manifest:
- targets = ["claude"]
- tool_envs = {}
- profile = "default"
- preset = "persistent-service"
- runtime_kind = "python"
- supervisor_kind = "service"
- scope = "user"
- port = 8787
- backend = "anthropic"
- health_url = "http://127.0.0.1:8787/readyz"
-
- monkeypatch.setattr("headroom.cli.install.load_manifest", lambda profile: Manifest())
- monkeypatch.setattr(
- "headroom.cli.install.runtime_status",
- lambda manifest: "running",
- )
- monkeypatch.setattr("headroom.cli.install.probe_ready", lambda url: True)
+ ("anthropic_url", "openai_url", "anthropic_target", "openai_target"),
+ [
+ (None, None, "default", "default"),
+ ("", "", "default", "default"),
+ ("https://anthropic-user:[email protected]/v1", None, "configured", "default"),
+ (None, "https://openai-user:[email protected]/v1", "default", "configured"),
+ (
+ "https://anthropic-user:[email protected]/v1",
+ "https://openai-user:[email protected]/v1",
+ "configured",
+ "configured",
+ ),
+ ],
+)
+def test_install_status_includes_protocol_targets_from_health_probe(
+ monkeypatch, anthropic_url, openai_url, anthropic_target, openai_target
+) -> None:
+ monkeypatch.setattr(inst, "load_manifest", lambda profile: _status_manifest(profile))
+ monkeypatch.setattr(inst, "runtime_status", lambda manifest: "running")
+ monkeypatch.setattr(inst, "probe_ready", lambda url: True)
monkeypatch.setattr(
- "headroom.cli.install.probe_json",
- lambda url: {"config": {"backend": "anthropic"}},
+ inst,
+ "probe_json",
+ lambda url: {
+ "config": {
+ "backend": "openai",
+ "anthropic_api_url": anthropic_url,
+ "openai_api_url": openai_url,
+ }
+ },
)
- result = runner.invoke(main, ["install", "status"])
+ 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 "Backend: anthropic" in result.output
-
-
-def test_install_status_survives_non_dict_config(monkeypatch) -> None:
- """A health payload whose `config` is a non-dict (e.g. a different service
- answering on the port returns config: null) must not crash the command."""
- runner = CliRunner()
+ assert "Default backend: openai" in result.output
+ assert f"Anthropic target: {anthropic_target}" in result.output
+ assert f"OpenAI target: {openai_target}" in result.output
+ for secret in ("fake-secret", "anthropic-user", "openai-user", ".invalid"):
+ assert secret not in result.output
+
+
+ "payload",
+ [
+ {"status": "healthy"},
+ {"config": {}},
+ {"config": {"backend": "anthropic"}},
+ {"config": None},
+ {"config": "not-a-config"},
+ {"config": []},
+ {"config": 42},
+ {"config": {"anthropic_api_url": False, "openai_api_url": 0}},
+ {"config": {"anthropic_api_url": [], "openai_api_url": {}}},
+ {"config": {"anthropic_api_url": ["malformed"], "openai_api_url": {"url": "bad"}}},
+ ],
+)
+def test_install_status_survives_unavailable_config(monkeypatch, payload) -> None:
+ """Redacted or malformed config is unknown, not evidence of unset URLs."""
+ monkeypatch.setattr(inst, "load_manifest", lambda profile: _status_manifest(profile))
+ monkeypatch.setattr(inst, "runtime_status", lambda manifest: "running")
+ monkeypatch.setattr(inst, "probe_ready", lambda url: True)
+ monkeypatch.setattr(inst, "probe_json", lambda url: payload)
- class Manifest:
- targets = ["claude"]
- tool_envs = {}
- profile = "default"
- preset = "persistent-service"
- runtime_kind = "python"
- supervisor_kind = "service"
- scope = "user"
- port = 8787
- backend = "anthropic"
- health_url = "http://127.0.0.1:8787/readyz"
+ result = CliRunner().invoke(main, ["install", "status"])
- monkeypatch.setattr("headroom.cli.install.load_manifest", lambda profile: Manifest())
- monkeypatch.setattr("headroom.cli.install.runtime_status", lambda manifest: "running")
- monkeypatch.setattr("headroom.cli.install.probe_ready", lambda url: True)
- monkeypatch.setattr("headroom.cli.install.probe_json", lambda url: {"config": None})
+ assert result.exit_code == 0, result.output
+ assert "Default backend: anthropic" in result.output
+ assert "Anthropic target: unknown" in result.output
+ assert "OpenAI target: unknown" in result.output
+
+
+ ("payload", "anthropic_target", "openai_target"),
+ [
+ ({"status": "healthy", "ready": True}, "unknown", "unknown"),
+ ({"config": {}}, "unknown", "unknown"),
+ (
+ {"config": {"anthropic_api_url": None, "openai_api_url": None}},
+ "default",
+ "default",
+ ),
+ (
+ {"config": {"openai_api_url": "https://user:[email protected]/v1"}},
+ "unknown",
+ "configured",
+ ),
+ ({"config": {"anthropic_api_url": ""}}, "default", "unknown"),
+ ({"config": {"anthropic_api_url": False, "openai_api_url": None}}, "unknown", "default"),
+ ],
+)
+def test_install_status_probes_live_health_response(
+ tmp_path, monkeypatch, payload, anthropic_target, openai_target
+) -> None:
+ """Exercise manifest persistence, HTTP probes and CLI rendering together.
- result = runner.invoke(main, ["install", "status"])
+ The redacted response is the shape returned to an untrusted Docker bridge
+ peer. This fixture is an HTTP server, not a Docker networking test.
+ """
+ monkeypatch.setenv("HOME", str(tmp_path))
+ monkeypatch.setenv("HEADROOM_WORKSPACE_DIR", str(tmp_path / "workspace"))
+ monkeypatch.setenv("HEADROOM_CONFIG_DIR", str(tmp_path / "config"))
+ monkeypatch.delenv("HEADROOM_DEPLOYMENT_PROFILE", raising=False)
+ requests = []
+
+ class HealthHandler(BaseHTTPRequestHandler):
+ def do_GET(self):
+ requests.append(self.path)
+ body = json.dumps({"ready": True} if self.path == "/readyz" else payload).encode()
+ self.send_response(200)
+ self.send_header("Content-Type", "application/json")
+ self.send_header("Content-Length", str(len(body)))
+ self.end_headers()
+ self.wfile.write(body)
+
+ def log_message(self, format, *args):
+ pass
+
+ with ThreadingHTTPServer(("127.0.0.1", 0), HealthHandler) as server:
+ thread = Thread(target=server.serve_forever, daemon=True)
+ thread.start()
+ try:
+ port = server.server_address[1]
+ save_manifest_strict(
+ DeploymentManifest(
+ profile="status-proof",
+ preset="persistent-task",
+ runtime_kind="python",
+ supervisor_kind="none",
+ scope="user",
+ provider_mode="manual",
+ targets=[],
+ port=port,
+ host="127.0.0.1",
+ backend="anthropic",
+ health_url=f"http://127.0.0.1:{port}/readyz",
+ base_env={
+ "OPENAI_TARGET_API_URL": "https://stale:[email protected]/v1"
+ },
+ )
+ )
+
+ result = CliRunner().invoke(main, ["install", "status", "--profile", "status-proof"])
+ finally:
+ server.shutdown()
+ thread.join(timeout=5)
- # No AttributeError; Backend falls back to the manifest value.
assert result.exit_code == 0, result.output
- assert "Backend: anthropic" in result.output
+ assert requests == ["/health", "/readyz"]
+ assert "Status: stopped" in result.output
+ assert "Healthy: yes" in result.output
+ assert "Default backend: anthropic" in result.output
+ assert f"Anthropic target: {anthropic_target}" in result.output
+ assert f"OpenAI target: {openai_target}" in result.output
+ assert "fake-secret" not in result.output
+ assert ".invalid" not in result.output
def test_install_restart_uses_internal_helpers(monkeypatch) -> None: