Repository navigation
Refuse to kill pid 0: it signals our own process group - #63
Merged
Merged
Conversation
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.
Problem
kill_processpasses itspidstraight tokill(1).kill 0does not mean "no process" — it signals every process in the caller's process group, which for the TUI is claudectl and the terminal that launched it. It then escalates tokill -9 0.Zero reaches it by an ordinary path, not a corrupt one:
ClaudeSession::from_registry_entrymaps an absent pid to0(entry.pid.unwrap_or(0)).~/.claude/sessions/<pid>.jsoninside the namespace eachsccreates withunshare --user --mount. The host cannot read it, andcollector_says_gonedeliberately treats a missing pid as "no evidence" so those rows keep rendering.handle_killreadssession.pidoff the selected row with no zero guard, bound tod.So every foreign sandbox row is two keystrokes from SIGTERM-then-SIGKILL on claudectl's own process group.
pid_alivealready guardspid != 0, but that is a different function on a different path.Found while restoring 19 live sandbox sessions to the registry after their slices were lost: all 19 rendered with pid 0, and the kill path was reachable on all of them.
Change
A
kill_targetguard at the lowest level, so no present or future caller can reachkill 0. The error says why and points at the actual remedy for a foreign session — close its terminal, since the host has no pid to signal.Tests
kill_targetis split out as a pure function specifically so it can be tested. Callingkill_process(0)in a test would signal the test runner's own process group, so a conventional RED-first run against the real function was not safe to perform; the pure guard is tested instead.pid_zero_is_refused_because_it_signals_our_own_process_groupa_real_pid_passes_throughcargo clippy --all-targets -- -D warningsclean.cargo test --lib727 passed; the 3 failures are pre-existing environment-bound perf tests (perf_do_refresh_io_does_not_explode_with_repeated_calls,perf_eviction_stays_linear_with_many_rows,perf_summarize_cached_costs_far_less_than_parsing) which fail on a host whose~/.claudeis a fuse mount holding thousands of transcripts, and pass on CI.Related
Companion to #62. Both are the same shape: a value that means "I could not measure this" being consumed as if it meant a real quantity — an empty reconcile read as "no sessions" there, a missing pid read as "process 0" here.