Repository navigation
Conversation
…22450) Edits to $KIROCREW_HOME/.env took effect only after a full gateway restart: the live config watcher fingerprinted config.json only and nothing re-read .env after boot. The dashboard's own credential writer applied its changes live, but a hand edit or any non-dashboard writer did not. ConfigWatch now reconciles .env in the same cycle that reloads config.json. It tracks a separate env fingerprint (loader.env_fingerprint), kept out of _config_fingerprint because that one is the parsed-config cache key. On an .env change it re-reads the raw credential map off the loop, diffs it against a baseline, and pushes changed keys into os.environ (set/pop), dispatching the same path a synthetic credentials.<KEY> change takes so the channel-restart applier restarts only the channels whose descriptor credentials changed (restart_channel, which re-reads load_credentials). Slack is host-managed with no in-process restart path, so a Slack token change logs a restart-needed notice instead. Teams gains a restart_credentials descriptor field for keys (the tenant id) that are restart-relevant but not required for readiness, since folding the tenant into `credentials` would wrongly report multi-tenant Teams as un-startable. Diff semantics, built up across review rounds and pinned by tests: - A removed key is popped from os.environ only when the current value still equals what .env last propagated, so an inherited shell/systemd value a removal never set is left alone. - The overwrite warning fires only on a genuinely foreign value collision, not on every routine rotation. - The watcher's diff baseline is seeded from the raw .env map the first boot-time load_credentials() actually read (recorded once, consumed once), not a later disk read, so a credential rotated in the boot window is still diffed and applied instead of silently adopted as the new baseline. - The fingerprint and baseline only advance after an apply succeeds; a failed apply (e.g. a malformed `=value` line in the same write as a real rotation) leaves both untouched so the next tick retries the whole diff, and the apply validates every key before mutating anything so a batch is atomic. - Every post-boot credential read (channel reconnect, readiness badge, jira/doctor/upload-destination readers) now calls load_credentials(propagate=False), so a worker-thread read can no longer reseed a credential the live watcher just removed. The dashboard's own credential writer routes through the same apply_env_credential_changes instead of hand-rolling os.environ set/pop, so it inherits the Docker-scrub skip and PATH carve-out. - A non-BOM decode error on .env is treated as non-definitive (warned once, retried) instead of wedging the watcher permanently. - Teams: a credential removal closes the live client but its inbound webhook route stays registered, so TeamsClient now re-checks "closed" after the processing awaits (not just at entry) and 503s once closed; closing clears the bound activity handler. Adds loader helpers (env_fingerprint, read_env_credentials_raw, changed_env_keys, apply_env_credential_changes, record_boot_raw_env/take_boot_raw_env) and registry.changed_credential_keys (case-insensitive on Windows), plus tests for the loader helpers, the watcher's .env tracking and boot- window baseline, the credential-driven channel restart, and the Teams webhook-after-close race. Later review rounds, folded into this commit: - A .env PATH line is expanded and validated off the event loop (ConfigWatch._prepare_path_additions -> env.prepare_env_path_additions, run via asyncio.to_thread) and handed to the applier as path_additions, so a ~otheruser entry's pwd.getpwnam / SAM lookup never blocks the loop. os.path.expanduser semantics are unchanged. - The applier decides per os.environ ENTRY, not per .env spelling: on Windows (case-insensitive os.environ) all spellings of a key are grouped and resolved once, to the first non-empty spelling in .env order (boot's setdefault precedence), so renames, partial duplicate removals and both-spellings edits are no longer order-dependent. - Ownership is recorded only when a write takes the entry over (new key, rotation, overwrite of a foreign value). A line that merely matches an inherited service/shell value is not owned, so removing it keeps the inherited credential. - Teams: the webhook handler (state.teams_on_activity) is bound only once a client is the accepted handle (after boot's start_channels, and after a restart passes its generation check), so a restart superseded mid-connect never exposes its handler. - Slack: the restart-needed notice matches credential keys by canonical entry name, like registry.changed_credential_keys.
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The diff only changes backend code and adds no dashboard control, label or string, so no screenshot was needed. The changed log lines and the Teams webhook 503 never reach the dashboard UI. [UX-REVIEWED] 10ae360 Description read[DESCRIPTION-READ] b18d10fd42a6903b3ff7c41981198848fcad1364230fd03b5e97ed176acd76e3 That sha256 names everything this verdict read: the PR description, plus the 3 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 |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. Watching Notes
[DESIGN-REVIEWED] 10ae360 Description read[DESCRIPTION-READ] 590accd65ecdb3c97596a08e05cf0ef33d3002b5820c1251e3e5f99ea5b48e42 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 |
GPT 6.1 Review — 🔴 changes requested (blocking)GPT 6.1 found at least one blocking issue that must be resolved before merging This comment is updated in place on each push. BLOCKING -- website/src/apps/meetings/hooks/useNoteDraft.ts:322 -- Pagehide save can be overwritten by an older autosave
[BLOCK-MERGE] 10ae360 Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 — the harm claim holds: the user's newest note edits are lost with no warning. This file is not in this PR's diff ( False positive or not applicable? A repository writer can comment: |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Every item traces back to the reported harm: a Notes
What this change shipsInventory (10 items) — 5 justifiedIntent: a credential an operator edits in
[FIRST-PRINCIPLES-REVIEWED] 10ae360 Description read[DESCRIPTION-READ] c35d1856c4f2ec4cb149a93dd6988a5ff0fe30dc12c41000a7d79a953c53df70 That sha256 names the PR description this verdict read. Recompute it with |
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: |
…ough the applier changed_env_keys compared .env keys one at a time, so on Windows (where several spellings share one case-insensitive os.environ entry) a save that only reordered two spellings with different values produced an empty diff, even though it changed which value boot and the live applier install. The watcher then advanced its baseline without applying the new winner. It now also compares each entry's effective value (first non-empty spelling in .env order) and reports every spelling of an entry whose value moved. On POSIX the result is the same per-key set as before. (GPT 6.1 Review blocking finding.) The first Weixin QR sign-in wrote WEIXIN_TOKEN into os.environ directly and never recorded .env ownership, so removing the line later left the revoked token in force until a full restart. The write now goes through apply_env_credential_changes, like the dashboard channel writer, which records ownership and keeps the Docker scrub guard. (Opus 5.5 Review blocking finding.)
|
Superseded by #23514: the same change as one commit on current main. It adds the two structural-guard registrations this PR's CI flagged (config.loader facade manifest and the gateway composition inventory). With #23335 now in the base, the out-of-diff meetings finding falls outside the review range. |
Problem / Motivation
Goal: An edit to
$KIROCREW_HOME/.envtakes effect on a running gateway, restarting only the affected channel, without a full gateway restart.Edits to
$KIROCREW_HOME/.envtook effect only after a full gateway restart. The live config watcher fingerprintedconfig.jsononly, and nothing re-read.envafter boot. The dashboard's own credential writer applied its changes live, but a hand edit or any other writer did not, so a rotated token kept reading as the old value until someone restarted the gateway.Why it matters
Operators rotate channel credentials by editing
.env. Today the edit silently does nothing until a restart, so a revoked token keeps a channel failing to authenticate, and a new token looks "saved" but is not in force. Requiring a full restart for a credential change also drops every running session.Not a goal
kirocrew restart" notice instead..envsupports or how boot reads it.What changed (motivation → approach → change)
Symptom: a
.envedit is ignored until restart. Root cause:ConfigWatchnever watched.env. Change:.envis reconciled in the same poll cycle that already reloadsconfig.json.load_credentials(propagate=False), so a worker-thread read cannot reseed a credential the watcher just removed.apply_env_credential_changesinstead of its own set/pop loop, so it also respects the Docker credentials scrub..envPATHline is expanded and validated off the event loop (env.prepare_env_path_additions, run viaasyncio.to_thread) and handed to the applier aspath_additions. A~otheruserentry callspwd.getpwnam/ the SAM database, and that lookup no longer runs on the loop.os.path.expandusersemantics are unchanged..envownership only when the write takes the entry over (a new key, a rotation, an overwrite of a foreign value, or a key.envalready owns). A line whose value merely matches what the process inherited from a service unit or shell is not owned, so removing it later leaves the inherited credential in place, as boot'ssetdefaultalready does.os.environENTRY rather than per.envspelling. On Windows (case-insensitiveos.environ) every spelling of a key (HTTPS_PROXY/https_proxy) is grouped and resolved once, to the first non-empty spelling in.envorder (boot'ssetdefaultprecedence), so a rename, a partial duplicate removal, or both spellings edited in one save cannot leave the entry depending on iteration order. On POSIX each entry has one spelling, so nothing changes there.changed_env_keys) also compares each entry's effective value, so a Windows save that only reorders two spellings with different values is applied instead of silently adopted as the new baseline.apply_env_credential_changesas the dashboard channel writer, so it records.envownership (a later removal of the line revokes it in-process) and keeps the Docker scrub guard.restart_credentialsdescriptor field.state.teams_on_activity) is bound only once a client is the accepted handle, after boot'sstart_channelsand after a restart passes its generation check.maybe_start_teamsno longer binds it before the connect completes, so a restart superseded mid-connect never exposes its handler (the route answers 503 until then).registry.changed_credential_keys, so a lowercase.envSlack key on Windows still gets the notice.This supersedes #23027 and #23470 (both closed). Same reviewed change, squashed onto current
mainso PR Hygiene's commit limit is met without a force-push; every AI review lane passed on that tree at #23470's last head. The second commit fixes the two findings raised here.Backwards compatibility
Compatible: boot still seeds
.envwithsetdefault, every key.envaccepted before is still accepted, andPATHentries resolve exactly as before.Removes nothing: the diff adds a watcher input and routes existing credential writes through one applier; no key, kind, public function or stored data is removed or renamed.
Reader: src/kiro_crew/dashboard/messaging_api/channel_config_writes.py:write_channel_env -- crew page -- under
_KIROCREW_CREDS_SCRUBBEDa dashboard save no longer writes credential keys intoos.environ, matching the boot loop; children read them from.env(test_a_landed_write_honours_the_docker_creds_scrub)Tests
Proof: PROVEN test/test_channel_boot_hot_reload.py::TestTeamsCloseClearsWebhookHandler::test_closing_teams_clears_the_late_bound_webhook_handler, test/test_channel_boot_hot_reload.py::TestTeamsWebhookPublishedOnlyForTheAcceptedClient::test_an_accepted_start_binds_its_handler, test/test_channel_boot_hot_reload.py::TestCredentialChangeRestartsChannel::test_a_credential_change_restarts_the_owning_channel, test/test_channel_boot_hot_reload.py::TestCredentialChangeRestartsChannel::test_a_credential_change_for_a_degraded_channel_is_deferred_not_dropped, test/test_channel_boot_hot_reload.py::TestSlackCredentialChangeWarns::test_a_slack_token_change_logs_a_restart_needed_notice (head 10ae360)
test/test_env_credential_hot_reload.py: an env-only edit dispatchescredentials.<KEY>and appliesos.environ; a failed apply leaves the baseline so a repair re-applies the rotation; an undecodable or wide-encoded.envis retried rather than read as every key cleared; a removal pops only what.envpropagated; a.envPATH edit is expanded on a worker thread, not the loop thread; a Windows case-duplicate keeps its entry when one spelling is removed; a live add that matches an inherited value does not take ownership, so deleting the line keeps the inherited token, while an add that writes a new value does own it and is popped on removal; both spellings edited in one save resolve to boot's precedence in either iteration order, modelled with a case-foldingos.environ; a reorder of two Windows spellings with different values is a diff and installs the new winner, while a reorder of equal values is not.test/test_dotenv_path_extension.py: a.envPATH line appends absolute directories behind the existing PATH, deduped; relative and unexpanded entries are dropped with a warning;~and~otheruserstill expand throughos.path.expanduser.test/test_channel_boot_hot_reload.py: a credential change restarts only the owning channel; a degraded channel's change is deferred, not dropped; a Slack token change logs the restart notice; closing Teams clears the late-bound webhook handler; a Teams restart superseded mid-connect never binds its webhook handler while an accepted one does; a lowercase Slack key on Windows still logs the notice.test/test_weixin_qr.py: a first sign-in records ownership, so deleting the line afterwards revokes the token in-process.test/test_teams_gateway.py:maybe_start_teamsregisters the transport but leaves the webhook handler unbound for the host.test/test_channel_env_write_off_loop.py: the dashboard writer honours the Docker credentials scrub.Local on head
10ae360118(Python 3.12): 2002 passed, sequential and parallel, across the env/config/channel/Teams/Slack/jira/loader suites; black, isort, flake8 clean on all 36 changed Python files; mypy clean on the nine changed source modules;scripts/check_black_formatting.pygate passes; flake-pattern ratchet passes against the merge base.Manual verification
N/A — the watcher cycle, applier, and channel restart dispatch are each driven end to end by the
ConfigWatch._cycle()tests above against a real temp.env, which is the path a hand edit takes.Related Issues
Fixes #22450
Sibling sweep
Swept: git grep -nE "load_credentials(|apply_env_credential_changes|os.environ[.*] *=" -- src/
Sibling: src/kiro_crew/dashboard/messaging_api/channel_config_writes.py -- changed here
Sibling: src/kiro_crew/slack/gateway_runtime/channel_lifecycle.py -- changed here
Sibling: src/kiro_crew/dashboard/source_providers/jira.py -- changed here
Sibling: src/kiro_crew/dashboard/upload_destination.py -- changed here
Pattern harvest
Not generalizable: the defect was one missing watcher input (
.envalongsideconfig.json), not a repeated code shape a rule could catch.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)docs/system-specs/modules/config.mdContribution License Agreement
Contributed under the project's Apache-2.0 license.