fix(daemon): write PID and install signal handlers in foreground mode#554
Open
Maple-Aikon wants to merge 1 commit into
Open
fix(daemon): write PID and install signal handlers in foreground mode#554Maple-Aikon wants to merge 1 commit into
Maple-Aikon wants to merge 1 commit into
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.
Linked issue
Closes a daemon lifecycle bug found while dogfooding
crg-daemon start --foreground. No public issue number — happy to open one if maintainer prefers a tracked issue.What & why
crg-daemon start --foregroundleaks the PID file and ignores SIGTERM/SIGHUP. Cause:_handle_startshort-circuits todaemonize()whenis_daemon_running()is False. The non-daemonize (foreground) branch returns early without writing the PID file or installing signal handlers, so:crg-daemon stopfails with "PID file missing"crg watch/crg addworkflows that needcrg-daemonrunning in foreground become un-killableThe Windows branch of
daemonize()already doeswrite_pid() + self._setup_signal_handlers()— this PR applies the same pattern to the Linux/macOS foreground branch.Diff
def _handle_start(args: argparse.Namespace) -> None: """Start the daemon process.""" - from .daemon import WatchDaemon, is_daemon_running, load_config + from .daemon import WatchDaemon, is_daemon_running, load_config, write_pid if is_daemon_running(): print("Error: Daemon is already running.") if not args.foreground: daemon.daemonize() + else: + write_pid() + daemon._setup_signal_handlers() daemon.run_forever()uv.lockwas auto-updated by the cherry-pick (one transitive bump) — happy to drop it from the PR if maintainer prefers source-only diffs.How it was tested
Manual functional test (with isolated
HOME):Before the fix: SIGTERM was ignored and the process had to be killed with SIGKILL.
Checklist
uv run pytest tests/test_daemon.py --tb=short -q→ 51/51uvx ruff check code_review_graph/daemon_cli.py→ cleanuvx mypy code_review_graph/daemon_cli.py --ignore-missing-imports --no-strict-optional→ clean