Fix/bash path probe tty foreground #4098
Merged
esengine merged 2 commits intoJun 12, 2026
Merged
Conversation
Remove the local investigation note from the commit history so the PR only carries code changes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Owner
|
Thanks for the precise diagnosis and the captured |
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.
Bash PATH Probe Steals TTY Foreground
Summary
Reasonix TUI can be suspended by Unix job control after a login-shell PATH probe runs. The reproduced case came from the bash tool probe in
internal/tool/builtin/bash.go, and the same probe pattern also exists in stdio plugin executable resolution ininternal/plugin/transport_stdio.go: both can start an interactive login shell (zsh -l -i -c ...) in the same controlling-terminal session as the TUI. That shell can briefly become the terminal foreground process group and exit without returning foreground ownership to Reasonix.Once Reasonix is no longer the terminal foreground process group, the next TTY read triggers
SIGTTIN(stopped (tty input)), making the TUI appear to exit.This is a terminal/session ownership bug, not a failure of the tool command that happened to be running. In the captured repro, the foreground process group changed before Reasonix received
SIGTTIN; after the short-lived probe exited, the TTY still pointed at the probe's process group rather than Reasonix's process group.Reproduction Evidence
Local repro on macOS after clearing
~/Library/Caches/reasonix/job-control.logand rebuilding Reasonix:Process state while stuck:
tpgid=41980points to the short-lived PATH probe process group.ps -g 41980returned no processes after the probe exited, so the TTY foreground process group was left pointing at a dead group. Reasonix then attempted to read from the TTY while its own process group was41366, causingSIGTTIN.Root Cause
The failing call path is:
There is an equivalent stdio plugin resolution path:
The
-ilogin-shell probe is useful for matching the user's login PATH, but it must not run in the same controlling-terminal session as the Bubble Tea TUI.Why
SIGTTINHappensOn Unix, a terminal has one foreground process group. If a process outside that foreground process group reads from the terminal, the kernel sends
SIGTTINto stop it. The trace shows:pgrp=41366tpgid=41980/bin/zsh -l -i -c ...plus macOSpath_helpersignal stopped (tty input)The
ps -g 41980check returned no processes after the probe exited, which means the TTY foreground process group was left pointing at a dead group. That is why Reasonix could not safely resume normal TTY input.Fix
Detach only the PATH probe command through a shared helper:
SysProcAttr.Setsid = true.This covers both the bash tool probe and the stdio plugin probe while leaving normal bash tool process-group handling unchanged, so cancellation and process-tree cleanup continue to use the existing
Setpgid/ negative-pid kill behavior.Why This Scope Is Small
The change is limited to the short-lived login-shell PATH probes:
It does not change:
Setpgidand negative-pid kill);The helper exists in
internal/procso both PATH probes share the same terminal-session behavior and cannot drift again.Why
SetsidIs Appropriate HereThe PATH probe is non-interactive from Reasonix's perspective:
CombinedOutput;PATH.Running this helper in a new session prevents the helper shell's job-control setup from changing the TUI's controlling terminal foreground process group. Since the helper communicates only through pipes and exits immediately, it does not need the TUI's controlling terminal.
This is intentionally not applied to normal bash tool commands in this PR, because those commands already rely on their existing process-group behavior for cancellation and cleanup.
Review Checklist
proc.PrepareShellPATHProbe.proc.PrepareShellPATHProbe.SysProcAttr.Setsid = true.Setpgidcleanup for regular bash commands is unchanged.Verification
reference #3655