Skip to content

fix(qqbot): accept 'dm' session key in approval authorization (#34432) - #34438

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/qqbot-approval-dm-session-key
Closed

fix(qqbot): accept 'dm' session key in approval authorization (#34432)#34438
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/qqbot-approval-dm-session-key

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

Summary

When Hermes QQ Bot receives a C2C (private) message and the dangerous-command approval flow triggers, clicking the approval button is always rejected with:

WARNING Rejected unauthorized approval click for session agent:main:qqbot:dm:<openid> (operator=<openid>)

Root cause: build_session_key() produces agent:main:qqbot:dm:<openid> for C2C messages (chat_type="dm"), but _is_authorized_interaction_for_session() only checks chat_type == "c2c". The "dm" identifier never matches, so every C2C approval click is rejected.

Fix: Accept both "c2c" and "dm" in the private-message authorization branch, since both identifiers refer to the same C2C conversation type — just from different code paths.

Fixes #34432

Code Intelligence

  • Analyzed: gateway/platforms/qqbot/adapter.py _is_authorized_interaction_for_session() and _parse_gateway_session_key() (line 1082-1085)
  • Blast radius: LOW — single condition change in one adapter, backward-compatible (adds "dm" to accepted set without removing "c2c")
  • Related patterns: build_session_key() in gateway/session.py (line 631) produces "dm" for all DM chat types; parse_interaction_event() in keyboards.py (line 459) maps QQ API chat_type=2scene="c2c"

Changes

  • gateway/platforms/qqbot/adapter.py: accept "dm" alongside "c2c" in _is_authorized_interaction_for_session
  • tests/gateway/test_qqbot.py: regression test test_approval_click_accepts_dm_session_key verifying approval clicks work with "dm" format session keys

Testing

160 passed in 5.28s (tests/gateway/test_qqbot.py)

The approval click authorization in _is_authorized_interaction_for_session
only matched chat_type == 'c2c', but build_session_key() produces session
keys with chat_type='dm' for C2C (private) messages. This caused every
approval button click on C2C sessions to be rejected as unauthorized.

Fix by accepting both 'c2c' and 'dm' in the private-message branch.

Fixes NousResearch#34432
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/qqbot QQ Bot adapter duplicate This issue or pull request already exists labels May 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #31593 (earliest open fix). Also duplicates closed #33962 and open #32752. All fix the same bug: _is_authorized_interaction_for_session() rejects DM approval clicks because session key uses chat_type='dm' but auth check only accepts 'c2c'. Canonical issue: #32528.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Closing as duplicate per triage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists platform/qqbot QQ Bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QQ Bot: approval button clicks rejected — session_key uses dm as chat_id instead of user openid

2 participants