Repository navigation
fix: ask systemd whether a pod host has a per-user manager - #31980
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: on the no-bus branch, the system manager's answer only changes the remedy text, never the error class, and the directory walk is still the fallback when systemd can't be asked. Notes
[DESIGN-REVIEWED] ac74ff3 Description read[DESCRIPTION-READ] 79a92b8c02e69c066f57be85cf1236ffca4284de49dca666648ee011dd9f5f78 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing to check. The fix replaces the lookup with systemd's own answer, which is the cause, not the symptom. Both callers ( What this change shipsInventory (7 items) — 6 justifiedIntent: a user on a Linux host whose per-user systemd manager is masked, or whose units live on a moved unit path, is told to use
[FIRST-PRINCIPLES-REVIEWED] ac74ff3 Description read[DESCRIPTION-READ] 6c825cfdab097a15c7d8a3a89e070c32654160150d900936027f0ce9d8bc267a That sha256 names the PR description this verdict read. Recompute it with |
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: |
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: |
afeb99f to
a9aa783
Compare
a9aa783 to
90e8c2b
Compare
90e8c2b to
52da632
Compare
|
[operator: bolichen97] The red Backend Tests shard 2 on Linux, Windows and macOS (and the Coverage Gate and PR Readiness that follow it) is |
The pod gate and doctor decided whether a host can run systemd --user by walking a hand-copied list of systemd's unit directories. A masked user@.service read as present and $SYSTEMD_UNIT_PATH was invisible, so a host with no usable manager was told to enable linger. Ask the system manager instead (systemctl show --property=LoadState user@<uid>.service): it needs no user bus and applies systemd's own instance-then-template lookup, masks and unit path. The directory walk stays only for when that call cannot answer. Both pod gates and doctor use the one helper; on the missing-bus branch the refusal is still PodBackendAbsent whatever the answer, and no --user call is spawned. Closes #7399
|
Re-sync budget reset This head's only red is main's former line-budget test, which main fixed in #32252; every other check, including every AI review lane, passed, so one more re-sync is granted to pick that fix up. [operator: bolichen97] |
52da632 to
ac74ff3
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved: PR Readiness passed on ac74ff3, and all five review lanes (Opus 5.5, GPT 6.1, Design, UX, First Principles) report no blocking finding on this head. No conflict and no open change request.
The pod gate and doctor decided whether a host can run systemd --user by walking a hand-copied list of systemd's unit directories. A masked user@.service read as present and $SYSTEMD_UNIT_PATH was invisible, so a host with no usable manager was told to enable linger. Ask the system manager instead (systemctl show --property=LoadState user@<uid>.service): it needs no user bus and applies systemd's own instance-then-template lookup, masks and unit path. The directory walk stays only for when that call cannot answer. Both pod gates and doctor use the one helper; on the missing-bus branch the refusal is still PodBackendAbsent whatever the answer, and no --user call is spawned. Closes #7399 (cherry picked from commit e6f6a10) Original author: Bolin Chen (#31980). Hand-resolved, comment only: src/kiro_crew/pod/runtime.py takes main's comment above the load-path fallback, which describes the code this commit adds; every code line is identical to main.
Problem / Motivation
Goal: Decide whether a Linux host has a per-user systemd manager by asking systemd itself, so a masked unit or a moved unit path no longer gets the wrong pod remedy.
The pod gate (
require_systemd()) andkirocrew doctordecided "can this host have asystemd --userinstance" by walking a hand-copied list of systemd's unit directories withos.path.exists. That walk reads a maskeduser@.service(a symlink to/dev/null) as present, cannot see$SYSTEMD_UNIT_PATH, and is a list someone has to keep in step with a manual page. On such a host, a pod verb tells the user to runloginctl enable-linger, which cannot work.Why it matters
A user on a host whose administrator masked the per-user manager is sent after a remedy that cannot succeed, instead of being pointed at
./dev-backend.sh. Doctor gives the same wrong answer. Every fix to the directory list so far has been one more directory found missing in review.Not a goal
PodBackendAbsent.What changed (motivation → approach → change)
A pod command or
kirocrew doctoron a Linux host whose per-user manager is masked, or whose units sit on a path only systemd knows, gets the right advice: there is no manager here, use./dev-backend.sh, instead of aloginctl enable-lingerthat cannot work. The wrong advice came fromuser_manager_unit()re-implementing systemd's unit lookup instead of asking for its result.user_manager_unit()now asks the SYSTEM manager first:systemctl show --property=LoadState user@<uid>.service. System scope needs no user bus, so it answers on exactly the hosts wheresystemctl --usercannot. PID 1 resolves that name the way it would to start it: a concreteuser@<uid>.servicebefore the template, any mask, and its own unit path.not-foundandmaskedmean no manager; any other state means one exists. This asks about the exact unit rather than listinguser@*.service(the issue's suggestion), because one word needs no row parsing and covers both unit shapes in one call. When the call cannot answer (no trustedsystemctl, an error, a timeout), the existing directory walk decides, as it did before.Both callers share the one helper, so the pod gate and doctor cannot disagree. The gate reaches it only on its no-bus branch, which refuses either way: the answer picks the remedy text, never the error class, and no
--usercall is spawned there. The refusal text names the unit and template instead of the directory list.pod/README.md, the doctor row incli.md, the Dev Fleet pod section andsrc/kiro_crew/docs/troubleshooting.mdsay the same.Backwards compatibility
Compatible: hosts where systemd's answer matches the directory walk get the same message as before; the only hosts that change are those where the walk was wrong (a masked unit, a unit path the list did not hold), and a host where systemd cannot be asked keeps today's walk.
Removes nothing: no key, function or record is removed; the refusal message drops its directory list because systemd, not that list, now decides.
Tests
test_user_manager_unit_takes_the_system_managers_answer: with a template file on disk, amaskedornot-foundanswer makesuser_manager_unit()returnNone,loadedreturns the unit, and the call is system scope (no--user). A failed call, a non-zero exit, an unparseable or empty answer and a timeout each fall back to the directory walk.test_missing_bus_spawns_only_the_system_unit_query(renamed fromtest_missing_bus_is_reported_without_spawning): the user-bus probe still spawns nothing on a missing bus; each gate spawns exactly onesystemctl show --property=LoadState user@4242.serviceand still raisesPodBackendAbsentwhen that query fails. Its oldspawned == []for the two gates is the one assertion this PR changes, because asking systemd on that branch is the fix; the new list is pinned exactly.test_user_manager_unit_finds_a_hand_installed_uid_unitpins the system answer as unavailable, so it keeps testing the directory walk it was written for.Determinism: the three tests 20 times at
-n0, then 10 times at-n 4 --dist loadgroup --max-worker-restart=2besidetest/test_cli_doctor.pyandtest/test_pod_cli.py, all green;test/test_pod_systemd.pyin a shuffled order (seed 9211), green.Proof: PROVEN test/test_pod_systemd.py::TestSessionBus::test_missing_bus_spawns_only_the_system_unit_query, test/test_pod_systemd.py::TestSessionBus::test_user_manager_unit_takes_the_system_managers_answer (head afeb99f)
Manual verification
On a Linux host with systemd 252, as an unprivileged user:
systemctl show --property=LoadState user@<uid>.serviceprintsLoadState=loaded, andLoadState=not-foundfor a unit with no file or template, with exit 0 in both cases. A masked or$SYSTEMD_UNIT_PATHhost was not available; those answers come from systemd's own lookup.Screenshots / video
N/A — no frontend change.
Related Issues
Closes #7399
Sibling sweep
Swept: git grep -nE "os.path.exists([^)]systemd|lib/systemd/system"|/etc/systemd/system"" -- 'src/.py'
Siblings: none -- the only load-path walk is the one in pod/runtime.py; the service module writes its own unit at a fixed path and does not probe for another one.
Pattern harvest
Not generalizable: a single hand-copied lookup of systemd's unit directories; the fix is to ask systemd, and there is no second copy to catch.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.