fix(run_shell): inherit parent environment in spawned shell#196
Open
qu0b wants to merge 1 commit into
Open
Conversation
Without this, exec.Cmd.Env is nil-initialized and the child process receives no environment — HOME, PATH, USER, SHELL are all unset. Scripts that rely on user-installed binaries (e.g. uv via pip install --user) or shell detection (e.g. foundryup checking $SHELL) fail with exit 127 or exit 1. User-supplied envVars in the task config still override inherited values via append order.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
command.Env = append(command.Env, os.Environ()...)before the user-suppliedenvVarsinpkg/tasks/run_shell/task.goexec.Cmd.Envis set to a non-nil slice, Go does not inherit the parent environment —HOME,PATH,USER,SHELLare all unset in the child processenvVarsfrom the task config are still appended after, so they continue to override inherited valuesWhy this matters
Without this fix, two common patterns silently break:
pip install --usertools (e.g.uv) install to$HOME/.local/bin. With$HOMEunset,~/.profilenever adds that directory toPATH, so the binary is not found (exit 127)foundryupreads$SHELLto decide which profile to update. With$SHELLunset it exits 1Both were worked around in playbooks with
sudo pip installandexport SHELL=/bin/bash, but fixing it at the task level is cleaner.Test plan
run_shelltask withpip install --user somepackage && somepackage --versionsucceeds withoutexport PATHworkaroundrun_shelltask runningfoundryupsucceeds withoutexport SHELL=/bin/bashprefix