Repository navigation
fix(service): address launchd gui/<uid> domain explicitly in install and stop - #17492
Conversation
0166018 to
4de4344
Compare
Design Review (Opus 5.5) — ✅ human override accepted@buluoray overrode this lane for |
First Principles Review (Opus 5.5) — ✅ human override accepted@buluoray overrode this lane for |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
4de4344 to
4bae3c3
Compare
|
Disposition of the Design Review and First Principles Review BLOCKs on Design: First Principles item 7: duplicated helpers — agreed. Both: no real-Mac run / unverified |
4bae3c3 to
fac8f4a
Compare
UX Review (Opus 5.5) — ⏭️ skippedRevision |
fac8f4a to
8ea30cc
Compare
8ea30cc to
f30c8a5
Compare
|
Disposition of the reviews on 8ea30cc, fixed in f30c8a5 (one push, rebased onto main):
Tests: 17 passed in |
|
Description updated at the owner's request: the owner asked for SSH installs on a Mac with no desktop login to keep working, so this PR now falls back to |
f30c8a5 to
ac69d51
Compare
|
Disposition of the reviews on f30c8a5, fixed in ac69d51 (one push, rebased onto main):
Tests: |
|
/ai-review override design ac69d51: the only open finding is the request for a run on a real Mac. The code was verified against source and a stateful launchctl stand-in (install, stop, uninstall and restart across gui/ and user/, with tests that redden on each reverted guard). An SSH install with no desktop login now falls back to user/, so no install that worked before can fail. No Mac is available on this host; the owner ruled this override acceptable on that basis. |
|
/ai-review override first-principles ac69d51: item 2 is the same real-Mac evidence request (owner ruled the override acceptable; no Mac on this host). Item 6 is stale: the PR body was updated after this verdict and now declares the |
Human judgment recorded@buluoray marked the design AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
Human judgment recorded@buluoray marked the first-principles AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
CrysisDeu
left a comment
There was a problem hiding this comment.
Approving at ac69d51. Read the full diff plus the owning spec; nothing blocking. Non-blocking notes, worth a follow-up or a quick fix before merge:
- [MINOR] src/kiro_crew/service/macos.py (
_bootout,return Trueafter the first domain that accepts) -- the module now explicitly models the agent living ingui/<uid>ORuser/<uid>, but a job can exist in BOTH: after the no-desktop fallback bootstraps intouser/<uid>, the plist is still in~/Library/LaunchAgents, so the next desktop login loads it intogui/<uid>as well (two gateways, one label; the second loses the port bind andKeepAliveloops it).stop()/uninstall()/reinstall then boot out only the first hit and return True while theuser/<uid>instance keeps running;restart()likewise kickstarts only the first. Sweep every domain in_bootout(andrestart) rather than returning on the first acceptance -- it is the same loop, andis_loaded()already probes both. The dual-domain state was equally reachable with the oldload -wfrom SSH, so this is not a regression, but the PR is the one introducing the two-domain model and should close it (or at least name it incli.md). - [NIT] src/kiro_crew/service/macos.py (
_domain_unavailable) -- matches only rc 125 / "125: domain does not support". The stand-in encodes that same assumption for everygui/verb (print,bootout,kickstart), but on a real Mac with nobody logged inlaunchctl print gui/<uid>/<label>can answer "Could not find domain for gui/" instead. If it does,is_loaded()reads "loaded" (fail-closed by design),restart()returns False without tryinguser/<uid>, and_bootoutlogs a refusal. Cheap hardening: add "could not find domain" to the absent/unavailable test. (The need for a real-Mac transcript is already recorded and overridden by the owner; this is a one-line mitigation, not a repeat of that ask.) - [NIT] src/kiro_crew/service/macos.py (
_uid) duplicates thegetattr(os, "getuid", lambda: -1)guard thatpod.launchd.domain()already carries;_legacy_domains()could deriveuser/<uid>fromdomain().split("/", 1)[1]and drop the helper.
is_active() and status() used `launchctl list <label>`, which reads only the caller's domain and can exit non-zero with empty output for a serving gui/<uid> agent, so `kirocrew service status` called a running gateway "not loaded". Both now probe `launchctl print <domain>/<label>` over gui/<uid> then user/<uid>, the same domains install, stop and restart address since #17492. status() renders a terse summary (domain, state, pid, non-zero last exit, plist path). Adds darwin-only tests that bootstrap throwaway agents into the real gui/<uid> domain and read running, never-started, exited and absent states back through the module. Closes #11002 Co-authored-by: Di Wu <dwu96@users.noreply.github.com>
is_active() and status() used `launchctl list <label>`, which reads only the caller's domain and can exit non-zero with empty output for a serving gui/<uid> agent, so `kirocrew service status` called a running gateway "not loaded". Both now probe `launchctl print <domain>/<label>` over gui/<uid> then user/<uid>, the same domains install, stop and restart address since #17492. status() renders a terse summary (domain, state, pid, non-zero last exit, plist path). `service status` exits on a new is_up() (state = running), so a crash-looping agent exits 1 as on Linux, while is_active() keeps loaded-counts-as-active for reach. Closes #11002 Co-authored-by: Di Wu <dwu96@users.noreply.github.com>
is_active() and status() used `launchctl list <label>`, which reads only the caller's domain and can exit non-zero with empty output for a serving gui/<uid> agent, so `kirocrew service status` called a running gateway "not loaded". Both now probe `launchctl print <domain>/<label>` over gui/<uid> then user/<uid>, the same domains install, stop and restart address since #17492. status() renders a terse summary (domain, state, pid, non-zero last exit, plist path). `service status` exits on a new is_up() (state = running), so a crash-looping agent exits 1 as on Linux, while is_active() keeps loaded-counts-as-active for reach. Closes #11002 Co-authored-by: Di Wu <dwu96@users.noreply.github.com>
Problem / Motivation
Goal: On macOS,
kirocrew service installputs the gateway agent in the launchd domain thatrestart,stopand the status probes all address, including when it is run over SSH, andkirocrew stopno longer reports success when launchd refused the stop.install()usedlaunchctl load -w <plist>andstop()usedlaunchctl unload <plist>. Those legacy verbs act on the caller's own domain. From a desktop session that isgui/<uid>, the domainrestart()'skickstart -k gui/<uid>/<label>and Dev Fleet's probe already name. From SSH it isuser/<uid>, so the agent lands whererestartcannot reach it, andstop_service()falls through to the port-SIGTERM path, whichKeepAliveundoes at once. Separately,stop()returnedNoneandstop_service()returnedTruefor any stop, so a refused unload printed "✅ Stopped kirocrew service".Why it matters
Anyone running the gateway on a Mac they reach over SSH (the module supports headless flows; see
headless_auth_warning) gets an agent thatkirocrew restart/stopcannot control, and a CLI that says the stop worked when it did not.Not a goal
is_active()/status(). Moving them tolaunchctl print gui/<uid>/<label>is open PR fix(service): probe launchd by domain target on macOS #11016. This PR leaves those two functions alone, so they still read the caller's domain withlaunchctl list: from SSH they do not see agui/<uid>job until fix(service): probe launchd by domain target on macOS #11016 lands. It merges cleanly beside fix(service): probe launchd by domain target on macOS #11016 (measured below).user/<uid>fallback in the probes (option 2 in the issue). The onlyuser/<uid>fallback here is ininstall(), for the one case wheregui/<uid>does not exist, and every write verb searches that domain too.kirocrew stopdoes after a refused service stop. It now takes the same non-service path it takes when no service is active.What changed (motivation → approach → change)
Symptom: an install from SSH lands the job where the other verbs do not look, and a refused stop is reported as a stop. Root cause: two write verbs act on whatever domain the caller is in, while every other verb names
gui/<uid>. Fix (options 1 and 3 from the issue):install():launchctl enable gui/<uid>/<label>, thenlaunchctl bootstrap gui/<uid> <plist>.enabletakes over the jobload -wdid of clearing a persistent disabled override, which an olderuninstallwrote withunload -w(without it, reinstalling after a legacy uninstall would be refused).gui/<uid>domain, and launchd answers125: Domain does not support specified action. On that answer only, install runsenable+bootstrapintouser/<uid>instead and logs which domain it used. This keeps the install working whereload -wfrom SSH succeeded before (the owner asked for this fallback). Any other bootstrap refusal still raisesServiceInstallError._bootout()boots out an agent an olderload -wleft behind, searchinggui/<uid>thenuser/<uid>. Becausebootoutis asynchronous (seepod/launchd.stop), it pollsprintuntil the label is gone, for up to 10s, before bootstrapping. Without that wait, bootstrap would hit the label that has not finished unloading.stop():launchctl bootout <domain>/<label>over the same domains, returningbool.bootouttakes the job out of the domain, soKeepAlivehas nothing to respawn. The plist and its enabled state stay in place for the next login, so the no-respawn property ofunloadwithout-wis kept. A definite "not found", or125from a missing domain, means no job there and the next domain is tried; any other refusal is logged and returnsFalse.restart():kickstart -kongui/<uid>thenuser/<uid>, the same order and the same "not found / 125 means try the next domain" rule, so it reaches an agent the no-desktop fallback installed. Any other refusal returnsFalse.uninstall(): the same bootout, then the plist is removed.is_loaded()(new):launchctl print <domain>/<label>overgui/<uid>thenuser/<uid>. Only "not found" or125counts as absent, so a flaky probe never reads as "nothing installed".controller.restart_service()gates onis_loaded()instead of the caller-domainis_active(). From SSH,is_active()misses agui/<uid>job, so a CLI restart got an empty report and fell to the SIGTERM-by-port + detached-spawn path, starting an unmanaged gateway beside theKeepAliveone. It now kickstarts the service job.controller.stop_service()callsmacos.stop()directly and returns its bool, instead of gating onis_active()(which from SSH misses agui/<uid>job) and returning a hard-codedTrue.docs/system-specs/modules/cli.md, launchd section.Backwards compatibility
No install that succeeded before should now fail (checked against source only, not on a real Mac). A desktop install still lands in
gui/<uid>. An SSH install with someone logged in at the desktop now lands ingui/<uid>instead ofuser/<uid>. An SSH install with nobody at the desktop falls back touser/<uid>, the domainload -wused, andrestart,stop,uninstalland reinstall all reach it there. Remaining gap:is_active()/status()still read the caller's domain, so from a desktop session they do not see a fallbackuser/<uid>job; #11016 covers those probes. Writer sweep: the only callers ofmacos.install()/macos.stop()/macos.restart()are inservice/controller.py.install_servicealready catchesServiceInstallErrorand prints it.Reader: src/kiro_crew/service/controller.py:stop_service -- entry: chat|release (CLI
kirocrew stop) -- callsmacos.stop()and passes its bool through; test_stop_service_propagates_the_launchd_answer, test_kirocrew_stop_from_ssh_boots_out_the_gui_jobReader: src/kiro_crew/cli_server.py:_stop -- entry: release (CLI) -- already branches on
stop_service()'s bool; a False takes the existing non-service pathReader: src/kiro_crew/service/macos.py:restart -- entry: release -- tries
gui/<uid>thenuser/<uid>; test_install_from_ssh_lands_where_restart_and_stop_address_it, test_install_without_a_desktop_session_falls_back_to_the_user_domainReader: src/kiro_crew/service/controller.py:restart_service -- entry: release (CLI restart command) -- gates on
macos.is_loaded(); test_kirocrew_restart_from_ssh_kickstarts_the_service_job, test_kirocrew_restart_with_nothing_loaded_leaves_it_to_the_foreground_pathReader: src/kiro_crew/service/macos.py:is_active/status -- entry: release -- untouched; they read the caller's domain until #11016, and
is_service_active()still usesis_active()Tests
All run with launchctl stubbed. This host is Linux, so the narrowest honest check is the argv the module builds, run against a stateful
launchctlstand-in. The stand-in models the one behaviour at issue:load/unloadact on the caller's domain, whilebootstrap/bootout/print/kickstartname one. It also models a persistent disabled override and the asynchronous bootout, and with no desktop login it answers125for everygui/<uid>verb.New
test/test_service_macos_launchd_domain.py(20 tests):gui/<uid>, after whichrestart()andstop()both succeed;kirocrew stopfrom SSH boots out thegui/<uid>job, and reports no stop when nothing is loaded; a CLI restart from SSH kickstarts the service job with and without a desktop session, and leaves a not-loaded agent to the foreground path;user/<uid>, logs it, andrestart()andstop()then reach it; reinstall and uninstall reach that job too; a bootstrap refusal other than125raises and does not fall back;load -wjob fromgui/<uid>and fromuser/<uid>, waits for the async bootout, and clears a legacy disabled override;stop()returns False for a refused bootout and for nothing loaded, finds a legacyuser/<uid>job, leaves the plist enabled, and never callsstop/disable/-w;uninstall()boots out by domain;stop_service()passes on True and False.Red on base (the file run against origin/main's
service/macos.pyandservice/controller.py): 16 failed, 4 passed. The four that pass are guards for behaviour base already had: the disabled override cleared byload -w,kirocrew stopreporting no stop with nothing loaded, a CLI restart with nothing loaded taking the foreground path, and a no-desktop reinstall/uninstall, whichload -w/unloadalready handled in the caller'suser/<uid>domain.Mutation matrix (each one applied alone; every one turns at least one named test red):
enable..._clears_a_disabled_override_left_by_legacy_uninstall..._migrates_a_legacy_load_w_job[gui,user],..._waits_for_the_async_bootout_...gui/<uid>only..._migrates_a_legacy_load_w_job[user],test_stop_still_finds_a_legacy_user_domain_jobtest_stop_service_propagates_the_launchd_answer[False]is_active()gate instop_servicetest_kirocrew_stop_from_ssh_boots_out_the_gui_joband otherstest_stop_with_nothing_loaded_is_not_a_stopload -wuser/<uid>install fallbacktest_install_without_a_desktop_session_falls_back_to_the_user_domaintest_install_fails_on_a_refusal_other_than_an_unavailable_domain125as a refusaltest_install_without_a_desktop_session_falls_back_to_the_user_domain,test_reinstall_and_uninstall_without_a_desktop_session_reach_the_user_jobgui/<uid>onlytest_install_without_a_desktop_session_falls_back_to_the_user_domainrestart_servicegated onis_active()againtest_kirocrew_restart_from_ssh_kickstarts_the_service_job[desktop]is_loaded()probesgui/<uid>onlytest_kirocrew_restart_from_ssh_kickstarts_the_service_job[no-desktop]Updated in
test/test_service.py: tests that pinned the oldload/unloadargv, or astop()mock without a return value, now pinbootstrap/bootoutand the bool, and the threerestart_servicelaunchd pins patchis_loaded. Runs:test/test_service_macos_launchd_domain.py20 passed;test/test_service.py442 passed.Overlap with #11016, measured with
git merge-tree --write-tree HEAD pr/11016:macos.pyandtest_service.pyauto-merge. The twocli.mdconflicts (lines ~239 and ~1466) are identical to the onesgit merge-tree origin/main pr/11016already reports, so this PR adds none.Manual verification
Not run on a real Mac, because this host cannot run launchd. Still to check on macOS:
kirocrew service install, thenlaunchctl print gui/$(id -u)/dev.kirocrew.gateway(rc 0),kirocrew restart,kirocrew stop(agent gone and not respawned).kirocrew service installsucceeds and logs theuser/<uid>fallback,launchctl print user/$(id -u)/dev.kirocrew.gateway(rc 0), thenkirocrew restartandkirocrew stopboth succeed. Also capture whatlaunchctl bootout gui/$(id -u)/dev.kirocrew.gatewayanswers in that state: the stand-in assumes125.Related Issues
Closes #11017
Related: #11016 (read-only probes; no shared hunks)
Pattern harvest
Rule candidate: review-prompt
Pattern: a launchctl verb that addresses the caller's domain implicitly (
load,unload,list <label>) in a module where other verbs namegui/<uid>explicitly.Checklist
Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.