fix(bash): address code-review findings on background shells - #237
Merged
Conversation
Post-merge review of #236: - HIGH: spawn_streaming_shell never disarmed its PgKillGuard, so on natural (and timeout) exit the guard's Drop fired a second killpg(SIGKILL) against an already-reaped, possibly OS-recycled process-group id. Now disarmed before finish() on every non-aborted completion path (matching run_with_timeout); the guard still fires on the abort/kill path, which is how kill_shell works. - MED-HIGH: background shells (own process group) leaked past normal exit — kill_all() only ran on session swap. Now also called when run_interactive returns (/quit, Ctrl+C/D, EOF) and at the headless session-end points. - MED: register() eviction at capacity dropped a still-running entry's JoinHandle (tokio detaches on drop → orphaned untracked process). Now evicts the oldest TERMINAL entry preferentially, and aborts the handle if a running entry must be evicted as a last resort. - MED: the arg schema description still described the reverted push-once model ('output delivered automatically, do NOT poll, killed at the timeout'). Rewritten to the poll-bash_output / unbounded / kill_shell model. - LOW: fixed a stale test doc-comment referencing the removed TaskKind::Shell; documented the Windows process-tree-kill limitation on spawn_streaming_shell. Tests: eviction aborts (not detaches) an evicted running shell; eviction prefers terminal entries. Full feature-matrix suite green at -D warnings (2166 passed).
allen-munsch
pushed a commit
to allen-munsch/dirge
that referenced
this pull request
Jun 3, 2026
…ls-review-followups fix(bash): address code-review findings on background shells
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.
Post-merge code review of #236 (background-shells rework) surfaced six findings; this fixes #1–#5 and documents #6.
spawn_streaming_shellnever disarmed itsPgKillGuard, so on natural (and timeout) exit the guard'sDropfired a secondkillpg(SIGKILL)against an already-reaped — possibly OS-recycled — process-group id (could kill an unrelated group). Now disarmed beforefinish()on every non-aborted completion path, matchingrun_with_timeout. The guard still fires on the abort path, which is exactly howkill_shell/kill_allkill the group.kill_all()only ran on session swap. Now also called whenrun_interactivereturns (/quit, Ctrl+C/D, EOF) and at the headless session-end points.register()eviction at capacity dropped a still-running entry'sJoinHandle(tokio detaches on drop → orphaned, untracked process). Now evicts the oldest terminal entry preferentially, and aborts the handle if a running entry must be evicted as a last resort.backgroundarg schema description still described the reverted push-once model ("output delivered automatically, do NOT poll, killed at the timeout") — which would stop the model from ever pollingbash_output. Rewritten to the poll / unbounded /kill_shellmodel.TaskKind::Shell.spawn_streaming_shell(Unix-onlyPgKillGuard; grandchildren best-effort on Windows).Verified-clean in review and left as-is: the abort→SIGKILL chain on unix, drain-EOF-while-process-alive, the cap TOCTOU (bash is
Sequential), global-store sharing,/taskslisting, and the status-bar call sites. The soft output-buffer cap and capturing trailing output after exit are intentional.Tests
-D warnings(2166 passed).