Skip to content

The agent that grows with you

fix(child-env): keep the scrub authoritative for the compute host and LSP servers

Andrex Ibiza, MBA75a97dfcfe0e
diff --git a/agent/lsp/client.py b/agent/lsp/client.py
index 17b48672322..4a31d12612f 100644
--- a/agent/lsp/client.py
+++ b/agent/lsp/client.py
@@ -248,6 +248,7 @@ class LSPClient:
async def _spawn(self) -> None:
from agent.delegation_context import delegated_child_subprocess_env
+ from tools.environments.local import hermes_subprocess_env
cmd = self._command
if sys.platform == "win32" and cmd[0].lower().endswith((".cmd", ".bat")):
cmd = ["cmd.exe", "/c", *cmd] # CreateProcess can't run .cmd/.bat shims directly
@@ -256,10 +257,12 @@ class LSPClient:
# the gateway's pgid and mcp_tool's orphan sweeper can killpg() the TUI parent with it.
# windows_hide_flags() suppresses the console window a .cmd shim would flash from a
# console-less host (CREATE_NO_WINDOW; 0 on POSIX).
+ # Language servers are third-party binaries a write_file can start: they get the
+ # scrubbed env (no gateway tokens, no provider keys), plus their own configured env.
self._proc = await asyncio.create_subprocess_exec(
cmd[0], *cmd[1:], limit=_STREAM_LIMIT,
stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
- env=delegated_child_subprocess_env({**os.environ, **(self._env or {})}), cwd=self._cwd,
+ env=delegated_child_subprocess_env({**hermes_subprocess_env(), **(self._env or {})}), cwd=self._cwd,
start_new_session=True, creationflags=windows_hide_flags(),
)
except FileNotFoundError as e:
diff --git a/tui_gateway/host_supervisor.py b/tui_gateway/host_supervisor.py
index a3077af3e38..7b1958427ef 100644
--- a/tui_gateway/host_supervisor.py
+++ b/tui_gateway/host_supervisor.py
@@ -327,7 +327,8 @@ class HostSupervisor:
raise RuntimeError("compute host respawn disabled after crash loop")
self._hello_event.clear()
self._hello = {}
- env = {**hermes_subprocess_env(inherit_credentials=True), **os.environ, **(self.env or {})}
+ # No os.environ layer on top: it would restore every Tier-1 secret the scrub just removed.
+ env = {**hermes_subprocess_env(inherit_credentials=True), **(self.env or {})}
env["HERMES_COMPUTE_HOST_HEARTBEAT_SECS"] = str(self.heartbeat_secs)
root = str(_repo_root())
env.setdefault("PYTHONPATH", root)