fix(terminal): prefer $SHELL over bash for background process spawning (#42203) - #53110
Merged
Merged
Conversation
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-assignment |
1 |
unresolved-import |
1 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`
tests/tools/test_find_shell.py:14: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`
✅ Fixed issues (2):
| Rule | Count |
|---|---|
unresolved-attribute |
2 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
run_agent.py:3002: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
Unchanged: 6033 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
Contributor
Duplicate of #53106 — same author, same files ( |
#42203) On macOS, terminal(background=true) silently failed: the process returned a session_id and exit_code=0 but the command never ran (empty stdout, no side effects). Root cause is two interacting issues: 1. _find_shell was aliased to _find_bash, which prefers `shutil.which("bash")` → /bin/bash (GNU bash 3.2, still shipped on macOS) over $SHELL (/bin/zsh). 2. process_registry.spawn_local runs [shell, "-lic", "set +m; <cmd>"] with stdin=/dev/null. bash 3.2 as a login shell sources ~/.bash_profile, which on many macOS setups contains `exec /bin/zsh -l`; that exec replaces bash but drops the -c argument, so the command is swallowed (exit 0, no output). Decouple _find_shell from _find_bash: _find_shell now prefers the user's configured $SHELL on POSIX (the shell they actually log in with), falling back to _find_bash when $SHELL is unset/missing. _find_bash is unchanged, so callers that genuinely need bash (e.g. the _run_bash login-shell snapshot) keep bash semantics. zsh handles -lic correctly even with redirected stdin. Salvaged from #42219 by @liuhao1024 (authorship preserved via cherry-pick). On top of the original (8 unit tests covering $SHELL-set/unset/missing/empty, Windows-ignores-$SHELL, _find_bash-unchanged), added an E2E regression test that reproduces the real bash-3.2 login-shell swallow (exit 0 / no file) and asserts the shell _find_shell selects actually executes a -lic background command. Mutation-verified: reverting _find_shell to the bash alias fails the $SHELL-preference test. Bug reproduced directly: /bin/bash 3.2 -lic with a .bash_profile->exec-zsh creates no file; zsh -lic does. Closes #42203. Supersedes #42290.
kshitijk4poor
force-pushed
the
salvage/42203-find-shell-prefer-usershell
branch
from
June 26, 2026 15:15
2f4e9d1 to
d9f1f1a
Compare
18 tasks
waefrebeorn
pushed a commit
to waefrebeorn/slermes
that referenced
this pull request
Jul 2, 2026
…-find-shell-prefer-usershell fix(terminal): prefer $SHELL over bash for background process spawning (NousResearch#42203)
habarmc1223-sudo
pushed a commit
to habarmc1223-sudo/hermes-agent-fluxmem
that referenced
this pull request
Jul 8, 2026
…-find-shell-prefer-usershell fix(terminal): prefer $SHELL over bash for background process spawning (NousResearch#42203)
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
…-find-shell-prefer-usershell fix(terminal): prefer $SHELL over bash for background process spawning (NousResearch#42203)
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
…-find-shell-prefer-usershell fix(terminal): prefer $SHELL over bash for background process spawning (NousResearch#42203)
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
…-find-shell-prefer-usershell fix(terminal): prefer $SHELL over bash for background process spawning (NousResearch#42203)
melon-xf
added a commit
to melon-xf/hermes-agent
that referenced
this pull request
Sep 3, 2026
…-find-shell-prefer-usershell fix(terminal): prefer $SHELL over bash for background process spawning (NousResearch#42203)
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
On macOS,
terminal(background=true)silently failed — the process returned a session_id and exit_code=0, but the command never ran (empty stdout, no side effects). This fixes it by spawning background processes with the user's actual login shell.Root cause (#42203)
Two interacting issues:
_find_shellwas aliased to_find_bash, which prefersshutil.which("bash")→/bin/bash(GNU bash 3.2, still shipped on macOS) over$SHELL(/bin/zsh, the Catalina+ default).process_registry.spawn_localruns[shell, "-lic", "set +m; <cmd>"]withstdin=/dev/null. bash 3.2 as a login shell (-l) sources~/.bash_profile, which on many macOS setups containsexec /bin/zsh -l. Thatexecreplaces bash with zsh but drops the-cargument, so the command is silently swallowed (exit 0, no output, no side effects).Fix
Decouple
_find_shellfrom_find_bash:_find_shellnow prefers the user's configured$SHELLon POSIX (the shell they actually log in with), falling back to_find_bashwhen$SHELLis unset/missing.process_registryuses this for the user-facing background command._find_bashis unchanged — callers that genuinely need bash (e.g. the_run_bashlogin-shell environment snapshot) keep bash semantics.zsh handles
-liccorrectly even with redirected stdin, so the swallow no longer occurs.Validation
tests/tools/test_find_shell.py— 9 passed./bin/bash3.2 invoked-licwithstdin=/dev/nulland a~/.bash_profilecontainingexec /bin/zsh -l→ exit 0, file NOT created, empty stdout (the silent swallow);/bin/zsh -licwith the same HOME → file created.$SHELLset/unset/missing/empty, Windows-ignores-$SHELL, returns-string,_find_bash-unchanged) + an E2E regression test reproducing the real swallow and asserting the shell_find_shellselects actually executes a-licbackground command._find_shellto the= _find_bashalias fails the$SHELL-preference test.test_process_registry.py::test_close_stdin_allows_eof_driven_process_to_finishreproduces identically on cleanorigin/main— not caused by this change.)Salvaged from #42219 by @liuhao1024 (authorship preserved via cherry-pick; already in AUTHOR_MAP). Added the E2E regression test on top of the original.
Closes #42203. Supersedes #42290 (which changed
_find_bashitself — riskier, as bash-dependent callers like_run_bashwould then receive$SHELL/zsh).