fix: detect parent death by ppid change instead of ppid==1#77
Merged
ErikBjare merged 1 commit intoFeb 27, 2026
Merged
Conversation
The previous check `os.getppid() == 1` assumed that PID 1 always means the parent died and the process was reparented to init. This fails when aw-watcher-afk is legitimately launched by a PID 1 process: - macOS: launchd (PID 1) as the launchd agent parent - Linux: systemd (PID 1) as the systemd user service parent The fix stores the initial parent PID at startup and checks if it changed, which correctly detects orphaned processes regardless of the init system or process manager. Fixes ActivityWatch#67
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to 7144da2 in 8 seconds. Click for details.
- Reviewed
31lines of code in1files - Skipped
0files when reviewing. - Skipped posting
0draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
Workflow ID: wflow_1d8ZUrez7mPBsvS8
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Greptile SummaryThis PR fixes a critical bug where Key Changes:
The fix correctly handles both legitimate PID 1 parents and actual orphaned processes, while also solving the PyInstaller bootloader compatibility issue mentioned in the old TODO. Confidence Score: 5/5
Important Files Changed
Last reviewed commit: 7144da2 |
This was referenced Feb 27, 2026
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
Fixes the false-positive "parent process died" exit when aw-watcher-afk is run via:
The previous check
os.getppid() == 1assumed PID 1 always means orphaned/reparented to init. This is wrong for modern process managers where PID 1 IS the expected parent.Fix: Store the initial parent PID at startup, then check if it changed — correctly detecting orphaned processes regardless of the init system.
Also improves the log message to show both old and new ppid for easier debugging.
Fixes #67
Test plan
Important
Fix false-positive parent death detection in
AFKWatcherby checkingppidchange instead ofppid == 1.AFKWatcherfromos.getppid() == 1toos.getppid() != self._initial_ppidinheartbeat_loop().ppidat startup inAFKWatcher.__init__()for comparison.ppidinheartbeat_loop().aw-watcher-afkruns correctly withlaunchdon macOS and as asystemduser service on Linux.This description was created by
for 7144da2. You can customize this summary. It will automatically update as commits are pushed.