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): don't let host env override the manifest in persistent-docker (#2090)

Abhay Singhb097ef3e2502
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 54e8479e1..b0b5bbd6b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -102,6 +102,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Bug Fixes
+* **install:** don't let a host env export override the manifest in persistent-docker deployments. `build_runtime_command` emitted the manifest's pinned `--env NAME=VALUE` pairs and then, for every host var matching a passthrough prefix, a bare `--env NAME`. Docker resolves duplicate `--env` last-wins, so a stale host export (e.g. `HEADROOM_BACKEND=anyllm`) that shared a passthrough prefix with a pinned manifest value (`HEADROOM_BACKEND=anthropic`) was appended after it and silently won, diverging the container from its deployment config. The bare passthrough is now skipped for any name the manifest already pins.
* **memory:** honor explicit `store=false` on OpenAI `/v1/responses` requests by skipping Headroom memory-tool injection that depends on stored-response continuations. Memory context injection stays available, and requests no longer get rewritten to `store=true` behind the client's back ([#1944](https://github.com/headroomlabs-ai/headroom/issues/1944)).
* **proxy/batch:** stop corrupting Google `batchGenerateContent` requests whose contents interleave text turns with text-less entries (functionCall/functionResponse/images). The batch handler restored preserved (non-text) entries with the raw-index loop that #836 replaced everywhere else — indexing the shorter `optimized_contents` (text-less entries produce no message) by the original `contents[]` index, which overwrites the wrong entry and drops any preserved entry whose original index is past the optimized length. A request like `[user text, model functionCall, user functionResponse, model text]` was forwarded to Google as two entries: the model's answer overwritten by the functionCall and the functionResponse dropped. The batch handler now uses the shared `_rebuild_gemini_contents` interleaving helper, so all entries survive in order.
* **proxy/gemini:** preserve Gemini code-execution parts (`executableCode` / `codeExecutionResult`) across the compression round-trip. `_has_non_text_parts` only recognized `inlineData`/`fileData`/`functionCall`/`functionResponse`, so a content entry carrying code-execution parts was not marked as preserved. A mixed `text`+`executableCode` entry lost its code payload (only the text survived), and a text-less code-execution entry was treated as a phantom that dropped the entire turn and shifted a neighboring message into the wrong role slot. Both keys are now recognized so those entries are preserved verbatim.
diff --git a/headroom/install/runtime.py b/headroom/install/runtime.py
index d6fd560a5..76535f47d 100644
--- a/headroom/install/runtime.py
+++ b/headroom/install/runtime.py
@@ -140,7 +140,13 @@ def build_runtime_command(manifest: DeploymentManifest) -> list[str]:
for name, value in runtime_env.items():
command.extend(["--env", f"{name}={value}"])
for name in sorted(os.environ):
- if name.startswith(PASSTHROUGH_ENV_PREFIXES):
+ # Skip any name the manifest already pinned above: Docker resolves
+ # duplicate `--env` last-wins, so a bare `--env HEADROOM_BACKEND`
+ # passthrough (which reads the host process env at
+ # `start_persistent_docker` time) would silently override the manifest's
+ # `--env HEADROOM_BACKEND=<value>`, diverging the container from its
+ # deployment config.
+ if name.startswith(PASSTHROUGH_ENV_PREFIXES) and name not in runtime_env:
command.extend(["--env", name])
# The image ENTRYPOINT already runs `headroom proxy` (see Dockerfile), so
# the args appended after the image name are only the proxy flags — never
diff --git a/tests/test_install/test_runtime.py b/tests/test_install/test_runtime.py
index f15cda93b..d28f38e6b 100644
--- a/tests/test_install/test_runtime.py
+++ b/tests/test_install/test_runtime.py
@@ -63,6 +63,47 @@ def test_build_runtime_command_for_docker_includes_deployment_env(
assert "HEADROOM_CONFIG_DIR=/tmp/headroom-home/.headroom/config" in command
+def test_build_runtime_command_docker_manifest_env_beats_host_passthrough(
+ monkeypatch, tmp_path: Path
+) -> None:
+ """A manifest value must win over a conflicting host export.
+
+ The manifest pins ``HEADROOM_BACKEND=anthropic``; the host process has a
+ stale ``HEADROOM_BACKEND=anyllm`` exported. Both start with the
+ ``HEADROOM_`` passthrough prefix, so without the dedupe the command emits
+ ``--env HEADROOM_BACKEND=anthropic`` and then a bare ``--env
+ HEADROOM_BACKEND``. Docker resolves duplicate ``--env`` last-wins, so the
+ bare passthrough reads the host value and silently overrides the manifest,
+ diverging the container from its deployment config.
+ """
+ monkeypatch.setattr(Path, "home", lambda: tmp_path)
+ monkeypatch.setenv("HEADROOM_BACKEND", "anyllm")
+ manifest = DeploymentManifest(
+ profile="default",
+ preset="persistent-docker",
+ runtime_kind="docker",
+ supervisor_kind="none",
+ scope="user",
+ provider_mode="manual",
+ targets=["claude"],
+ port=8787,
+ host="127.0.0.1",
+ backend="anthropic",
+ image="ghcr.io/chopratejas/headroom:latest",
+ base_env={"HEADROOM_PORT": "8787", "HEADROOM_BACKEND": "anthropic"},
+ proxy_args=["--host", "127.0.0.1", "--port", "8787"],
+ )
+
+ command = build_runtime_command(manifest)
+
+ # The manifest value is emitted...
+ assert "HEADROOM_BACKEND=anthropic" in command
+ # ...and no bare `--env HEADROOM_BACKEND` follows it to pull in the host
+ # value. `in` on the list matches the exact token, so the pinned
+ # `HEADROOM_BACKEND=anthropic` element does not count here.
+ assert "HEADROOM_BACKEND" not in command
+
+
def test_build_runtime_command_for_docker_matches_wrapper_parity(
monkeypatch, tmp_path: Path
) -> None: