fix: fire pane-died/pane-exited hooks with remain-on-exit#228
Merged
Conversation
When remain-on-exit is on, prune_exited() marks panes as dead but keeps them in the tree. The hook-firing logic only checked whether the tree leaf count decreased (any_pruned), which never happens in the remain-on-exit case since dead panes are still counted as leaves. Fix: prune_exited() now returns a newly_dead_count tracking panes that transitioned alive→dead in each call. reap_children() propagates this as a separate any_newly_dead flag alongside any_pruned. The server event loop fires pane-died/pane-exited hooks when either flag is true, but only resizes the layout when panes were actually removed. This matches tmux semantics: hooks fire when the child process exits, regardless of whether the pane is retained or removed. The dead flag on the pane prevents hooks from firing repeatedly on subsequent reap ticks — has_any_exited() skips already-dead panes. Fixes psmux#227 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
|
Hey @tarikguney, closing this since the same fix already landed via the second commit in #225 (80bb22e), which is now merged into master. The changes in |
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
pane-diedandpane-exitedhooks not firing whenremain-on-exitis enabledRoot cause
When
remain-on-exitis on,prune_exited()marks panes asdeadbut keeps them in the tree. The hook-firing logic only checked whether the tree leaf count decreased (leaves_after < leaves_before), which never happens in the remain-on-exit case since dead panes are still counted as leaves. So hooks never fired.What changed
src/tree.rs:prune_exited()now returns(Option<Node>, newly_dead_count)— the second value tracks panes that transitioned alive→dead in each callreap_children()returns(all_empty, any_pruned, any_newly_dead)— separating "pane removed from tree" from "pane became dead"src/server/mod.rs:any_pruned || any_newly_dead(either a pane was removed OR became dead)any_pruned(actual tree structure change)fire_hooks()helper instead of inline hook executionWhy hooks don't fire repeatedly
The
has_any_exited()fast-path check (line 688) returnsfalsefor already-dead panes (if p.dead { return false; }), so once a pane transitions to dead state and hooks fire, subsequent reap ticks skip it entirely.Fixes #227
Test plan
remain-on-exit on: start a pane with a short-lived process, setpane-diedhook — verify hook fires when process exitsremain-on-exit off: same test — verify existing behavior (hooks fire, pane is removed) still worksrespawn-paneafter death should reset the pane; if it dies again, hooks should fire again🤖 Generated with Claude Code