Repository navigation
Fix: Report a stopped Cortex as stopped on macOS, and make stop wait until it is down - #2031
Conversation
…until it is down On macOS, status said "Cortex is NOT answering ... will fail", exit 1, after a deliberate `service stop`, exactly as after a crash: it never asked launchd why nothing answered. It now does, as it asks systemd on Linux (#1529), and names the case: - stopped and disabled, as `service stop` leaves it: "Cortex is stopped, and stays stopped ...", exit 0; - booted out but not disabled, which the next login undoes; - loaded but not running, as launchd leaves a job while it holds starts back for a while after login, with how to start it now; - no desktop session, as over SSH to a Mac nobody is logged in to: Cortex runs only in one, and an SSH login does not start it. `service stop` and uninstall also returned as soon as `launchctl bootout` did, which is before teardown finishes, so they said "stopped" while the supervisor was still taking the proxy down and holding its ports. Both now wait for the label to leave the domain, as systemd's `disable --now` waits, and only after a bootout that found a job. TestServiceLifecycle_RealLaunchd now asserts the stopped wording. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Alan Cha <Alan.cha1@ibm.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 10 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
clawgenti
left a comment
There was a problem hiding this comment.
Summary
This fixes what it says it fixes. On macOS, status now asks launchd why the health probe got no answer, and a service stop reads as stopped with exit 0, as it already does on Linux. service stop and uninstall now wait for the label to leave the domain before they return. Each case in reportJobNotAnswering matches what launchdJobState can produce. The wait runs only after a bootout that found a job, so the "No such process" path stays instant. The undo in setup and the uninstall reporting both handle the new timeout error correctly: the undo still checks serviceLoaded before it returns the error. No must-fix issues. Two small comments are inline, both about the no-desktop-session message.
Verified locally (Linux, Go 1.27.3): go vet is clean for GOOS=linux and GOOS=darwin, and gofmt -l is clean. The new tests (TestReportJobNotAnswering*, TestStopAndUnloadWaitForTheBootout) pass, and so do the existing stop, unload, characterize and undo tests. The full cmd/agentop run had one failure, TestServiceInstall_RefusesABrokenConfig. It fails the same way on main, because this sandbox has no systemd user bus, so it is environmental and not caused by this PR. I couldn't fetch the macOS job log because the log host timed out, so I didn't confirm from the log that TestServiceLifecycle_RealLaunchd ran. The job is green, has no failure annotations, and runs with AGENTOP_LAUNCHD_TESTS=required, so a skip there would have failed it.
Author: Alan-Cha (MEMBER — maintainer)
Areas reviewed: Go (cmd/agentop service status/stop/unload, launchd state probe, tests), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (all checks green, including the macOS job that runs cmd/agentop with AGENTOP_LAUNCHD_TESTS=required)
One conflict, in TestServiceStatus_NotAnsweringNamesTheAgentsThatFail: main added readyOnFirstAnswer(t), this branch pins jobStateOf beside unitStateOf. Both kept. One break the merge did not report: main's Windows build (#1520) dropped the syscall import from cmd_service_platform.go, where this branch reads /dev/console's owner from a syscall.Stat_t. That read is now fileOwner, with a Unix half in proc_unix.go and a Windows half in proc_windows.go, as main does for its other process and file primitives. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Alan Cha <alan-cha@wecm-9-67-182-240.wecm.ibm.com>
clawgenti
left a comment
There was a problem hiding this comment.
Summary
The launchd half of status now matches what #1529 did for systemd: a service stop reads as a stop (exit 0), and a booted-out-but-enabled job, a loaded-but-held-back job and an absent desktop session each get their own wording. The stop wait is gated on a bootout that found a job, so TestUnloadService_Darwin's "No such process" path is unaffected. I found no blocking issues. There is one suggestion about the service uninstall timeout path and two wording nits.
Verified locally at 68d312d: go vet is clean for linux, darwin and windows (the merge's fileOwner split builds on Windows), and the new and adjacent tests pass on Linux (TestReportJobNotAnswering*, TestStopAndUnloadWaitForTheBootout, TestUnloadService_*, TestCharacterize_*, TestServiceStatus_NotAnsweringNamesTheAgentsThatFail). On macOS CI, Build and test cmd/agentop runs with AGENTOP_LAUNCHD_TESTS: required and plain go test -race ./..., so the green job means TestServiceLifecycle_RealLaunchd ran and passed its new Cortex is stopped, and stays stopped / exit 0 assertion. I couldn't download the raw job log from here, but the job has no annotations beyond the runner-capacity notice.
Author: Alan-Cha (MEMBER, maintainer)
Areas reviewed: Go (cmd/agentop service status/stop/unload, proc_unix/proc_windows), tests, docs
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: passing (all checks green, including Go CI core peerproc macOS and Windows build)
Status's no-desktop-session message said "nobody is logged in", which is wrong when someone else is at the screen, and "it starts at the next login", which is wrong after `agentop service stop`: stop disables the job, and without the session status cannot ask whether it did. It now says "you are not logged in" and that it starts at the next login unless `agentop service stop` stopped it. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Alan Cha <alan-cha@wecm-9-67-182-240.wecm.ibm.com>
`agentop service uninstall` printed the "still shutting down" error and then "Removed. Cortex is stopped" with exit 0: removeService returns false only for a unit-file failure. unloadService's timeout now wraps errStillShuttingDown, and service uninstall, seeing it, says Cortex was still shutting down and exits 1. The plist is removed either way. The docs credited `agentop uninstall` with the new wait, which it already had; the command that newly waits is `service uninstall`. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Alan Cha <alan-cha@wecm-9-67-182-240.wecm.ibm.com>
clawgenti
left a comment
There was a problem hiding this comment.
Summary
6da7eef fixes the uninstall timeout contradiction from my last review. unloadService now wraps errStillShuttingDown with %w. removeServiceStopped checks for it with errors.Is, and service uninstall says Cortex "may still be running" and exits 1 instead of printing "Cortex is stopped". The plist is still removed. The other two callers of unloadService still behave correctly. agentop uninstall sees the job still loaded and reports stillLoaded. The setup undo returns the error while serviceLoaded. The docs now name service stop and service uninstall. I found no blocking issues. My two nits are both doc comments that this commit left attached to the wrong declaration.
Verified locally at 6da7eef (Linux, Go 1.26.10): go vet is clean for linux, darwin and windows, and gofmt -l is clean. These tests pass: TestReportJobNotAnswering*, TestStopAndUnloadWaitForTheBootout, TestServiceUninstall*, TestUnloadService_*, TestCharacterize_*, TestServiceStatus* and TestReportUnitNotAnswering*. With a scratch test against the stubbed launchctl, I checked that unloadService("darwin", ...) returns an error for which errors.Is(err, errStillShuttingDown) holds, with the message text unchanged. I also fed launchdJobState a print with a nested endpoint state = and a modern print-disabled listing. It read state = spawn scheduled from the job and not from the endpoint, and it read disabled: true. CI is all green. Go CI (core peerproc, macOS) runs plain go test -race ./... with AGENTOP_LAUNCHD_TESTS: required and no continue-on-error. So the real-launchd lifecycle test's new Cortex is stopped, and stays stopped / exit 0 assertion ran and passed, and so did the darwin-only TestServiceUninstallSaysStoppedOnlyOnceItIs. I couldn't download the raw job log because the log host timed out. The job's only annotation is the runner-capacity notice.
Author: Alan-Cha (MEMBER, maintainer)
Areas reviewed: Go (cmd/agentop service status/stop/uninstall, launchd state, proc_unix/proc_windows), tests, docs
Agent/IDE config (.claude/.vscode): none
Commits: 4 commits, all signed-off: yes
CI status: passing
| disabled bool | ||
| } | ||
|
|
||
| // launchdJobState asks launchd for Cortex's job. Not known when launchctl is missing |
There was a problem hiding this comment.
nit: errStillShuttingDown went in between launchdJobState's doc comment and the function. So the "launchdJobState asks launchd for Cortex's job..." paragraph now joins the sentinel's comment as one block on the var, and launchdJobState has no doc comment. Moving the var (with its own comment) above line 834, or next to unloadService, puts both back where they belong.
| return n | ||
| } | ||
|
|
||
| // stop and unload return only once launchd has the label out of the domain. A |
There was a problem hiding this comment.
nit: The same thing happened here. The new test went in between TestStopAndUnloadWaitForTheBootout's doc comment ("stop and unload return only once launchd has the label out of the domain...") and that function. That paragraph now heads TestServiceUninstallSaysStoppedOnlyOnceItIs, and TestStopAndUnloadWaitForTheBootout at line 205 has none. Moving these four lines down to sit above it fixes that.
Follow-up to #1780 and #1529.
Status after a stop
On macOS,
agentop service statusafter a deliberateservice stopsaid "Cortex is NOT answering … Claude Code and OpenCode will fail", exit 1, the same as after a crash. It never asked launchd why nothing answered. Linux has asked systemd since #1529. Now macOS asks launchd and names the case:service stopleaves)Cortex is stopped, and stays stopped across logins and reboots until you start it.launchctl bootoutby hand)Cortex is stopped, but not disabled, so it starts again at the next login.launchd has its job loaded but not running (state = …), plusagentop service restartgui/<uid>domain, and the console belongs to someone elsenobody is logged in to this Mac's desktop … An SSH login does not start it.Cortex is NOT answering, unchangedThe third row is what launchd leaves a job in while it holds starts back. On every login I tested (macOS 26.5.2, 26.6.1, 26.6.2), launchd logs "pending spawn, domain in on-demand-only mode" for the first ~10–40 s. It also leaves the job there between restarts (
ThrottleInterval). The fourth row is what status over SSH sees on a Mac sitting at its login screen: a launch agent runs only in a desktop session. The console's owner tells that apart from a sandbox that can't see the domain, so a sandbox still gets the unchanged message.service stopand uninstall waitBoth returned as soon as
launchctl bootoutdid, which is before teardown finishes (waitBootedOut's doc). So they said "stopped" while the supervisor was still taking the proxy down, which takes up tosuperviseStopGrace, and still holding its ports. Now both wait for the label to leave the domain, as systemd'sdisable --nowwaits. They wait only after a bootout that found a job: "No such process" is nothing to wait for, andTestUnloadService_Darwinrelies on that. If the teardown doesn't finish inserviceBootoutTimeout, they say so and point atservice status. clawgenti suggested this on #1780.Tests
TestReportJobNotAnswering: every state above, with the wording each must and mustn't use.TestReportJobNotAnsweringNamesTheHolder: the loaded-not-running case names a foreign port holder before the consequence, as Linux does (The supervisor loops forever when another install holds the pinned ports, and never says so #1122). A stopped Cortex names none.TestServiceStatusAsksLaunchdOnlyWhenSilent: launchd is asked once, only when the probe failed.TestStopAndUnloadWaitForTheBootout: a stubbedlaunchctlkeeps the label in the domain for three prints after bootout. Stop and unload return only after the fourth, and say "still shutting down" when it never goes. Mutation-checked: with the waits removed, all four cases fail.TestServiceLifecycle_RealLaunchd(strict on the macOS CI job) now assertsCortex is stopped, and stays stopped, exit 0, after the real stop.fakeSupervisor'slaunchctlstub answersprint-disabled.TestServiceStatus_NotAnsweringNamesTheAgentsThatFailpins launchd's state as it already pinned systemd's.go vet(darwin and linux) andgofmtare clean.scripts/dev/go-test-shards.sh -race cmd/agentoppasses (1182 tests), and so do the subpackages.Not run on a VM this time: my VMs can't be reached while this Mac's VPN is connected. The lifecycle test runs on GitHub's macOS runner in this PR's CI, in strict mode.
Assisted-By: Claude (Anthropic AI) noreply@anthropic.com