fix: prefer foreground process during session resurrection - #1
Draft
bearmug wants to merge 3 commits into
Draft
Conversation
When a parent process has multiple children (e.g. `claude --resume` spawning MCP servers), `get_all_cmds_by_ppid` would store only the last child from `ps` output due to HashMap::insert overwriting. This caused session resurrection to capture a subprocess command instead of the user's actual foreground command. Fix by: - Adding the STAT column to ps output (`ps -ao ppid,stat,args`) - Collecting all children per parent PID - Preferring the foreground process (STAT contains '+') - Falling back to the first child when no foreground process exists The non-unix (Windows) path receives the same fix for the overwrite bug, using first-child as the heuristic since sysinfo does not expose foreground process group information. The return type and trait signature are unchanged, so all consumers (populate_session_layout_metadata, get_pane_running_command) work without modification. Relates to zellij-org#2925, zellij-org#4129
bearmug
force-pushed
the
fix/resurrect-prefer-foreground-process
branch
from
March 19, 2026 22:36
7813751 to
020d2b6
Compare
- Negate empty if-branch in update_terminal_commands (match existing is_dirty pattern at line 124) - Avoid unnecessary .clone() in select_best_candidates by using position() + into_iter().nth() to move instead of copy
The sticky command change (not clearing `run` when the default shell is detected) caused a regression. The os_input_output fix alone addresses the root cause — this clearing behavior is needed for panes that legitimately return to the shell.
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
get_all_cmds_by_ppidsilently overwriting when a parent PID has multiple children, causing session resurrection to capture a subprocess command instead of the user's foreground commandps -ao ppid,stat,args(adding STAT column) to prefer the foreground process (marked with+) over background childrenProblem
When tools like
claude --resumerun in a Zellij pane, they spawn child processes (MCP servers, LSP servers, etc.). The previous code usedHashMap::insertin a loop overpsoutput, so whichever child appeared last would silently overwrite earlier entries sharing the same parent PID. On resurrection, Zellij would then run the wrong command (e.g.node /path/to/mcp-serverinstead ofclaude --resume my-session).Relates to zellij-org#2925, zellij-org#4129
Approach
The STAT column from
pscontains+for processes in the foreground process group. By collecting all children per parent PID and preferring the one marked as foreground, we reliably capture the command the user actually launched.post_command_discovery_hookcontinues to work per-process; empty hook output now excludes that process from candidatesTest plan
zellij action dump-sessioncaptures the correct command