From c50e5fcc112aab3a2dd8f78b568a46062c5c108d Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Sun, 14 Dec 2025 09:19:13 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20fix:=20pass=20muxEnv=20to=20back?= =?UTF-8?q?ground=20bash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure run_in_background bash processes receive MUX_MODEL_STRING and MUX_THINKING_LEVEL by merging muxEnv with secrets (matching foreground behavior). Adds a regression test covering gpt-5.2. Signed-off-by: Thomas Kosiewski --- _Generated with `mux` • Model: `unknown` • Thinking: `unknown`_ Change-Id: I041d1884f7b0caa4f804fd10b81e5d81522fc1e2 --- src/node/services/tools/bash.test.ts | 43 ++++++++++++++++++++++++++++ src/node/services/tools/bash.ts | 3 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/node/services/tools/bash.test.ts b/src/node/services/tools/bash.test.ts index 8511d28199..0bef787429 100644 --- a/src/node/services/tools/bash.test.ts +++ b/src/node/services/tools/bash.test.ts @@ -1519,6 +1519,7 @@ describe("bash tool - background execution", () => { expect(result.success).toBe(true); if (result.success && "backgroundProcessId" in result) { expect(result.backgroundProcessId).toBeDefined(); + // Process ID is now the display name directly expect(result.backgroundProcessId).toBe("test"); } else { @@ -1527,4 +1528,46 @@ describe("bash tool - background execution", () => { tempDir[Symbol.dispose](); }); + + it("should inject muxEnv environment variables in background mode", async () => { + const manager = new BackgroundProcessManager("/tmp/mux-test-bg"); + + const tempDir = new TestTempDir("test-bash-bg-mux-env"); + const config = createTestToolConfig(tempDir.path); + config.backgroundProcessManager = manager; + config.muxEnv = { + MUX_MODEL_STRING: "openai:gpt-5.2", + MUX_THINKING_LEVEL: "medium", + }; + + const tool = createBashTool(config); + const args: BashToolArgs = { + script: 'echo "MODEL:$MUX_MODEL_STRING THINKING:$MUX_THINKING_LEVEL"', + timeout_secs: 5, + run_in_background: true, + display_name: "test-mux-env-bg", + }; + + const result = (await tool.execute!(args, mockToolCallOptions)) as BashToolResult; + + expect(result.success).toBe(true); + if (result.success && "backgroundProcessId" in result) { + const outputResult = await manager.getOutput( + result.backgroundProcessId, + undefined, + undefined, + 2 + ); + expect(outputResult.success).toBe(true); + if (outputResult.success) { + expect(outputResult.output).toContain("MODEL:openai:gpt-5.2"); + expect(outputResult.output).toContain("THINKING:medium"); + } + } else { + throw new Error("Expected background process ID in result"); + } + + await manager.terminateAll(); + tempDir[Symbol.dispose](); + }); }); diff --git a/src/node/services/tools/bash.ts b/src/node/services/tools/bash.ts index 6b7038d1c6..f72f0fddc1 100644 --- a/src/node/services/tools/bash.ts +++ b/src/node/services/tools/bash.ts @@ -257,7 +257,8 @@ export const createBashTool: ToolFactory = (config: ToolConfiguration) => { script, { cwd: config.cwd, - env: config.secrets, + // Match foreground bash behavior: muxEnv is present and secrets override it. + env: { ...(config.muxEnv ?? {}), ...(config.secrets ?? {}) }, niceness: config.niceness, displayName: display_name, isForeground: false, // Explicit background