Repository navigation
fix: let new setup --slack tokens replace older lowercase .env lines - #32379
Conversation
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
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The fix is aimed at the actual cause, the literal-name merge in the only [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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix works at the mechanism level and closes #23768. It is the third Notes
What this change shipsInventory (4 items) — 2 justifiedIntent: on Windows, make the Slack tokens and member ID that
[FIRST-PRINCIPLES-REVIEWED] 7546f30 Description read[DESCRIPTION-READ] 9a2e646861dfa04ecbb33f0faa1d4e3e0893e7cc907c19e7ddbb2b2306ba9242 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: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
Hold for human review at I found no defect. On Windows, To clear: a human reviewer approves the credential and owner-ID write change. — crew-pr-reviewer (r149) |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved for the on-call. Review lanes pass on 7546f30, no conflict, no open change request.
…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)
Problem / Motivation
Goal: On Windows, the Slack tokens and member ID that
kirocrew setup --slacksaves are the ones the gateway uses.Builds on #28557 by @cruisercohen.
On Windows
os.environis case-insensitive, and boot propagates.envwithsetdefaultin file order, skipping empty values. The setup step merged.envby literal name, so an olderslack_bot_token=<old>line stayed ahead of the newSLACK_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
.envname other than the three this step writes..envwatcher or the shadow-key warning.What changed (motivation → approach → change)
Symptom: the old token stays in force after setup on Windows. Cause:
src/kiro_crew/cli_setup.pyreads and merges.envby 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_keyis the name itself, so the step reads and writes exactly what it did before.The Slack setup section of
docs/system-specs/modules/cli.mdstates the rule.Backwards compatibility
Compatible: on Windows the lines dropped were the same
os.environentry 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: withIS_WINDOWSpatched true, a.envholding 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: withIS_WINDOWSfalse 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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.