Repository navigation
fix(config): one remedy for a UTF-16/UTF-32 .env; refuse the whole channel save - #17012
Conversation
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] a635120 Description read[DESCRIPTION-READ] 67e103351b7d6313c1a821c9b5a631012f26430691daa6260eec04b826d9d04f 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, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check that the maintainers agree to reverse #15596's "config kept" choice for Discord and Telegram. The PR's reason: that write drops the legacy What this change shipsInventory (9 items) — 9 justifiedIntent: a Windows operator with a UTF-16/UTF-32
[FIRST-PRINCIPLES-REVIEWED] a635120 Description read[DESCRIPTION-READ] 8647fe1a1adb3a11816c5ca2868045d9eee91dd056741bb6f4c4f25e7fdb525e That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
0bb6f98 to
7f4f1f3
Compare
|
|
7f4f1f3 to
4031fae
Compare
|
New head 4031fae: the same single commit rebased onto main c6bfd72 (range-diff identical to 7f4f1f3, no content change). Every review lane on 7f4f1f3 was PASS or no findings, so no review span is open. The two reds on 7f4f1f3 were outside this diff:
Rerun on the new head: the 12 channel-save, writer and service test files listed in the description (813 passed, 4 skipped), plus |
4031fae to
eb1c4d8
Compare
f295a5f to
3f790b2
Compare
|
|
|
Head 3f790b2 (base e1999e4): every review lane passes, and both GPT findings on f295a5f are answered above. The test reds on this head are outside this diff:
|
edb3487 to
f138589
Compare
f138589 to
2126371
Compare
Head 2126371 also moves the Teams, Webex and WeCom folder step after the |
… failed channel save A wide .env reads as unset, so service install warned with its append remedy, which leaves the file unreadable after the restart it asks for. The warning now prints the loader's shared decode sentence (file plus "Save it as UTF-8") for a wide file and drops the append, and doctor's kiro key block agrees with the gateway's decode line. The Discord and Telegram saves wrote config.json, dropping the legacy bot_token the gateway falls back to while the .env is unreadable, and kept it when the .env write then failed. They now undo the config commit on any failed .env write with the same shielded rollback block the other channel saves use, under the same live-config hold. A refused save changes nothing on every channel, so the config_kept wording is gone. Closes kirodotdev#17000
…back step Each of the seven channel savers carried its own copy of the shielded .env write, the config rollback and the os.environ sync. The Slack copy had the rollback but not the cancellation guard, so a cancel that arrived after its .env write landed rolled config.json back and split the pair. _write_env_or_roll_back in handlers/messaging.py now holds that step once and every saver calls it. A test pins that no saver writes .env any other way, and the helper's own tests cover a failed write, a cancel after a landed write, a cancel after a failed write and the environment sync. The config spec now lists Discord and Telegram among the savers that roll back under live.hold(), with a hold test for both. The environment-sync test scopes its probe variables with monkeypatch.context() and checks both are gone once that undo has run, the end-to-end saves put back every credential a landed save copies into os.environ, and the cancellation test bounds the waits it releases itself.
2126371 to
a635120
Compare
|
Reviewed, not approving (crew-pr-reviewer). The direction is good: one remedy sentence everywhere, and every channel save now rolls its |
bolichen97
left a comment
There was a problem hiding this comment.
Sensitive change review
Head commit: a635120
- Rule changed: channel .env write failure handling
- Before -> after: config.json write stayed committed when .env write failed -> config is rolled back on a failed .env write
- Worst case if wrong: a failed save leaves previous config (user retries); no secret exposure
- Evidence checked: full diff read; tests on the PR read; Security Scope Review and PR Readiness green on this head; no owner/operator gate added or removed.
- No regression: normal-user workflows unchanged; only the stated path differs.
- How to undo: revert the squash commit.
Follow-up to #15596.
Problem / Motivation
Goal: When the
.envis saved as UTF-16 or UTF-32, every surface gives the one remedy that works (re-save it as UTF-8), and a refused channel save changes nothing, its sidebar folder included. That rollback is the same single step every channel save uses, so no saver can end withconfig.jsonand.envout of step.On origin/main, a wide
.envreads as unset, and two surfaces still act on that wrongly:kirocrew service installwarns thatKIRO_API_KEYwill not reach the service and tells the operator toprintf ... >> <path>. Appending UTF-8 after a UTF-16/UTF-32 byte-order mark leaves a file the gateway still cannot read, so the service is still signed out after the restart.kirocrew doctorprints the gateway's "Save it as UTF-8" line and then that append remedy, which contradicts it.config.jsonbefore the.env. That write drops the legacybot_tokenthe gateway is using while the.envis unreadable, then the.envwrite is refused with 409, so the bot loses its only token on the next restart. The 409 says "your other settings were saved", and the save skips its audit record.Why it matters
Windows operators hit this with PowerShell's default
>/Out-File. Following the install warning leaves them signed out with no further hint, and a Discord or Telegram save that looks harmless removes the working bot token.Not a goal
.envto UTF-8 automatically..envwrite fails; they already undo their config on a 409. The changes on those saves are the two rows in the table below: Teams, Webex and WeCom now file the session folder after the.envwrite, and Slack keeps its config when cancelled after a landed write, as the other four already did..envwrite landed:_write_env_or_roll_backre-raises the cancellation before theos.environsync, so the old token stays in this process until restart. That is the behaviour on origin/main, and the.envandconfig.jsonon disk agree.What changed (motivation → approach → change)
service install/doctorkiro key block, wide.env>>).envwriteconfig.jsonkept (legacybot_tokendropped).envwrite.envwrite landedconfig.jsonrolled back, so the new token sits beside the old settingsundecodable_env_messageinconfig/loader.pyis the one sentence for an unreadable.env: the gateway logs it throughwarn_undecodable_env, andservice/common.pyprints it inheadless_auth_warningwhen_names_defined_in_env_fileraisesEnvFileWideEncodingError. No second wide-encoding helper is added.The Discord and Telegram saves already commit through
_LockedSectionWrite, which can undo exactly the keys it wrote, legacybot_tokendrop included. They now roll that commit back on any failed.envwrite, under the samelive.hold()as the other savers. The session folder is created only after the.envwrite succeeds._write_env_off_looploses itsconfig_keptoption with the wording it selected.The
.envhalf of every channel save (the shielded write, the rollback on failure and theos.environsync) is now one helper,_write_env_or_roll_backinhandlers/messaging.py, which all seven savers call in place of their own copies. A cancellation drains the write and rolls back only when the write itself failed. The Slack copy lacked that guard and rolled back on any cancellation; it now behaves like the others. The config spec lists Discord and Telegram among the savers that hold the watcher across the pair.Backwards compatibility
Compatible: only the failure paths change, and on those the old behaviour was a remedy that did not work and a partial save.
Reader:
src/kiro_crew/dashboard/handlers/messaging.py:_write_env_off_loop(config_keptremoved) -- entry: dashboard -- its only callers with the option were the Discord and Telegram saves, which now call_write_env_or_roll_backinside that rollback block;test_a_wide_env_refuses_the_save_and_leaves_the_config_as_it_was.Reader:
src/kiro_crew/service/common.py:_names_defined_in_env_file(raises for a wide file instead of returning an empty set) -- entry: CLI (service install,doctor) -- both callers,api_key_will_be_droppedandheadless_auth_warning, handle the raise;test_service_warning_sees_a_bom_first_key,test_service_warning_still_fires_for_a_wide_file.Tests
test/test_env_file_bom.py:test_a_wide_file_is_told_to_re_save_not_to_append(UTF-16LE/BE, UTF-32LE/BE): the install warning carries the exact decode sentence and no>>orprintf. Fails on origin/main.test_doctor_prints_one_remedy_for_a_wide_file(same four): the doctor kiro key block says "Save it as UTF-8." and has no>>. Fails on origin/main.test_a_wide_env_refuses_the_save_and_leaves_the_config_as_it_was(Discord, Telegram x four encodings): 409 ending "The .env was not changed.",.envbyte-identical, the channel'sconfig.jsonsection (legacybot_tokenincluded) unchanged, no audit record. Fails on origin/main.test_any_failed_env_write_rolls_the_config_back(Discord, Telegram): anOSErrorfrom the.envwrite also leaves the section unchanged. With the rollback call removed from the Discord and Telegram failure branch, this and the previous test fail (10 cases).test_the_session_folder_is_filed_only_after_the_env_write_lands(Teams, Webex, WeCom x refused, landed): a failed.envwrite files no folder, new or renamed; a landed one renames it. The three refused cases fail on the previous head.test_service_warning_sees_a_bom_first_keynow expects the raise for a wide file.test/test_channel_env_write_off_loop.py:test_every_saver_writes_env_through_the_shared_rollback_step(seven savers): each calls_write_env_or_roll_backonce and never_write_env_off_looporasyncio.shielditself. Fails on the previous head.test_a_failed_write_rolls_back_and_raises,test_a_failed_write_with_no_config_commit_just_raises,test_a_cancelled_save_rolls_back_only_when_the_write_failed(landed, failed),test_a_landed_write_syncs_the_process_environment: the helper's contract. The environment-sync test scopes its probe variables withmonkeypatch.context()and checks both are gone once that undo has run; the end-to-end saves put back every credential a landed save copies intoos.environ; the cancellation test bounds the waits it releases itself.test_the_config_and_env_writes_run_under_the_live_config_hold(Discord, Telegram): both writes run with the watcher held, and the hold is released after.test/test_slack_config_handlers.py:test_slack_cancellation_after_successful_env_write_does_not_rollback_config: a Slack save cancelled after its.envwrite committed keeps the newcommandinconfig.jsonbeside the new token. Fails on the previous head's Slack saver, which rolled the config back.Run: every test file that drives the channel saves or the shared writers (
test_channel_env_write_off_loop,test_config_rmw_preserves_settings,test_config_savers_locked_write,test_discord_config_handlers,test_telegram_config_handlers,test_slack/feishu/wecom_config_handlers,test_handlers_messaging_composition_contract,test_no_config_dir_in_async) plustest_service.pyandtest_env_file_bom.py: 813 passed, 4 skipped on base 782dedd. On the current head (base b13cebd): every channel's config-handler tests,test_channel_env_write_off_loop,test_config_savers_locked_write,test_handlers_messaging_composition_contract,test_env_file_bom,test_config_live,test_serviceandtest_config_load_pipeline, plustest_source_pin_budget: 1120 passed, 3 skipped. After the folder-order change: every test file that namessession_folderorensure_channel_folder(17 files) 1358 passed, 1 skipped, and the channel save files above 1818 passed. After the rebase onto 3343351 (unchanged range-diff): the channel save files,test_channel_env_write_off_loop,test_config_savers_locked_write,test_handlers_messaging_composition_contract,test_env_file_bom,test_service,test_source_pin_budgetandtest_kas_login_loopback: 975 passed, 4 skipped.scripts/local-gate.pyrelated set on the first head: 46431 passed; its 29 failures (test_design_tweak_*, twotest_cli.pydoctor STT tests,test_config_validation,test_auto_improvement_members,test_home_pin_survives_monkeypatch_undo) fail identically on bare origin/main af1eb61 on the same host. black gate, isort, flake8, mypy on the changed files and the comment-history gate pass.Manual verification
N/A -- unit coverage sufficient: the tests drive the real
headless_auth_warning, the doctor kiro key check and the real Discord/Telegram handlers against wide files and a failing.envwrite.Related Issues
Closes #17000
Pattern harvest
Rule candidate: review-prompt
Pattern: a save that commits one store before validating the input another store's write needs, so a later refusal leaves a partial save.
Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.
Checklist