fix(gateway): prevent background process notifications from triggering false pairing requests - #6434
Merged
Conversation
…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.
Closed
5 tasks
dev-xyz-0-0
added a commit
to dev-xyz-0-0/hermes-agent
that referenced
this pull request
Apr 30, 2026
…g false pairing requests NousResearch/hermes-agent#6434
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Salvage of PR #5985 by @xingkongliang (cherry-picked with authorship preserved).
When a background process with
notify_on_complete=Truefinishes, the gateway injects a syntheticMessageEventto notify the session. This event was constructed withoutuser_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
internal: bool = Falsefield toMessageEventdataclass_is_user_authorized()whenevent.internal is Trueinternal=Trueon the synthetic event in_run_process_watcherFollow-up fix
DISCORD_ALLOW_ALL_USERS, etc.) in the pairing regression test — the contributor's test assumed a clean env, butgateway/run.pyloads dotenv at module level which can setDISCORD_ALLOW_ALL_USERS=Truefrom~/.hermes/.env.Test results
18/18 tests pass (4 new + 14 existing background process notification tests).
Closes #5985