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): use safe model backends for persistent services (#3646)
lorenzozane7287589d23b7
diff --git a/headroom/install/planner.py b/headroom/install/planner.pyindex 518688abf..a545ffd01 100644--- a/headroom/install/planner.py+++ b/headroom/install/planner.py@@ -169,6 +169,10 @@ def build_manifest("HEADROOM_MODE": proxy_mode,"HEADROOM_BACKEND": backend,}+ if effective_preset == InstallPreset.PERSISTENT_SERVICE.value:+ # Keep native services away from Metal-specific model backends by default.+ base_env["HEADROOM_EMBEDDER_RUNTIME"] = "cpu"+ base_env["HEADROOM_KOMPRESS_BACKEND"] = "onnx"if anyllm_provider:base_env["HEADROOM_ANYLLM_PROVIDER"] = anyllm_providerif region:diff --git a/tests/test_install/test_planner.py b/tests/test_install/test_planner.pyindex 30ab8a070..d5169acee 100644--- a/tests/test_install/test_planner.py+++ b/tests/test_install/test_planner.py@@ -50,6 +50,8 @@ def test_build_manifest_for_persistent_docker_sets_expected_defaults() -> None:# exist inside the container and would keep /readyz at 503 (#2803). The proxy# resolves the DB under its own cwd, which is the bind-mounted ~/.headroom.assert "--memory-db-path" not in manifest.proxy_args+ assert "HEADROOM_EMBEDDER_RUNTIME" not in manifest.base_env+ assert "HEADROOM_KOMPRESS_BACKEND" not in manifest.base_envdef test_build_manifest_python_runtime_keeps_explicit_memory_db_path() -> None:@@ -97,6 +99,8 @@ def test_build_manifest_falls_back_from_windows_service_to_task(monkeypatch) ->assert manifest.preset == InstallPreset.PERSISTENT_TASK.valueassert manifest.supervisor_kind == "task"+ assert "HEADROOM_EMBEDDER_RUNTIME" not in manifest.base_env+ assert "HEADROOM_KOMPRESS_BACKEND" not in manifest.base_envdef test_build_manifest_uses_provider_slice_env_builders_for_all_supported_targets() -> None:@@ -365,3 +369,31 @@ def test_build_manifest_extra_env_wins_over_grok_xai_default() -> None:assert manifest.base_env["OPENAI_TARGET_API_URL"] == "https://gateway.example/v1"idx = manifest.proxy_args.index("--openai-api-url")assert manifest.proxy_args[idx + 1] == "https://gateway.example/v1"+++def test_build_manifest_for_persistent_service_uses_safe_model_backends() -> None:+ manifest = build_manifest(**_base_manifest_kwargs())++ assert manifest.base_env["HEADROOM_EMBEDDER_RUNTIME"] == "cpu"+ assert manifest.base_env["HEADROOM_KOMPRESS_BACKEND"] == "onnx"+++def test_persistent_service_explicit_model_backends_override_safe_defaults() -> None:+ manifest = build_manifest(+ **_base_manifest_kwargs(+ extra_env={+ "HEADROOM_EMBEDDER_RUNTIME": "pytorch_mps",+ "HEADROOM_KOMPRESS_BACKEND": "pytorch_mps",+ }+ )+ )++ assert manifest.base_env["HEADROOM_EMBEDDER_RUNTIME"] == "pytorch_mps"+ assert manifest.base_env["HEADROOM_KOMPRESS_BACKEND"] == "pytorch_mps"+++def test_persistent_task_does_not_inherit_service_backend_defaults() -> None:+ manifest = build_manifest(**_base_manifest_kwargs(preset=InstallPreset.PERSISTENT_TASK.value))++ assert "HEADROOM_EMBEDDER_RUNTIME" not in manifest.base_env+ assert "HEADROOM_KOMPRESS_BACKEND" not in manifest.base_envdiff --git a/wiki/persistent-installs.md b/wiki/persistent-installs.mdindex 3c2184d37..4a53098ac 100644--- a/wiki/persistent-installs.md+++ b/wiki/persistent-installs.md@@ -27,6 +27,15 @@ headroom install statusThis installs a background service on the current machine, applies persistent tool wiring, and keeps the proxy healthy on port `8787`.+Native `persistent-service` manifests explicitly default the memory embedder to+`cpu` and Kompress to `onnx`. This avoids selecting the Apple Silicon Metal+backends during supervised startup, where a native MPS abort cannot be handled+by Python. These are safe defaults only: explicit `--env+HEADROOM_EMBEDDER_RUNTIME=pytorch_mps` or+`--env HEADROOM_KOMPRESS_BACKEND=pytorch_mps` still opts into MPS and requires+the matching platform and optional dependencies. The two settings are+independent; the Kompress setting does not control memory embedding.+### Persistent watchdog task```bash