Skip to content

fix(env): reload .env credential changes without a gateway restart (#22450) - #23836

Merged
iamwhatever merged 1 commit into
mainfrom
env-hotreload-22450-v5
Oct 29, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
env-hotreload-22450-v5

Conversation

@RohanK6

@RohanK6 RohanK6 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An edit to $KIROCREW_HOME/.env takes effect on a running gateway, restarting only the affected channel, without a full gateway restart.

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 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

  • Hot-swapping a Slack token in place. Slack's client is host-managed with no in-process restart path, so a Slack token change logs a "run kirocrew restart" notice instead.
  • Pushing a new environment into already-running children (ACP sessions, MCP servers). They keep their environment until they respawn.
  • Changing which keys .env supports or how boot reads it.

What changed (motivation → approach → change)

Symptom: a .env edit is ignored until restart. Root cause: ConfigWatch never watched .env. Change: .env is reconciled in the same poll cycle that already reloads config.json.

operator edits $KIROCREW_HOME/.env
        │
        ▼
ConfigWatch._cycle()  ── same poll that already reloads config.json
        │
        ├─ env_fingerprint(.env) unchanged → nothing to do
        │
        └─ env_fingerprint(.env) changed
                │
                ▼
        read_env_credentials_raw()       (off-loop, permission-checked)
        _prepare_path_additions()        (off-loop: PATH expand + validate)
                │
                ▼
        diff vs baseline (seeded once at boot from the raw map
        load_credentials() actually read, not a later disk read)
                │
                ├─ validate every changed key first (atomic batch)
                │
                ▼
        apply_env_credential_changes()   (on-loop: os.environ mutation only)
                │   set/pop os.environ, honouring the Docker scrub and PATH carve-outs
                │   pop only what .env itself propagated (ownership is recorded)
                │
                ├─ success → advance fingerprint + baseline
                │            dispatch credentials.<KEY> (+ Teams restart_credentials)
                │                     │
                │                     ▼
                │            restart_channel() re-reads load_credentials()
                │            (Slack: host-managed → "run kirocrew restart" notice)
                │
                └─ failure → leave fingerprint + baseline untouched
                             next tick retries the whole diff
  • After boot, every gateway-side credential read (channel reconnect, readiness badge, jira/doctor/upload-destination) uses load_credentials(propagate=False), so a worker-thread read cannot reseed a credential the watcher just removed.
  • The dashboard's credential writer now goes through the same apply_env_credential_changes instead of its own set/pop loop, so it also respects the Docker credentials scrub.
  • A .env PATH line is expanded and validated off the event loop (env.prepare_env_path_additions, run via asyncio.to_thread) and handed to the applier as path_additions. A ~otheruser entry calls pwd.getpwnam / the SAM database, and that lookup no longer runs on the loop. os.path.expanduser semantics are unchanged.
  • A live set records .env ownership only when the write takes the entry over (a new key, a rotation, an overwrite of a foreign value, or a key .env already 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's setdefault already does.
  • The .env ownership record survives an in-app restart through one environment marker, _KIROCREW_ENV_OWNED_KEYS. The record is Python module state, and os.execv keeps os.environ but resets module state, so without it the restarted gateway would find every .env key already set, treat each one as inherited, and never pop any of them on a later removal. The marker rides the existing exec-successor channel, platform_compat.keep_for_reexec, the same one the managed-service launch marker uses; no new pre-exec hook is added. Every change to the record (note_env_owned_key, discard_env_owned_key, reset_env_owned_keys, and the boot-time adopt_env_owned_keys_from_reexec) hands keep_for_reexec the owned key NAMES (comma-joined, no values; an empty marker when nothing is owned). The marker is never in this process's own os.environ: reexec_launcher / reexec_python_module write it there only on the line that already applies _KEPT_FOR_REEXEC, right before the exec. In the successor, the first load_credentials(propagate=True) (at the latest the one in run_gateway, which runs before the orchestrator is built and before anything in that function spawns a process) calls adopt_env_owned_keys_from_reexec, which pops the marker from os.environ and restores the record, so spawned children never inherit it. The only callers of those two seams are the gateway's update/restart paths, and a failed exec there exits the process (exit_after_failed_restart_exec) rather than leaving it running with the marker set.
  • The applier decides per os.environ ENTRY rather than per .env spelling. On Windows (case-insensitive os.environ) every spelling of a key (HTTPS_PROXY / https_proxy) is grouped and resolved once, to the first non-empty spelling in .env order (boot's setdefault precedence), 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.
  • The watcher's diff (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.
  • The Weixin QR sign-in writes its token through the same apply_env_credential_changes as the dashboard channel writer, so it records .env ownership (a later removal of the line revokes it in-process) and keeps the Docker scrub guard.
  • The Weixin QR sign-in's .env + config.json commit runs under live.hold() (like every sibling channel saver) and through drained_to_thread, so the watcher never restarts Weixin between the two writes and a cancelled request never releases the hold mid-write.
  • The boot .env record is tied to the file it was read from: the watcher adopts it only for the same .env, so a record from another data home is never taken as its baseline.
  • Teams: closing the client on a credential removal also clears its bound webhook handler and returns 503 for a request already past the close check, because the inbound route stays registered independently of the client. A tenant-only edit restarts Teams through a new restart_credentials descriptor field. The tenant gets its own descriptor field rather than joining credentials because readiness (channels.py channel_readiness) reports any absent credentials key as missing, and an unset tenant is the supported multi-tenant mode.
  • 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. maybe_start_teams no longer binds it before the connect completes, so a restart superseded mid-connect never exposes its handler (the route answers 503 until then).
  • Slack: the restart-needed notice matches credential keys by canonical entry name, the same rule as registry.changed_credential_keys, so a lowercase .env Slack key on Windows still gets the notice.
  • The .env writers match lines by canonical entry name (_env_name_key), not literal spelling: the dashboard channel writer (_write_env_updates_locked) and the Weixin sign-in's _write_env_secret / _read_env_value / _delete_env_key. Before this, on Windows a hand-typed slack_bot_token= line was left in place and the saved SLACK_BOT_TOKEN= was appended after it, so the first-non-empty-spelling rule above put the OLD token back in force while the save reported success. Now a save rewrites the first case-equivalent spelling under the declared name and drops the rest, a clear removes every spelling, and the rollback read returns the spelling boot actually propagates. On POSIX the canonical name is the name itself, so a lowercase line is a different variable and is left alone.

This supersedes #23569, and before it #23027, #23470, #23491 and #23514 (all closed). It is one commit on current main (the final #23569 diff plus the First Principles fix below, squashed on a new branch), plus a second commit for the GPT 6.1 WeChat rollback finding below, so PR Hygiene's two-commit limit is met without a force-push. It folds in every review fix from those PRs, including the structural-guard registrations, the Weixin sign-in hold, and scoping the boot .env record.

Carried over from #23569

  • Maintainer HOLD (policy-sensitive), raised at 609fb58fbc. The HOLD found no definite defect. It reserves the credential and Teams webhook admission changes for a human reviewer, and it was waiting on Sensitive Change Review. The disposition posted there explains both changes in plain words, answers the two advisory notes (the _KIROCREW_ENV_OWNED_KEYS marker is described above, and restart_credentials is explained under Teams), and says the HOLD still stands. This PR does not clear it: a maintainer still needs to review the credential and Teams admission changes, and Sensitive Change Review still needs to complete here.
  • GPT 6.1 Windows case-equivalent .env finding (channel_config_writes.py): fixed. The writer bullet above covers it. GPT 6.1 reported no findings at fix(env): reload .env credential changes without a gateway restart #23569's last head, 5e779ea66e.
  • GPT 6.1 WeChat rollback finding at 383ae6675e (weixin_qr.py:182): fixed in the second commit. A failed config.json write rolled back by restoring one snapshotted value, but the sign-in had already collapsed every Windows case spelling of the key into one line. So an empty lowercase alias ahead of the working token (boot skips the empty one) came back as the only line, and the working token was lost. The rollback now restores the exact .env text, BOM included, snapshotted under the shared .env lock the commit already holds. _read_env_value now returns the first non-empty spelling, the one boot propagates.
  • First Principles BLOCK at 5e779ea66e (a second exec-successor hook beside keep_for_reexec): fixed here as the verdict's Subtraction asked. _carry_env_ownership_across_reexec and its three call sites are deleted, and serialize_env_owned_keys_for_reexec is gone with them. The ownership record now hands its marker to keep_for_reexec, so platform_compat_runtime.py and platform_compat.py are byte-identical to main. The verdict's other note, that restart_credentials has one consumer, is answered under Teams above.

Backwards compatibility

Compatible: boot still seeds .env with setdefault, every key .env accepted before is still accepted, and PATH entries 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_SCRUBBED a dashboard save no longer writes credential keys into os.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, test/test_slack_config_handlers.py::test_windows_save_replaces_a_lowercase_spelling_of_the_key (head a502a7b)

  • test/test_env_credential_hot_reload.py: an env-only edit dispatches credentials.<KEY> and applies os.environ; a failed apply leaves the baseline so a repair re-applies the rotation; an undecodable or wide-encoded .env is retried rather than read as every key cleared; a removal pops only what .env propagated; a .env PATH 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-folding os.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 .env PATH line appends absolute directories behind the existing PATH, deduped; relative and unexpanded entries are dropped with a warning; ~ and ~otheruser still expand through os.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; a confirmed sign-in persists while the watcher is held and a cancelled one keeps the hold until the write finishes; a boot record from another .env file is refused; on Windows a sign-in replaces a lowercase weixin_token line and the rollback delete removes every spelling, while on POSIX both leave the lowercase name alone; a failed config write restores .env byte for byte on both platforms, including an empty lowercase alias ahead of the working token and a UTF-8 BOM, and _read_env_value skips an empty case spelling on Windows. The Windows rollback cases fail against the previous rollback.
  • test/test_slack_config_handlers.py: on Windows a dashboard save replaces a lowercase spelling of the key, collapses several spellings to one line where the first was, and a clear removes every spelling; on POSIX a lowercase name is left untouched. The five Windows cases fail against the previous writers.
  • test/test_env_credential_hot_reload.py (re-exec): the real reexec_launcher seam, with os.execv stubbed, hands the successor a marker naming both owned keys, the marker is never in the live process's own environment, and the successor's first load_credentials adopts it and pops both keys on a later removal; a re-exec with nothing owned, or after an owned key was discarded, still carries an empty marker. Both tests fail if the ownership record stops calling keep_for_reexec.
  • test/conftest_resets.py: the boot .env record and the ownership set are reset around every test, so neither leaks across an xdist worker. The _KEPT_FOR_REEXEC reset now binds one fresh dict in both platform_compat and platform_compat_runtime. Before, it rebound only the facade name, while keep_for_reexec and the reexec_* seams write to the runtime module's dict, so a value kept in one test could reach a later test's stubbed exec.
  • test/test_teams_gateway.py: maybe_start_teams registers 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.

On head a502a7be15 (Python 3.12): squashed to one commit and rebased onto current main. Fixes three CI failures from the previous head: added _keep_env_owned_keys_for_reexec_locked to config.loader's facade manifest; the re-exec marker test now patches IS_WINDOWS through the platform_compat facade instead of one owner module; main's test_the_badge_never_breaks_boot now expects load_credentials(propagate=False), the post-boot read this PR introduces. Locally: TestUnreadyChannelBadge and both facade-mirror guards pass; black/isort/flake8 clean; black gate passes. The earlier full local runs on 383ae6675e (1555 passed) and 46233c0224 (177 passed) covered the same production code.
Also on a502a7be15: the WeChat sign-in rollback no longer overwrites the whole .env with its snapshot. If nothing else touched the file since the sign-in's write, it puts the snapshot back byte for byte; otherwise it restores only the WEIXIN_TOKEN entry's prior lines into the current file, keeping unrelated edits, and refuses (logged) if that entry itself was changed meanwhile. New tests: test_rollback_keeps_an_unrelated_edit_saved_after_the_token_write, test_rollback_refuses_when_the_token_entry_was_changed_independently; all 47 tests in test/test_weixin_qr.py pass.
And on a502a7be15: the rollback snapshot and the published text now both come from _write_env_secret's own single read (it returns (prior, published)), so the snapshot holds every edit the write kept and no read of .env runs between the token write and the rollback-protected config write. New tests: test_write_env_secret_returns_its_own_read_and_what_it_published, test_write_env_secret_on_an_absent_file_reports_no_prior, test_a_read_failure_after_the_token_write_cannot_escape_the_commit; all 50 tests in test/test_weixin_qr.py pass, and the 104 in test/test_env_file_bom.py and test/test_env_staged_publish.py.
Fix on a502a7be15: reworded one test docstring in test/test_weixin_qr.py to present tense so the Comment History Gate passes. No code change.
And on a502a7be15: a .env edit to the Slack owner (KIROCREW_OWNER_ID) now logs the same restart-needed notice as a Slack token edit. The owner is read once at start into _owner_id and the owner allowlist, so a replaced or removed owner stays authorized until restart (GPT 6.1 finding at channel_lifecycle.py:644). Covered by test/test_channel_boot_hot_reload.py::TestSlackCredentialChangeWarns::test_an_owner_change_logs_the_restart_needed_notice.
Rebased on a502a7be15: onto current main (includes #23870, the macOS test_acp_elicitation_runtime fix). Still one commit; no change to this PR's diff.
Fix on a502a7be15: the WeChat sign-in .env writes publish UTF-8 bytes instead of text, so Windows no longer newline-translates them. The rollback compares the file with what it published and restores the snapshot byte for byte; on Windows the text-mode write turned \n into \r\n, so the comparison never matched and a CRLF snapshot would be written back as \r\r\n. Covered by test/test_weixin_qr.py::test_atomic_write_secret_lands_byte_for_byte and ::test_a_failed_commit_restores_crlf_line_endings_byte_for_byte; also rebased onto current main.

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

Swept (case-equivalent .env spellings): git grep -nE 'split("=", 1)[0]|partition("=")' -- src/
Sibling: src/kiro_crew/dashboard/handlers/weixin_qr.py -- changed here
Sibling: src/kiro_crew/cli_setup.py -- tracked in #23768

Swept (exec-successor hand-off): git grep -nE "keep_for_reexec|_KEPT_FOR_REEXEC|os.execv" -- src/
Sibling: src/kiro_crew/config/loader_builders.py -- not affected -- already uses keep_for_reexec, the channel the ownership marker now shares
Sibling: src/kiro_crew/platform_compat_runtime.py -- not affected -- identical to main; the only pre-exec write is the existing os.environ.update(_KEPT_FOR_REEXEC)

Pattern harvest

Not generalizable: the defect was one missing watcher input (.env alongside config.json), not a repeated code shape a rule could catch.

Checklist

  • At most two commits (this PR has two), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable) — docs/system-specs/modules/config.md
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision c61b937bc96f5e0f25a6b2599639a9507186a2f3 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of c61b937bc96f5e0f25a6b2599639a9507186a2f3 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: .env is now checked in the same watcher poll that already reloads config.json, and both writers now share one function for applying changes, so the fix targets the cause rather than the symptom.

Notes

  • _write_env_secret's return type changed, but its callers outside the patch (test_env_staged_publish.py, test_env_file_bom.py) ignore the return value. The ## Backwards compatibility section falls after the description's truncation point, so I could not check it against them.
  • _KIROCREW_ENV_OWNED_KEYS is a new contract between the gateway and its re-exec successor. Keep it limited to the keep_for_reexec path, so a second writer of the ownership record doesn't appear later.

[DESIGN-REVIEWED] c61b937

Description read

[DESCRIPTION-READ] 4ecd84df4740e12204d55bdcf5a7529018324e1b1cbdd8f48115635a727aced6

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of c61b937bc96f5e0f25a6b2599639a9507186a2f3 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The Windows case-folding added to the two dashboard writers rides along, and so does the Weixin rollback rewrite it forces.

Notes

  • Item 7 — rides along, oversized: the description says "every case-equivalent spelling of an updated key is replaced". That fixes a Windows writer defect that predates this PR and has no linked report, and it is what forces the rewrite of the Weixin rollback (_restore_env_entry, _env_entry_lines, _env_file_text). Subtraction: drop the _same_env_entry / canon_updates matching in weixin_qr.py and channel_config_writes.py, and restore the single-value prior rollback; defer the writer fix to its own issue.
  • Item 6 — one consumer, generalized: ChannelDescriptor.restart_credentials is a tuple field, and only Teams (channels.py:113) sets it, with one key. Grep for restart_credentials in src/ found 1 constructing site. Subtraction: none smaller without folding a Teams special case into changed_credential_keys, so leave it.

What this change ships

Inventory (8 items) — 5 justified

Intent: an operator's .env credential edit takes effect on a running gateway without a full restart. This is a FIX (#22450).

  1. A hand edit to .env is applied live and restarts only the affected channel — justified
  2. A Slack token change logs a "run kirocrew restart" notice — justified
  3. Removing a .env line revokes only credentials .env itself set, including after an in-app restart (_KIROCREW_ENV_OWNED_KEYS marker) — justified
  4. Dashboard and Weixin credential saves go through the shared applier and respect the Docker scrub — justified
  5. After boot, credential reads no longer re-seed os.environ — justified
  6. Editing only the Teams tenant restarts Teams — one consumer, generalized
  7. On Windows, dashboard writers collapse every case-variant spelling of a key, and the Weixin rollback is rewritten to match — rides along, oversized
  8. A closed Teams client returns 503 and drops its webhook handler — rides along

[FIRST-PRINCIPLES-REVIEWED] c61b937

Description read

[DESCRIPTION-READ] dd0675ac22fa58f50fdef4258cf106749c685cb9bd2b54f16f8e641412599a5b

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of c61b937bc96f5e0f25a6b2599639a9507186a2f3 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] c61b937

False positive or not applicable? A repository writer can comment:
/ai-review override gpt c61b937bc96f5e0f25a6b2599639a9507186a2f3 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed c61b937bc96f5e0f25a6b2599639a9507186a2f3 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] c61b937

Verdict parsed from the review's SHA-scoped output markers for commit c61b937bc96f5e0f25a6b2599639a9507186a2f3.

False positive or not applicable? A repository writer can comment:
/ai-review override fable c61b937bc96f5e0f25a6b2599639a9507186a2f3 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 24, 2026
@RohanK6 RohanK6 closed this Oct 24, 2026
@RohanK6 RohanK6 reopened this Oct 24, 2026
@RohanK6
RohanK6 force-pushed the env-hotreload-22450-v5 branch 2 times, most recently from 910a698 to a8f7eeb Compare October 24, 2026 23:51
@RohanK6 RohanK6 closed this Oct 25, 2026
@RohanK6 RohanK6 reopened this Oct 25, 2026
@RohanK6
RohanK6 force-pushed the env-hotreload-22450-v5 branch 2 times, most recently from 6a0423d to 6f25202 Compare October 25, 2026 00:34
@RohanK6 RohanK6 closed this Oct 25, 2026
@RohanK6 RohanK6 reopened this Oct 25, 2026
@RohanK6
RohanK6 force-pushed the env-hotreload-22450-v5 branch from 6f25202 to d60449a Compare October 25, 2026 01:08
@RohanK6 RohanK6 closed this Oct 25, 2026
@RohanK6 RohanK6 reopened this Oct 25, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 25, 2026
@RohanK6
RohanK6 force-pushed the env-hotreload-22450-v5 branch 2 times, most recently from 2b40ed5 to 07b44ff Compare October 25, 2026 01:53
@RohanK6 RohanK6 closed this Oct 25, 2026
@RohanK6 RohanK6 closed this Oct 25, 2026
@RohanK6 RohanK6 reopened this Oct 25, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 25, 2026
@RohanK6
RohanK6 force-pushed the env-hotreload-22450-v5 branch from 3a40c71 to a502a7b Compare October 25, 2026 12:16
@RohanK6 RohanK6 closed this Oct 25, 2026
@RohanK6 RohanK6 reopened this Oct 25, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 25, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at a502a7b: this needs a human reviewer.

The PR changes how .env credentials get into and out of the running gateway's environment. The new apply_env_credential_changes sets and pops credential keys live, decides which keys .env owns, and keeps the Docker scrub carve-out (loader_credentials.py#L549-L752). A new _KIROCREW_ENV_OWNED_KEYS marker survives os.execv (#L407-L486). The PR also rewrites the dashboard and Weixin credential writers and changes when the Teams webhook handler is bound. Credential and webhook changes like these are reserved for a human reviewer. I found no concrete defect in the parts I read, but I did not audit every file.

Three current-head AI notes have no reply:

  • First Principles item 7: the ownership set and re-exec marker are oversized; the lane proposes popping a removed key only when os.environ.get(k) == old[k].
  • First Principles item 8: the Windows case-variant collapse and its rollback rewrite have no cited defect.
  • Design: add a test that the marker is adopted before any child spawns.

To clear: a maintainer reviews the credential paths and Sensitive Change Review records that check, and the author answers each note (fix, rebut, or a linked issue).

— crew-pr-reviewer (r126)

…22450)

Edits to $KIROCREW_HOME/.env took effect only after a full gateway
restart: the live config watcher fingerprinted config.json only. The
watcher now reconciles .env in the same poll cycle, applies the diff to
os.environ through one applier (honouring the Docker credentials scrub
and the PATH carve-out), pops only keys .env itself owns, and restarts
only the channel whose credential changed. Slack, which has no
in-process restart, logs a "run kirocrew restart" notice.

The .env ownership record is carried across an in-app re-exec through
the existing keep_for_reexec channel, so a post-restart .env removal
still pops what .env owned. The dashboard channel writer and the Weixin
sign-in writer match .env lines by canonical os.environ entry name, so
on Windows a lowercase spelling of a saved key cannot keep an old token
in force. POSIX stays case-sensitive.

Supersedes #23569.

Fixes #22450
@RohanK6
RohanK6 force-pushed the env-hotreload-22450-v5 branch from a502a7b to c61b937 Compare October 28, 2026 03:03
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Oct 28, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Recommend HOLD at c61b937. This needs a human reviewer.

The PR changes how .env credentials get into and out of the running gateway's environment. apply_env_credential_changes sets and pops credential keys live, decides which keys .env owns, and keeps the Docker scrub carve-out. The _KIROCREW_ENV_OWNED_KEYS marker carries that ownership across os.execv (#L417-L486). The PR also rewrites the dashboard and Weixin credential writers and changes when the Teams webhook handler is bound and when it answers 503. Changes like these are reserved for a person. In the parts I read I found no defect, and CI is green.

One current-head note has no reply. First Principles item 7 says the Windows case-variant collapse in both writers, and the Weixin rollback rewrite it forces, ride along without a linked report, and suggests deferring them to their own issue. Please keep it with a short rationale, or split it out.

To clear: a maintainer reviews the credential and Teams admission paths, and the author answers item 7.

— crew-pr-reviewer (r131)

@RohanK6

RohanK6 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author
  • Item 7: Windows case-variant collapse in the two writers and the Weixin rollback ride along

Rebutted, kept: this is not a separate pre-existing fix. This PR makes dashboard and Weixin saves take effect live through apply_env_credential_changes, which resolves each Windows entry to the first non-empty spelling in .env order.
Without spelling-aware writers, a save appends SLACK_BOT_TOKEN= after a hand-typed slack_bot_token= line, and the new live apply keeps the OLD token in force while the save reports success. That defect is in the path this PR adds.
GPT 6.1 raised it on #23569 (channel_config_writes.py) and it was fixed there; the Weixin rollback rewrite is the follow-on GPT 6.1 finding at 383ae6675e (weixin_qr.py:182), where a one-value rollback lost the working token.
Evidence: the five Windows cases in test/test_slack_config_handlers.py and the lowercase weixin_token cases in test/test_weixin_qr.py fail against the previous writers. On POSIX the canonical name is the name itself, so nothing changes there.

@iamwhatever

Copy link
Copy Markdown
Contributor

Recommend HOLD (policy: human review) at c61b937bc96f5e0f25a6b2599639a9507186a2f3.

The PR changes how .env credentials enter and leave the running gateway's environment. apply_env_credential_changes sets and pops credential keys live, decides which keys .env owns, and keeps the Docker scrub carve-out. The _KIROCREW_ENV_OWNED_KEYS marker carries that ownership across os.execv (#L407). The PR also rewrites the dashboard and Weixin credential writers (weixin_qr.py#L252) and changes when the Teams webhook handler is bound and when it answers 503. The user's standing rule reserves credential and webhook-admission changes for a person.

Since r131 the author has answered First Principles item 7 with an evidence-backed rebuttal. Without spelling-aware writers, a save on Windows would append a second spelling, and the new live apply would keep the old token while reporting success. The cited tests fail against the old writers. I accept that reply. Every AI lane passes or was skipped at this head, all checks are green, and the branch merges cleanly with main. In the parts I read I found no defect, but I didn't audit all 45 files.

To clear: a maintainer reviews the credential, re-exec ownership and Teams admission paths.

— crew-pr-reviewer (r134)

@iamwhatever
iamwhatever enabled auto-merge (squash) October 29, 2026 15:51
@iamwhatever
iamwhatever merged commit 436b4ad into main Oct 29, 2026
116 checks passed
@iamwhatever
iamwhatever deleted the env-hotreload-22450-v5 branch October 29, 2026 15:52
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.env changes require a full gateway restart (no hot-reload)

2 participants