Skip to content

[Bug]: Weixin gateway death loop after upgrade — open policy without ALLOW_ALL_USERS opt-in #57474

Description

@mlc622

Bug Description

After upgrading Hermes Agent from a previous version to v0.18.0, the gateway enters an infinite crash-restart loop when the Weixin platform has dm_policy or group_policy set to open but neither WEIXIN_ALLOW_ALL_USERS nor GATEWAY_ALLOW_ALL_USERS is enabled. Each cycle: gateway starts → fails the safety check → exits → systemd restarts → repeat. The restart counter reached 1705 before the issue was manually diagnosed.

Steps to Reproduce

  1. Configure weixin platform with WEIXIN_DM_POLICY=open in .env (no WEIXIN_ALLOW_ALL_USERS)
  2. Start gateway via hermes gateway start or systemd service
  3. Gateway exits immediately and systemd restarts it in a loop

Expected Behavior

One of:

  • Gateway should start successfully (config was valid in the previous version), or
  • Gateway should exit with an actionable error message telling the user how to fix it, and not restart in a loop

Actual Behavior

Gateway enters an infinite crash-restart loop. systemd counter exceeded 1700. The error message states the problem but does not suggest the fix:

ERROR gateway.run: Refusing to start: weixin has dm_policy/group_policy set to "open" but neither GATEWAY_ALLOW_ALL_USERS nor WEIXIN_ALLOW_ALL_USERS is enabled.
ERROR gateway.run: Gateway exiting cleanly: weixin: open policy without allow-all opt-in

Systemd journal:

hermes-gateway.service: Scheduled restart job, restart counter is at 1702.
hermes-gateway.service: Scheduled restart job, restart counter is at 1703.

Affected Component

Gateway (WeChat/Weixin platform adapter)

Environment

  • OS: Linux (Ubuntu)
  • Python: 3.11.15
  • Hermes Version: v0.18.0 (2026.7.1, commit 63354ed)

Root Cause Analysis

The gateway startup validation in gateway/run.py enforces that open DM/group policies must be paired with an explicit ALLOW_ALL_USERS opt-in. This is a sensible safety check, but:

  1. No backward compatibility — configs valid in the previous version break silently after upgrade
  2. The error message does not tell the user how to resolve it (e.g. "set WEIXIN_ALLOW_ALL_USERS=true or change dm_policy to pairing")
  3. Immediate exit on this check triggers a systemd restart loop (exponential backoff notwithstanding, still 1700+ cycles overnight)

Suggested Fix

  1. Add an upgrade migration or startup warning that detects the incompatible config before the hard exit
  2. Improve the error message to include resolution steps
  3. Consider whether exiting on a config validation error is the right behavior (vs. skipping the platform with a warning log)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existsarea/authAuthentication, OAuth, credential poolscomp/gatewayGateway runner, session dispatch, deliveryplatform/wecomWeCom / WeChat Work adaptertype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions