Skip to content

Fix: Report a stopped Cortex as stopped on macOS, and make stop wait until it is down - #2031

Merged
Alan-Cha merged 4 commits into
mainfrom
macos-stop-status
Nov 23, 2026
Merged

Alan-Cha merged 4 commits into
mainfrom
macos-stop-status

Conversation

@Alan-Cha

Copy link
Copy Markdown
Member

Follow-up to #1780 and #1529.

Status after a stop

On macOS, agentop service status after a deliberate service stop said "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:

launchd reports Status says Exit
Label not loaded, and disabled (what service stop leaves) Cortex is stopped, and stays stopped across logins and reboots until you start it. 0
Not loaded, not disabled (launchctl bootout by hand) Cortex is stopped, but not disabled, so it starts again at the next login. 1
Loaded, not running launchd has its job loaded but not running (state = …), plus agentop service restart 1
No gui/<uid> domain, and the console belongs to someone else nobody is logged in to this Mac's desktop … An SSH login does not start it. 1
Running, or launchd can't be asked Cortex is NOT answering, unchanged 1

The 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 stop and uninstall wait

Both returned as soon as launchctl bootout did, which is before teardown finishes (waitBootedOut's doc). So they said "stopped" while the supervisor was still taking the proxy down, which takes up to superviseStopGrace, and still holding its ports. Now both wait for the label to leave the domain, as systemd's disable --now waits. They wait only after a bootout that found a job: "No such process" is nothing to wait for, and TestUnloadService_Darwin relies on that. If the teardown doesn't finish in serviceBootoutTimeout, they say so and point at service 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 stubbed launchctl keeps 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 asserts Cortex is stopped, and stays stopped, exit 0, after the real stop.
  • fakeSupervisor's launchctl stub answers print-disabled. TestServiceStatus_NotAnsweringNamesTheAgentsThatFail pins launchd's state as it already pinned systemd's.
  • Local: go vet (darwin and linux) and gofmt are clean. scripts/dev/go-test-shards.sh -race cmd/agentop passes (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

…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>
@Alan-Cha
Alan-Cha requested a review from a team as a code owner November 20, 2026 18:34
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 71c4d5e0-6147-4188-8b1d-70b7b05d1b80
Commits

Reviewing files that changed from the base of the PR and between 0ae1d75 and 6da7eef.

Files selected for processing: 10

  • cmd/agentop/cmd_service.go
  • cmd/agentop/cmd_service_characterize_test.go
  • cmd/agentop/cmd_service_launchd_integration_test.go
  • cmd/agentop/cmd_service_launchd_status_test.go
  • cmd/agentop/cmd_service_platform.go
  • cmd/agentop/cmd_service_systemd_test.go
  • cmd/agentop/cmd_service_test.go
  • cmd/agentop/proc_unix.go
  • cmd/agentop/proc_windows.go
  • docs/laptop-service.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions github-actions Bot added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 20, 2026

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread cmd/agentop/cmd_service.go Resolved
Comment thread cmd/agentop/cmd_service_platform.go Resolved
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 clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread cmd/agentop/cmd_service_platform.go Resolved
Comment thread docs/laptop-service.md Resolved
Comment thread cmd/agentop/cmd_service.go Resolved
Alan Cha added 2 commits November 23, 2026 10:30
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 clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Alan-Cha
Alan-Cha merged commit 8f06ddf into main Nov 23, 2026
39 checks passed
@Alan-Cha
Alan-Cha deleted the macos-stop-status branch November 23, 2026 16:20
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants