🤖 fix: pass muxEnv to background bash #1142
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes missing
MUX_MODEL_STRING/MUX_THINKING_LEVELin explicitly-backgrounded bash tool calls (run_in_background: true) by passingmuxEnvthrough toBackgroundProcessManager.spawn()(secrets still override).Adds a regression test that starts a background bash process and asserts it can read both env vars.
📋 Implementation Plan
🤖 fix: ensure MUX model + thinking env are set for GPT‑5.2 (esp. background bash)
What’s broken
When running commands via the bash tool in background mode (
run_in_background: true), the environment inside the spawned process does not include:MUX_MODEL_STRINGMUX_THINKING_LEVELThis shows up most often when using
openai:gpt-5.2because that model tends to trigger longer-running tool usage (builds/tests/dev servers) where backgrounding is common.Root cause (code-level)
We do compute the MUX env (including model + thinking) correctly:
src/node/runtime/initHook.ts:getMuxEnv()supports{ modelString, thinkingLevel }and will set:env.MUX_MODEL_STRING = options.modelStringenv.MUX_THINKING_LEVEL = options.thinkingLevelWe do pass it for AI tool calls:
src/node/services/aiService.tsbuilds tool config with:muxEnv: getMuxEnv(..., { modelString, thinkingLevel: thinkingLevel ?? "off" })But the bash tool’s explicit background path drops
muxEnv:src/node/services/tools/bash.ts(insidecreateBashTool,if (run_in_background) { ... })backgroundProcessManager.spawn(..., { env: config.secrets, ... })config.muxEnv, soMUX_*variables (including model/thinking) never reach the background process.Foreground execution does include it (
env: { ...config.muxEnv, ...config.secrets }), which is why this can look “model-specific” depending on tool usage patterns.Proposed fixes
Approach A (recommended): Fix background bash env injection (small + correct)
Net LoC (product code): ~10–20
src/node/services/tools/bash.tsbackground path to pass merged env:env: { ...(config.muxEnv ?? {}), ...(config.secrets ?? {}) }src/node/services/tools/bash.test.ts:describe("bash tool - background execution")asserting:config.muxEnv = { MUX_MODEL_STRING: "openai:gpt-5.2", MUX_THINKING_LEVEL: "medium" }echo "MODEL:$MUX_MODEL_STRING THINKING:$MUX_THINKING_LEVEL"BackgroundProcessManager.getOutput(processId, ..., timeout=2)config.secretsoverridesconfig.muxEnvfor the same key, matching existing foreground behavior.Why this is enough:
runtime.exec(... env: ...)and manually spawn a background process.Approach B (stretch): Also thread model/thinking into ORPC
workspace.executeBashNet LoC (product code): ~80–150
If the bug report is actually about UI-driven bash (ORPC) rather than AI tool calls, we currently don’t provide any
muxEnvthere.Implementation idea:
src/common/orpc/schemas/api.tsworkspace.executeBash.inputto accept optional:modelString?: stringthinkingLevel?: ThinkingLevelsrc/node/services/workspaceService.ts:executeBash()to pass:muxEnv: getMuxEnv(metadata.projectPath, getRuntimeType(metadata.runtimeConfig), metadata.name, { modelString, thinkingLevel })api.workspace.executeBash(...)to pass the current model/thinking if readily available.I’m not recommending this by default because it’s broader surface area and not necessary to fix the bash tool behavior for agents.
Validation plan
bun test src/node/services/tools/bash.test.ts -t "background"make typecheckmake testAcceptance criteria
echo $MUX_MODEL_STRINGandecho $MUX_THINKING_LEVELreturn non-empty values matching the active workspace session configuration (e.g.,openai:gpt-5.2,medium).Notes / risks
buildWrapperScript(export KEY='value'), so this is just fixing the missing inputs.Generated with
mux• Model:unknown• Thinking:unknown