Skip to content

fix(gateway): prevent background process notifications from triggering false pairing requests - #6434

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-063b6e1d
Apr 9, 2026
Merged

fix(gateway): prevent background process notifications from triggering false pairing requests#6434
teknium1 merged 2 commits into
mainfrom
hermes/hermes-063b6e1d

Conversation

@teknium1

@teknium1 teknium1 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Salvage of PR #5985 by @xingkongliang (cherry-picked with authorship preserved).

When a background process with notify_on_complete=True finishes, the gateway injects a synthetic MessageEvent to notify the session. This event was constructed without user_id, causing _is_user_authorized() to reject it and trigger the DM pairing flow — sending a pairing code to the bot owner's own chat.

Fix

  • Added internal: bool = False field to MessageEvent dataclass
  • Skip _is_user_authorized() when event.internal is True
  • Set internal=True on the synthetic event in _run_process_watcher
  • 4 regression tests

Follow-up fix

  • Cleaned env vars (DISCORD_ALLOW_ALL_USERS, etc.) in the pairing regression test — the contributor's test assumed a clean env, but gateway/run.py loads dotenv at module level which can set DISCORD_ALLOW_ALL_USERS=True from ~/.hermes/.env.

Test results

18/18 tests pass (4 new + 14 existing background process notification tests).

Closes #5985

xingkongliang and others added 2 commits April 8, 2026 22:43
…g false pairing requests

When a background process with notify_on_complete=True finishes, the
gateway injects a synthetic MessageEvent to notify the session. This
event was constructed without user_id, causing _is_user_authorized()
to reject it and — for DM-origin sessions — trigger the pairing flow,
sending "Hi~ I don't recognize you yet!" with a pairing code to the
chat owner.

Add an `internal` flag to MessageEvent that bypasses authorization
checks for system-generated synthetic events. Only the process watcher
sets this flag; no external/adapter code path can produce it.

Includes 4 regression tests covering the fix and the normal pairing path.
The test_non_internal_event_without_user_triggers_pairing test relied on
no Discord auth env vars being set, but gateway/run.py loads dotenv at
module level. In environments with DISCORD_ALLOW_ALL_USERS=True in .env,
the auth check passed instead of triggering the pairing flow.

Clear DISCORD_ALLOW_ALL_USERS, DISCORD_ALLOWED_USERS, GATEWAY_ALLOW_ALL_USERS,
and GATEWAY_ALLOWED_USERS via monkeypatch to ensure test isolation.
@teknium1
teknium1 merged commit 5449c01 into main Apr 9, 2026
2 of 4 checks passed
dev-xyz-0-0 added a commit to dev-xyz-0-0/hermes-agent that referenced this pull request Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants