Repository navigation
fix(service): bake KIROCREW_HOME into the installed service - #32493
Open
SaRedfiche wants to merge 1 commit into
Open
SaRedfiche wants to merge 1 commit into
SaRedfiche wants to merge 1 commit into
Conversation
4 of 5 tasks
SaRedfiche
force-pushed
the
crew/kirocrew-helper/service-home-env
branch
from
November 8, 2026 19:38
af6b381 to
40a0d5d
Compare
`kirocrew service install` captured KIROCREW_PORT and KIROCREW_KIRO_BIN from the installing shell but not KIROCREW_HOME, so a user with a custom data home got a service that resolved the default ~/.kiro/crew and started a new, empty, signed-out crew there with no warning. service_environment() now bakes KIROCREW_HOME when it is set, exactly as config_dir() reads it: made absolute, untrimmed, and with a leading "~" kept for the service to expand against the baked HOME (right under `sudo -H`). Both the systemd unit and the launchd plist render from that dict. The KIRO_API_KEY warning's caveat no longer claims the home is not inherited; it asks the operator to confirm the service's home, since a unit from another shell or an override file can still set a different one. Default installs are unchanged. Closes kirodotdev#32366
SaRedfiche
force-pushed
the
crew/kirocrew-helper/service-home-env
branch
from
November 9, 2026 23:43
40a0d5d to
16c467b
Compare
Contributor
Author
|
Hi maintainers, could someone approve the workflow runs for this fork PR? It's rebased onto current main (head |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Motivation
Goal:
kirocrew service installrun from a shell withKIROCREW_HOMEset installs a service that runs that same crew, instead of silently starting a new, empty one in~/.kiro/crew.A user with
export KIROCREW_HOME=$HOME/crew-dataruns the gateway happily, then runskirocrew service installfor 24/7 use. The unit carriesHOME,PATH, the locale,KIROCREW_PORTandKIROCREW_KIRO_BIN, but noKIROCREW_HOME. The service resolves the default~/.kiro/crewand starts a fresh crew there: signed out, no chats, nothing printed.Why it matters
Keeping the crew up after logout is the natural next step after a custom data home works. Today that step swaps the user's crew for an empty one, and nothing on screen or in the logs connects the two. It hits every Linux and macOS user who relocated their data home.
Not a goal
KIROCREW_HOMEis set only for the one-line install (KIROCREW_HOME set only for the install: the installer puts part of the crew there, then the gateway silently starts a second, engine-less crew in ~/.kiro/crew #32362).PATH(open PR fix(service): put nvm's Node ahead of /usr/bin in the service PATH #32108 changes that part of the same function).KIROCREW_HOME) writes.kirocrew doctorto read the home an installed unit really carries (it still judges from its own shell).What changed (motivation → approach → change)
The service never learned which crew to run, so it ran the default one.
service_environment()already copiesKIROCREW_PORTandKIROCREW_KIRO_BINfrom the installing shell into the one dict both the systemd unit and the launchd plist render from. It now copiesKIROCREW_HOMEthe same way, only when it is set.KIROCREW_HOME/srv/crew-data/srv/crew-data, untrimmed, exactly asconfig_dir()reads itcrew-data(relative)~/crew-dataconfig_dir()expands it against the bakedHOME, which stays right undersudo -HThe
KIRO_API_KEYwarning used to add "KIROCREW_HOME is set here but is also not inherited". That claim is false now, so the caveat says something true instead: a service installed from a shell with another value, or whose override file (/etc/kirocrew/kirocrew.envon Linux) sets its own, runs a different home, so confirm the home. It shows on install and inkirocrew doctor, in both theKIRO_API_KEYnote and the inherited-variables note (service/inherited_env.py), which share the helper, since neither command can see which home the service really starts with. The cli spec namesKIROCREW_HOMEamong the installer-derived values and describes the caveat.Backwards compatibility
Compatible: with
KIROCREW_HOMEunset the dict, the unit and the plist are byte-identical to today. An existing install keeps its old unit until the nextservice install.Removes nothing: the warning keeps its caveat on the same condition (
KIROCREW_HOMEset); only its wording changes, and no function or key is removed.Tests
test_propagates_crew_home_only_when_set: absent when unset or empty, copied untrimmed when set.test_relative_crew_home_is_absolutized_and_tilde_kept: a relative home is made absolute;~/...is kept verbatim.test_crew_home_reaches_both_rendered_service_definitions: the value, with a space in it, reaches the plist'sEnvironmentVariablesand the unit's quotedEnvironment=line.test_custom_home_caveat_only_when_home_is_overriddenadditionally pins that the caveat no longer says "not inherited" and names the override file.Proof: PROVEN test/test_service_environment.py::TestServiceEnvironment::test_crew_home_reaches_both_rendered_service_definitions, test/test_service_headless_api_key.py::TestHeadlessApiKeyWarning::test_custom_home_caveat_only_when_home_is_overridden (head 16c467b)
Locally:
test/test_service*.py,test_env_file_bom.py,test_linux_facade.py,test_doctor*.pyandtest_service_inherited_env.pypass (1262), the two changed files pass 3 repeats and a reversed order, as do mypy--platform linux, flake8, isort, pinned black on the changed lines, semgrep on the diff, the flake-pattern ratchet, and the repo'scheck_*scripts that run without CI inputs.Manual verification
N/A — unit coverage renders both real service definitions end to end. I did not run a live
systemctl/launchctlinstall.Related Issues
Closes #32366
Related: #32362 (installer-side
KIROCREW_HOME, out of scope here).Related: #11289 (Windows Task Scheduler service) does not render from
service_environment()and refuses an install whoseKIROCREW_HOMEis not persisted withsetx, so Windows needs nothing here. It reformats the same caveat line this PR rewords inservice/common.py; whichever lands second takes a one-line rebase.Sibling sweep
Swept: git grep -n 'environ.get("KIROCREW_' -- src/kiro_crew/service/
Sibling: src/kiro_crew/service/common.py:198 -- not affected -- KIROCREW_KIRO_BIN is already baked
Sibling: src/kiro_crew/service/common.py:207 -- not affected -- KIROCREW_PORT is already baked
Sibling: src/kiro_crew/service/macos.py:252 -- not affected -- KIROCREW_SERVICE_BIN picks the program path at install, never needed at runtime
Sibling: src/kiro_crew/service/controller.py:129 -- not affected -- Windows has no managed service on main (install prints the unsupported-platform message); #11289's Windows service handles the home by refusing an unpersisted one
Pattern harvest
Not generalizable: the set of variables a managed service must inherit is a per-variable product decision (credentials are deliberately excluded), so no lint can tell a missing key from an intentionally omitted one.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)