Repository navigation
fix: make stop no longer leaves orphaned sysmon processes running - #5
Merged
Merged
Conversation
…rphaned processes Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- Add PGREP helper (`pgrep -x -U $(id -u) sysmon`) as the single liveness source of truth, avoiding false matches on /usr/libexec/sysmond or other users' processes. - Rewrite `stop` to scan for live processes instead of trusting only the pidfile: kills every live PID, confirms termination with a bounded retry loop, and only removes the pidfile after a confirmed stop or when nothing was running. - Chain `clean: stop` so cleanup can never strand a running process. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… status - `start` now checks both the tracked pidfile PID and a fresh live scan before launching, refusing with a non-zero exit if a sysmon instance is already live (tracked or untracked) instead of silently orphaning it. - `status` reports four distinct states -- not running, stale pidfile, running+tracked (with an extra warning if untracked orphans coexist), and running+UNTRACKED -- always exiting 0. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Records that quick task 260826-pn8 supersedes the decision 'pidfile-based start/stop in Makefile retained as-is'. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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
make stopreported "sysmon is not running" while asysmonprocess kept running. Observed live: PID 70263, alive since Aug 19, 2:44 of accumulated CPU, with no/tmp/sysmon.pidpresent. It had to be killed by hand.stopandstatusderived liveness solely from$(PIDFILE). The pidfile desyncs from reality in two ways:make start— the second start overwrites the pidfile with its own PID, orphaning the first instance permanently.make clean— deleted the pidfile without killing anything.stopalso ranrm -f $(PIDFILE)unconditionally, even when no kill happened.Fix
Process liveness becomes the source of truth; the pidfile is demoted to a label that is trusted only when a live scan corroborates it.
Makefileis the only file changed.PGREPhelper —pgrep -x -U $(id -u) sysmon, the single liveness source forstart/stop/status.stop— kills by pidfile when valid, falls back to the live scan when the pidfile is missing or stale, confirms termination (10 polls × 0.2s), and removes the pidfile only after a confirmed stop. A failed kill exits non-zero and leaves the pidfile in place.start— refuses with a non-zero exit when any live instance exists, instead of spawning the next orphan.clean— declaresstopas a prerequisite, so it can never strand a running process.status— reports running-and-tracked, running-but-UNTRACKED, stale-pidfile, and not-running as distinct states, and warns when a tracked instance coexists with an orphan.Match precision (important)
The obvious
pkill -f sysmonwould have been dangerous: on macOS,pgrep -f sysmonmatches the system daemon/usr/libexec/sysmond(verified — PID 92862 on the dev machine). This PR uses-x(exact process name, so the trailingdexcludessysmond) and-U(current user only), and never uses-forpkill.Two related hardening points:
SIGTERMto an unrelated process, a worse bug than the one being fixed.stopkills every PID in the scan, not just the tracked one, so a tracked instance plus stray orphans are cleared in one pass.Verification
Full manual sequence run on macOS 26 / arm64, all passing:
make startmake statusrunning, tracked (PID 98220)make startmake stopstopping tracked PID→stoppedmake statusnot running, pidfile gonermpidfilerunning, UNTRACKED (PID(s) 98367)make stop← the original bugpidfile missing or stale -- stopping PID(s) found by live scan: 98367→stoppedmake status/pgrepnot running/ emptymake cleancleaned, nothing leftEdge cases also verified: stale pidfile with nothing running (cleared, exit 0); tracked instance coexisting with an orphan (
statuswarns,stopclears both);sysmondnever matched by the Makefile's scan.Note on project state
This supersedes the recorded decision in
.planning/STATE.md— "pidfile-based start/stop in Makefile retained as-is (not touched by this refactor)". The pidfile is retained, but it is no longer the sole liveness signal. STATE.md is updated accordingly.🤖 Generated with Claude Code