Skip to content

fix: let new setup --slack tokens replace older lowercase .env lines - #32379

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/23768-setup-slack-env-fold
Nov 7, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/23768-setup-slack-env-fold

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On Windows, the Slack tokens and member ID that kirocrew setup --slack saves are the ones the gateway uses.

Builds on #28557 by @cruisercohen.

On Windows os.environ is case-insensitive, and boot propagates .env with setdefault in file order, skipping empty values. The setup step merged .env by literal name, so an older slack_bot_token=<old> line stayed ahead of the new SLACK_BOT_TOKEN=<new> line and kept the old token in force, with no error shown. The same held for the app token and the owner ID.

Why it matters

A Windows operator who re-runs the Slack step to replace a revoked or wrong token sees "Credentials saved", but the gateway and every child process keep the old value, so Slack stays broken with no clue why. The issue thread has this reproduced on a Windows host.

Not a goal

  • Changing any .env name other than the three this step writes.
  • Changing boot propagation, the live .env watcher or the shadow-key warning.
  • Any change on Linux or macOS, where the two spellings are separate variables.

What changed (motivation → approach → change)

Symptom: the old token stays in force after setup on Windows. Cause: src/kiro_crew/cli_setup.py reads and merges .env by literal name, so a differently-cased line survives ahead of the new one. Change: when the step reads .env, a small helper, _fold_env_spellings, folds every spelling of the app token, bot token and owner ID into the canonical name. It matches names with _env_name_key, the helper #23836 used for the dashboard and Weixin writers. The kept line holds the value boot would have used (the first non-empty spelling). So the prompt shows the value in force, pressing Enter keeps it, and the save writes one line per entry. On POSIX _env_name_key is the name itself, so the step reads and writes exactly what it did before.

The Slack setup section of docs/system-specs/modules/cli.md states the rule.

Backwards compatibility

Compatible: on Windows the lines dropped were the same os.environ entry as the canonical line written in their place; on POSIX the merge is unchanged.

Removes nothing: the only lines dropped are other spellings of an entry the same save rewrites, and the value in force is carried onto the canonical line.

Tests

  • test/test_cli_setup_slack.py::TestOtherSpellingsOfASavedName::test_on_windows_the_new_values_replace_every_spelling: with IS_WINDOWS patched true, a .env holding lowercase app, bot and owner lines ends with one line per entry holding the new values, and an unrelated key survives.
  • test_on_windows_enter_keeps_the_owner_in_force_behind_an_empty_spelling: with an empty canonical owner line ahead of a populated lowercase one, the prompt shows the populated value, Enter keeps it, and the file ends with one owner line holding it.
  • test_on_posix_a_differently_cased_name_is_left_alone: with IS_WINDOWS false the lowercase lines stay as written, in place.
  • pytest -n 4 test/test_cli_setup_slack.py test/test_cli_setup.py: 77 passed.

Proof: PROVEN test/test_cli_setup_slack.py::TestOtherSpellingsOfASavedName::test_on_windows_the_new_values_replace_every_spelling, test/test_cli_setup_slack.py::TestOtherSpellingsOfASavedName::test_on_windows_enter_keeps_the_owner_in_force_behind_an_empty_spelling (head 7546f30)

Manual verification

Not run on a Windows host. The issue thread has a Windows reproduction of the failure on main; the unit tests run the real setup step with the Windows key rule patched in.

Related Issues

Closes #23768

Sibling sweep

Swept: git grep -ln "publish_env(" -- src/ and git grep -n _env_name_key -- src/
Sibling: src/kiro_crew/dashboard/handlers/weixin_qr.py -- not affected -- already matches lines by _env_name_key
Sibling: src/kiro_crew/dashboard/messaging_api/channel_config_writes.py -- not affected -- already matches lines by _env_name_key
Sibling: src/kiro_crew/secrets/migrate.py -- not affected -- rewrites each existing line in place under its own name, never adds a second spelling

Pattern harvest

Rule candidate: review-prompt
Pattern: a .env writer that merges lines by literal name instead of _env_name_key

Checklist

  • At most two commits (one is the norm), 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)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

On Windows os.environ is case-insensitive and boot keeps the first
non-empty spelling of a name in .env. The setup step read and merged
.env by literal name, so an older slack_bot_token line stayed ahead of
the new SLACK_BOT_TOKEN line and kept the old token in force.

The step folds every spelling of the app token, bot token and owner ID
into the canonical name, matched with _env_name_key and carrying the
value in force, so the prompt shows that value and the save replaces
it. On POSIX the names are separate variables and nothing changes.

Builds on #28557.

Closes #23768
@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 7, 2026 14:17
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 7546f30e58f76784595ab60a931b0c799dbcc7ab 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 Nov 7, 2026

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks. The fix is aimed at the actual cause, the literal-name merge in the only .env reader the Slack step uses, and it reuses the existing _env_name_key rule. On POSIX nothing changes.

[DESIGN-REVIEWED] 7546f30

Description read

[DESCRIPTION-READ] 801a73ec67711cca539e6ed332b41742fb4137c56d7e87f4919047de3b81d491

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 Nov 7, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 7546f30e58f76784595ab60a931b0c799dbcc7ab — 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 fix works at the mechanism level and closes #23768. It is the third .env writer to do its own case-folding, which is worth a note but is reversible.

Notes

  • Item 1 — duplicate (note): live = next((pairs[k] for k in spellings if pairs[k]), "") restates the rule "the first non-empty spelling wins". That rule is already written as _effective_entry_values in config/loader_credentials.py:488. Subtraction: replace the live line with _effective_entry_values(pairs).get(canon, "").
  • Item 1 — symptom-level (note): grepping _env_name_key( across .env merge writers gives 3 sites that each fold spellings their own way: dashboard/messaging_api/channel_config_writes.py:463, dashboard/handlers/weixin_qr.py:152, and now cli_setup.py:771. _write_env_updates_locked(ep, updates) already does this merge by canonical entry for the dashboard's save of these same Slack keys. Subtraction: drop _fold_env_spellings and the dict-rebuild merge at cli_setup.py:932-960, and have the step call that existing locked writer under the lock it already holds.

What this change ships

Inventory (4 items) — 2 justified

Intent: on Windows, make the Slack tokens and member ID that kirocrew setup --slack saves the ones the gateway actually uses. This is a FIX.

  1. On Windows, re-running the Slack step replaces old lowercase app-token, bot-token and owner lines with the new values — duplicate (note)
  2. The prompt hint shows the value boot would actually use, and pressing Enter keeps it — justified
  3. On Windows, the other spellings of those three names disappear from .env on save — symptom-level (note)
  4. The cli.md Slack setup section states the folding rule — justified

[FIRST-PRINCIPLES-REVIEWED] 7546f30

Description read

[DESCRIPTION-READ] 9a2e646861dfa04ecbb33f0faa1d4e3e0893e7cc907c19e7ddbb2b2306ba9242

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 Nov 7, 2026

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 7546f30

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

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

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 7546f30

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

@bolichen97
bolichen97 enabled auto-merge (squash) November 7, 2026 14:44
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 7, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Hold for human review at 7546f30e58f76784595ab60a931b0c799dbcc7ab. The change decides which Slack tokens and which owner ID stay in force in .env, and credential and identity changes are reserved for a person.

I found no defect. On Windows, _fold_env_spellings keeps the value boot would use under the canonical name and drops the other spellings of the same entry (cli_setup.py#L763). It applies only to the three Slack names (#L797). On POSIX _env_name_key is the identity, so nothing changes there. The First Principles notes are refactor suggestions and do not block. All checks are green.

To clear: a human reviewer approves the credential and owner-ID write change.

— crew-pr-reviewer (r149)

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for the on-call. Review lanes pass on 7546f30, no conflict, no open change request.

@KiroCrewCaptain
KiroCrewCaptain merged commit eae2b50 into main Nov 7, 2026
96 of 97 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/23768-setup-slack-env-fold branch November 7, 2026 19:42
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 7, 2026
buluoray pushed a commit that referenced this pull request Nov 7, 2026
…32379)

On Windows os.environ is case-insensitive and boot keeps the first
non-empty spelling of a name in .env. The setup step read and merged
.env by literal name, so an older slack_bot_token line stayed ahead of
the new SLACK_BOT_TOKEN line and kept the old token in force.

The step folds every spelling of the app token, bot token and owner ID
into the canonical name, matched with _env_name_key and carrying the
value in force, so the prompt shows that value and the save replaces
it. On POSIX the names are separate variables and nothing changes.

Builds on #28557.

Closes #23768

(cherry picked from commit eae2b50)
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.

kirocrew setup --slack leaves an older lowercase .env token in force on Windows

3 participants