Skip to content

fix(setup): replace every spelling of a Slack name the setup wizard writes - #28557

Closed
cruisercohen wants to merge 1 commit into
mainfrom
fix/23768-setup-slack-env-case
Closed

cruisercohen wants to merge 1 commit into
mainfrom
fix/23768-setup-slack-env-case

Conversation

@cruisercohen

@cruisercohen cruisercohen commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On Windows, new Slack credentials saved by the setup wizard's Slack step are the ones the gateway uses.

On Windows os.environ is case-insensitive, and boot propagates .env with setdefault in file order. The wizard merged .env by literal name, so an older lowercase bot line (slack_bot_token=) stayed ahead of the new SLACK_BOT_TOKEN= line and kept the old value in force, with no error shown.

Why it matters

A Windows operator who re-runs the Slack step to replace a revoked or wrong value sees a success message, but the gateway and every child keep the old value, so Slack stays broken with no clue why.

Not a goal

  • Changing what the wizard reads from .env or shows at its prompts.
  • Changing the loader's propagation or shadow-key warning.
  • Any change on Linux or macOS, where the two spellings are separate variables.

What changed (motivation → approach → change)

Symptom: old value still in force after setup on Windows → cause: the merge dict in src/kiro_crew/cli_setup.py is keyed by literal name, so a differently-cased line survives ahead of the new one → change: a new _pop_env_entry helper removes every spelling of an entry, matched with _env_name_key (the helper #23836 used for the dashboard and Weixin writers), before the app, bot and owner ID entries are written. For the owner ID the live value (the first non-empty spelling, as boot propagates it) is carried over under the canonical name, so the existing keep/drop logic for a rejected member ID still sees it. On POSIX _env_name_key is the literal name, so behavior there is unchanged.

Backwards compatibility

Compatible: on Windows the lowercase lines it drops were the same os.environ entry as the canonical ones it writes; on POSIX nothing changes.

Removes nothing: the only lines dropped are other spellings of an entry that is rewritten in the same save, so no value a reader could see is lost.

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_the_live_value_is_the_first_non_empty_spelling and test_a_rejected_member_id_keeps_the_saved_owner_behind_an_empty_spelling: an empty lowercase owner line ahead of a populated canonical one does not erase the saved owner when the typed member ID is rejected.
  • test_on_posix_a_differently_cased_name_is_left_alone: with IS_WINDOWS False the lowercase lines are kept as separate variables.
  • pytest -n0 on test_cli_setup_slack.py, test_cli_setup.py, test_env_file_bom.py, test_env_staged_publish.py: 179 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_a_rejected_member_id_keeps_the_saved_owner_behind_an_empty_spelling (head 901c9ee)

Manual verification

Not run on a Windows host. The issue thread has a Windows reproduction of the failure on main; the unit test reproduces the same merge with the Windows key rule.

Related Issues

Fixes #23768

Sibling sweep

Swept: git grep -nE 'partition("=")' -- 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

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

@cruisercohen
cruisercohen requested review from a team and KiroCrewCaptain as code owners November 2, 2026 21:38
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 2, 2026
@cruisercohen
cruisercohen force-pushed the fix/23768-setup-slack-env-case branch from 827c60f to 619c707 Compare November 2, 2026 21:43
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 901c9ee8ac071a254e0f56b5f81b92bacfc0cd32 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 2, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the fix reuses the existing _env_name_key rule that the sibling .env writers already follow, the .env change is limited to the three entries the wizard rewrites, and the behavior on POSIX is unchanged.

[DESIGN-REVIEWED] 901c9ee

Description read

[DESCRIPTION-READ] 9fce4835044b8b8be0276fa63a01997ebd9c86d62958301fc3c40a328c9c62e0

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 2, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 901c9ee8ac071a254e0f56b5f81b92bacfc0cd32 — 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 is aimed at the mechanism (the literal-name merge in the setup wizard's only .env writer), and the two other dashboard .env writers already match names by _env_name_key.

What this change ships

Inventory (4 items) — 4 justified

Intent: On Windows, a re-run of the Slack setup step must leave the newly typed tokens in force, not the old lowercase lines. This is a FIX (#23768).

  1. On Windows, re-running Slack setup replaces older lowercase app and bot token lines instead of leaving them ahead of the new ones — justified
  2. On Windows, an existing lowercase owner-ID line is rewritten under the canonical name, keeping the first non-empty value — justified
  3. When the typed member ID is rejected, a saved owner behind an empty lowercase line is still found and re-checked — justified
  4. New private helper _pop_env_entry in cli_setup.py, called three times in one function — justified

[FIRST-PRINCIPLES-REVIEWED] 901c9ee

Description read

[DESCRIPTION-READ] e811851eaba86fec589a2ca0c1cbee62a8c843f883b584fc1cb9cce5655bd28c

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 2, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 901c9ee

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

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

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 901c9ee

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

@cruisercohen
cruisercohen force-pushed the fix/23768-setup-slack-env-case branch from 619c707 to 0c5d339 Compare November 2, 2026 22:27
@cruisercohen

Copy link
Copy Markdown
Contributor Author

GPT 6.1 finding (cli_setup.py, preserve the first nonempty saved owner value): confirmed and fixed in 0c5d339. _pop_env_entry now returns the first NON-EMPTY spelling, matching boot's propagation (loader_config skips empty values; _effective_entry_values uses the same rule), while still removing every spelling. New tests: test_the_live_value_is_the_first_non_empty_spelling (helper) and test_a_rejected_member_id_keeps_the_saved_owner_behind_an_empty_spelling (end to end on the Windows key rule: empty lowercase owner line, populated canonical line, typed member ID rejected, saved owner kept). Both fail without the change; prove.py PROVEN.

@cruisercohen
cruisercohen force-pushed the fix/23768-setup-slack-env-case branch from 0c5d339 to 901c9ee Compare November 2, 2026 23:01
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 3, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

[operator: bolichen97] Continuing this in #32379; thanks for the start.

KiroCrewCaptain 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
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)
@iamwhatever

Copy link
Copy Markdown
Contributor

Thanks, @cruisercohen. Closing this as superseded: #23768 was fixed by #32379 ("fix: let new setup --slack tokens replace older lowercase .env lines", merged 2026-11-07). Main now folds every spelling of each Slack name in _fold_env_spellings in src/kiro_crew/cli_setup.py, the same behaviour this PR adds. Please reopen if a case is still missing on latest main.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge

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