Fix stopping disabled KeepAlive service - #1252
Conversation
|
Correctness/reliability concern — PID capture → signal has a TOCTOU window In
Between steps 1 and 3 there's a window where the captured PID could become stale (process exits on its own, e.g. crash) and get reused by an unrelated process — macOS PID reuse is rare but not impossible, especially if Suggest re-validating that Minor: the lifecycle lint test ( No other issues found in the plist/version bumps or docs update — they're consistent with the code change. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e23327c9dc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "Failed to identify the KeyPath Kanata service process" | ||
| ) | ||
| } | ||
| let result = Self.run("/bin/kill", ["-TERM", processID], timeout: 15) |
There was a problem hiding this comment.
Revalidate the PID after disabling the job
If Kanata exits or restarts between the initial launchctl print and the disable operation, processID identifies the previous process rather than the current service instance. The raw root-level kill can then either return ESRCH while a replacement remains alive—causing stop to re-enable the job and fail—or, after PID reuse, signal an unrelated process. Re-read and validate the job's current PID after disabling it, or use another service-owned mechanism that preserves process identity, before signaling.
Useful? React with 👍 / 👎.
Summary
Why
Installed release acceptance showed that
launchctl disablesucceeds but makeslaunchctl kill system/com.keypath.kanataunable to resolve the still-running process. The CLI therefore reported failure and TCP stayed up.Tests
TEST_FILTER=HelperServiceKeepAliveLifecycleLintTests TIMEOUT_SECONDS=600 ./Scripts/run-tests-safe.shTEST_FILTER=HelperVersionContractTests KEYPATH_TEST_PREBUILD=0 TIMEOUT_SECONDS=180 ./Scripts/run-tests-safe.sh./Scripts/build-helper.shgit diff --checkRelease gate
This PR is required before publishing KeyPath 1.0.1. Publication remains paused until the merged build is notarized and the installed CLI proves stop/TCP-down/start/TCP-up.