Skip to content

fix(platforms): clear home channel when setup prompt left blank (#12423) - #58421

Closed
DavidMetcalfe wants to merge 3 commits into
NousResearch:mainfrom
DavidMetcalfe:fix/feishu-home-channel-clear-all-adapters
Closed

fix(platforms): clear home channel when setup prompt left blank (#12423)#58421
DavidMetcalfe wants to merge 3 commits into
NousResearch:mainfrom
DavidMetcalfe:fix/feishu-home-channel-clear-all-adapters

Conversation

@DavidMetcalfe

Copy link
Copy Markdown
Contributor

Problem

Interactive platform setup wizards (Feishu, Discord, Slack, Mattermost, WhatsApp) could not clear an existing *_HOME_CHANNEL env var. If a user re-ran setup and left the home-channel prompt blank, the old value was silently preserved. Users had to manually edit ~/.hermes/.env to clear it.

Reported in #12423 for Feishu; the same pattern existed in 4 other adapters.

Changes

  • All 5 adapters: Added remove_env_value to the lazy-import block and an else branch that calls it when the prompt is left blank, clearing the persisted env var.
  • Whitespace handling: All adapters now .strip() the prompt result before the emptiness check, so whitespace-only input clears instead of being saved.
  • Feishu UX hint: Added a print_info line before the prompt explaining that leaving it blank clears a previously saved home channel.
  • Code smell fix: Used else: if remove_env_value(...) instead of elif remove_env_value(...) to avoid side effects in a conditional expression (caught by review).

Tests

  • Updated _run_setup_feishu helper to mock remove_env_value and track removed keys.
  • Added TestSetupFeishuHomeChannel with 4 tests:
    • Blank input removes existing home channel
    • Blank input without prior key still invokes remove
    • Non-empty input saves and does not remove
    • Whitespace-only input clears (not saves)
  • All 18 tests pass.

Verification

python -m pytest tests/gateway/test_setup_feishu.py -q

Notes

  • Supersedes stale PR fix(cli): clear Feishu home channel when setup prompt left blank (#12423) #12451 (targeted pre-refactor file path hermes_cli/gateway.py; function moved to plugins/platforms/feishu/adapter.py).
  • The other 4 adapters' prompts already say "leave empty to set later" — the else branch now makes that accurate (empty = clear). Prompt wording could be updated in a follow-up for full consistency.

…Research#12423)

All 5 platform adapters (Feishu, Discord, Slack, Mattermost, WhatsApp)
now call remove_env_value() when the home-channel prompt is left blank,
instead of silently preserving the old value.

Also: .strip() prompt input, else-block instead of elif side-effect,
mock remove_env_value in tests, add 4 clearing tests.
@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins platform/feishu Feishu / Lark adapter platform/discord Discord bot adapter platform/slack Slack app adapter platform/whatsapp WhatsApp Business adapter P3 Low — cosmetic, nice to have labels Jul 4, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for tracing the Feishu report through the plugin migration and applying the existing remove_env_value() helper. The five changed paths still have the reported truthy-only persistence behavior on current main (for example, plugins/platforms/feishu/adapter.py:5616-5619), and the proposed removal mechanism is appropriate.

Problems

  • The same bug class remains in the adjacent plugin setup flows: Matrix only saves MATRIX_HOME_ROOM when home_room is truthy (plugins/platforms/matrix/adapter.py:4532-4534), and WeCom only saves WECOM_HOME_CHANNEL when home is truthy (plugins/platforms/wecom/adapter.py:1819-1821). Both are active cron/home delivery targets (cron/scheduler.py:215,225).
  • The new regression coverage is Feishu-only. Existing Slack coverage confirms blank input is not saved (tests/gateway/test_slack_plugin_setup.py:45-57), but does not exercise removal of an existing target.

Suggested changes

  • Apply the same clear-on-blank behavior to Matrix and WeCom.
  • Add seeded-existing-value, blank, whitespace, and non-empty tests for each affected setup wizard.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 15, 2026
Extends the home-channel clear-on-blank behavior from NousResearch#58421 to the two
remaining adapters whose home-channel prompts still preserved the old
value silently:

- Matrix (`plugins/platforms/matrix/adapter.py`): the
  `MATRIX_HOME_ROOM` prompt at line 4651 was the last
  truthy-only-save site. Both Matrix (`MATRIX_HOME_ROOM`) and WeCom
  (`WECOM_HOME_CHANNEL`) are listed in
  `cron/scheduler.py::_HOME_TARGET_ENV_VARS` as active cron home
  delivery targets — leaving them on the old behavior silently re-sent
  cron job output to a channel/room the user had tried to clear.

- WeCom (`plugins/platforms/wecom/adapter.py`): the
  `WECOM_HOME_CHANNEL` prompt at line 1820 had the same
  truthy-only-save shape.

Both adapters now:
  1. `.strip()` the prompt input so whitespace-only answers don't get
     persisted as a literal space.
  2. In the else branch, call `remove_env_value()` and print
     "Home channel cleared." when the prior value was actually
     removed. The 5 already-patched adapters in NousResearch#58421 follow the
     same shape.

This addresses the second finding in maintainer teknium1's
`keep_open / salvageability=high` review of NousResearch#58421
(comment 4983105207): the same bug class was still present in Matrix
and WeCom on current `main`.

Refs: PR NousResearch#58421, comment 4983105207.
Adds 4 home-channel tests for each of the 6 platform setup wizards
that already (Discord, Slack, Mattermost, WhatsApp, Matrix, WeCom) or
will (Matrix, WeCom — see prior commit) call `remove_env_value()` on a
blank home-channel prompt answer:

1. `test_blank_removes_existing_home_channel` — pre-seed env with the
   home-channel var, run setup with blank input, assert
   `remove_env_value` was called AND the key is no longer in saved
   env.
2. `test_blank_without_prior_home_still_attempts_remove` — no
   pre-seeded env, run setup with blank input, assert
   `remove_env_value` was called once (safe no-op, but the call
   confirms the else-branch runs).
3. `test_nonempty_saves_home_channel` — no pre-seeded env, run setup
   with a real channel ID, assert `save_env_value` was called AND
   `remove_env_value` was NOT called.
4. `test_whitespace_only_clears_home_channel` — pre-seed env with
   home-channel, run setup with `"   "` input, assert it cleared.

This addresses the first finding in maintainer teknium1's
`keep_open / salvageability=high` review of NousResearch#58421
(comment 4983105207): the prior regression coverage was Feishu-only,
and the existing Slack coverage only confirmed blank input is not
saved — it didn't exercise removal of an existing target. The new
`TestSlackHomeChannelClear` class augments the existing Slack test
file (`tests/gateway/test_slack_plugin_setup.py`) without breaking
the two pre-existing tests in that file.

The new test files use the Slack-style `monkeypatch` helper rather
than the heavier `unittest.mock.patch` style of
`tests/gateway/test_setup_feishu.py` because the setup-time
I/O surface for each adapter is simpler than Feishu's
(QR scan, manual connection mode, etc.). The Matrix test additionally
patches `tools.lazy_deps.feature_missing` and `ensure` so the wizard's
mautrix auto-install path is a no-op — no pip invocations from unit
tests. The WeCom test additionally stubs `qr_scan_for_bot_info` and
patches `hermes_cli.setup.prompt_choice` so the QR path is skipped.

Total new coverage: 24 tests across 6 new test files + a Slack
augmentation (4 tests in `TestSlackHomeChannelClear`). All 44
home-channel tests across 7 adapters pass locally
(`pytest tests/gateway/test_discord_plugin_setup.py
        tests/gateway/test_mattermost_plugin_setup.py
        tests/gateway/test_whatsapp_plugin_setup.py
        tests/gateway/test_matrix_plugin_setup.py
        tests/gateway/test_wecom_plugin_setup.py
        tests/gateway/test_slack_plugin_setup.py
        tests/gateway/test_setup_feishu.py`).

Refs: PR NousResearch#58421, comment 4983105207.
@DavidMetcalfe

Copy link
Copy Markdown
Contributor Author

Thanks for the trace and the salvageability tag — both findings addressed in two follow-up commits on top of 394f6ca07:

bf5115ff8fix(platforms): clear home channel on blank prompt for matrix and wecom

Matrix (plugins/platforms/matrix/adapter.py) and WeCom (plugins/platforms/wecom/adapter.py) now mirror the same remove_env_value() + .strip() + else-clear pattern as the other 5 adapters. Both are in cron/scheduler.py::_HOME_TARGET_ENV_VARS (line 254 and 264), so the cron-silent-preserve failure mode is closed for every active cron home delivery target.

201a39e78test(gateway): add home-channel clear-on-blank coverage for 6 adapters

5 new test files (Discord/Mattermost/WhatsApp/Matrix/WeCom) + a TestSlackHomeChannelClear class augmenting the existing Slack test. Each adapter gets 4 scenarios:

  • test_blank_removes_existing_home_channel — pre-seeded env, blank prompt → remove_env_value called AND key removed from saved env.
  • test_blank_without_prior_home_still_attempts_remove — no pre-seeded env, blank prompt → remove_env_value still called once (confirms the else-branch isn't dead code).
  • test_nonempty_saves_home_channel — fresh env, real value → save_env_value called AND remove_env_value NOT called (no accidental clear on save).
  • test_whitespace_only_clears_home_channel — pre-seeded env, " " input → cleared (regression guard on .strip()).

Local verification:

$ pytest tests/gateway/test_discord_plugin_setup.py \
        tests/gateway/test_mattermost_plugin_setup.py \
        tests/gateway/test_whatsapp_plugin_setup.py \
        tests/gateway/test_matrix_plugin_setup.py \
        tests/gateway/test_wecom_plugin_setup.py \
        tests/gateway/test_slack_plugin_setup.py \
        tests/gateway/test_setup_feishu.py
============================== 44 passed in 0.56s ==============================

44 tests across 7 adapters, all green. The Matrix test additionally patches tools.lazy_deps.feature_missing/ensure so the wizard's mautrix auto-install path is a no-op; the WeCom test stubs qr_scan_for_bot_info and prompt_choice so the QR path is skipped. CI should be green on the next push.

Cross-vendor dual review (Flash + GPT-OSS) on the rework passed with no BLOCKERs; both reviewers independently accepted the adapter patches, mock semantics, prompt-choice sequence, scope, and commit boundary. Two SHOULD-FIX findings (None-safety on prompt() and Unicode whitespace) were verified against hermes_cli/cli_output.py:43-48 (prompt() returns str, never None) and str.strip() semantics (handles all Unicode whitespace per the Unicode database) — both false positives.

Happy to split the test commit per-adapter or follow up on the prompt-text-consistency NIT separately if you'd prefer.

teknium1 pushed a commit that referenced this pull request Jul 23, 2026
Blank (or whitespace-only) answers to the home-channel prompt in the
interactive setup wizards previously left any previously saved
*_HOME_CHANNEL / *_HOME_ROOM env value in place, so operators could not
clear a stale home channel by re-running setup. Strip the prompt input
and call remove_env_value() on blank answers across the Discord, Slack,
Feishu, Matrix, Mattermost, WeCom and WhatsApp plugin setup wizards,
with per-adapter wizard tests covering set/clear/whitespace flows.

Squash of the three commits from PR #58421 (setup-wizard fix, matrix/
wecom extension, and 6-adapter test coverage) — one commit per
contributor on this salvage branch.

Fixes #12423
Salvaged from #58421
teknium1 pushed a commit that referenced this pull request Jul 23, 2026
Blank (or whitespace-only) answers to the home-channel prompt in the
interactive setup wizards previously left any previously saved
*_HOME_CHANNEL / *_HOME_ROOM env value in place, so operators could not
clear a stale home channel by re-running setup. Strip the prompt input
and call remove_env_value() on blank answers across the Discord, Slack,
Feishu, Matrix, Mattermost, WeCom and WhatsApp plugin setup wizards,
with per-adapter wizard tests covering set/clear/whitespace flows.

Squash of the three commits from PR #58421 (setup-wizard fix, matrix/
wecom extension, and 6-adapter test coverage) — one commit per
contributor on this salvage branch.

Fixes #12423
Salvaged from #58421
teknium1 pushed a commit that referenced this pull request Jul 23, 2026
Blank (or whitespace-only) answers to the home-channel prompt in the
interactive setup wizards previously left any previously saved
*_HOME_CHANNEL / *_HOME_ROOM env value in place, so operators could not
clear a stale home channel by re-running setup. Strip the prompt input
and call remove_env_value() on blank answers across the Discord, Slack,
Feishu, Matrix, Mattermost, WeCom and WhatsApp plugin setup wizards,
with per-adapter wizard tests covering set/clear/whitespace flows.

Squash of the three commits from PR #58421 (setup-wizard fix, matrix/
wecom extension, and 6-adapter test coverage) — one commit per
contributor on this salvage branch.

Fixes #12423
Salvaged from #58421
teknium1 pushed a commit that referenced this pull request Jul 23, 2026
Blank (or whitespace-only) answers to the home-channel prompt in the
interactive setup wizards previously left any previously saved
*_HOME_CHANNEL / *_HOME_ROOM env value in place, so operators could not
clear a stale home channel by re-running setup. Strip the prompt input
and call remove_env_value() on blank answers across the Discord, Slack,
Feishu, Matrix, Mattermost, WeCom and WhatsApp plugin setup wizards,
with per-adapter wizard tests covering set/clear/whitespace flows.

Squash of the three commits from PR #58421 (setup-wizard fix, matrix/
wecom extension, and 6-adapter test coverage) — one commit per
contributor on this salvage branch.

Fixes #12423
Salvaged from #58421
@teknium1

Copy link
Copy Markdown
Contributor

Merged via #70196 — your commit was cherry-picked/reapplied onto current main with your authorship preserved in git history: your blank-home-channel fix was cherry-picked, fixes #12423.

Thanks for the contribution!

@teknium1 teknium1 closed this Jul 23, 2026
randlee pushed a commit to randlee/hermes-agent that referenced this pull request Aug 11, 2026
Blank (or whitespace-only) answers to the home-channel prompt in the
interactive setup wizards previously left any previously saved
*_HOME_CHANNEL / *_HOME_ROOM env value in place, so operators could not
clear a stale home channel by re-running setup. Strip the prompt input
and call remove_env_value() on blank answers across the Discord, Slack,
Feishu, Matrix, Mattermost, WeCom and WhatsApp plugin setup wizards,
with per-adapter wizard tests covering set/clear/whitespace flows.

Squash of the three commits from PR NousResearch#58421 (setup-wizard fix, matrix/
wecom extension, and 6-adapter test coverage) — one commit per
contributor on this salvage branch.

Fixes NousResearch#12423
Salvaged from NousResearch#58421
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have platform/discord Discord bot adapter platform/feishu Feishu / Lark adapter platform/slack Slack app adapter platform/whatsapp WhatsApp Business adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants