feat: reap orphaned agent processes on launch#102
Open
gi11es wants to merge 2 commits into
Open
Conversation
When Deckard dies abnormally, spawned claude/codex processes survive as orphans (they ignore the PTY hangup), and session restore then resumes the same sessions again — two live processes appending to one session file. Observed at 41-orphan scale after a single force-kill. Track direct (non-tmux) shell PIDs in a persistent registry keyed by kernel process start time (guards against PID reuse). On launch, before restore spawns replacements, kill recorded processes that are alive but reparented to launchd. Entries owned by another live instance are left alone; tmux sessions remain persistent by design. Fixes #100 Co-Authored-By: Claude Fable 5 <[email protected]>
- terminate()/detach() no longer remove registry entries: they only express kill intent, and agents observably survive SIGTERM — eager removal made such survivors permanently unreapable. Entries are removed on confirmed exit (processTerminated) or reaped next launch. - per-instance registry files (spawned-pids-<pid>.json) stamped with the owner's pid + start time replace the shared last-writer-wins file, so concurrent instances (Debug build + installed app) cannot lose each other's records; reap skips files whose owner is alive and processes/deletes files of dead instances (legacy ownerless format still consumed; undecodable files left untouched) - decide() hard-guards pid > 0 (kill(0)/kill(-1) target process groups) - kill() failures are logged and the entry retained for a later attempt - versioned file format; kept entries are written back, verified by test Co-Authored-By: Claude Fable 5 <[email protected]>
Owner
Author
|
Subagent review follow-up (pushed): (1) |
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.
Fixes #100.
When Deckard dies abnormally, spawned
claude/codexprocesses survive as orphans (they ignore the PTY hangup), and session restore then resumes the same sessions again — two live processes appending to one session jsonl. Observed at 41-orphan scale after a single force-kill.Approach
SpawnedProcessRegistry: persists direct-spawn (non-tmux) shell PIDs tospawned-pids.jsonwith the kernel process start time (viasysctl) to guard against PID reuse.TerminalSurfacerecords on spawn and removes onterminate()/detach()/processTerminated.AppDelegatecallsreapOrphans()at startup before the window controller spawns restores: recorded PIDs that are alive, start-time-matched, and reparented to launchd (ppid == 1) are killed. Entries still parented (e.g. a second live Deckard instance) are kept untouched. tmux sessions remain persistent by design.🤖 Generated with Claude Code