Skip to content

fix(qqbot): authorize approval clicks for DM sessions (chat_type='dm') - #35774

Closed
luyao618 wants to merge 1 commit into
NousResearch:mainfrom
luyao618:fix/qqbot-approval-dm-chat-type
Closed

fix(qqbot): authorize approval clicks for DM sessions (chat_type='dm')#35774
luyao618 wants to merge 1 commit into
NousResearch:mainfrom
luyao618:fix/qqbot-approval-dm-chat-type

Conversation

@luyao618

Copy link
Copy Markdown
Contributor

Summary

Fixes #35760 — QQ bot approval button clicks (e.g. allow-once, allow-always) were always rejected with Rejected unauthorized approval click for session ..., blocking every tool requiring user approval until the ~280s approval timeout fired.

Root cause

gateway/platforms/qqbot/adapter.py::_is_authorized_interaction_for_session only matched chat_type == "c2c". But this adapter creates DM sessions with chat_type="dm":

# adapter.py:1282 (C2C message create handler)
chat_type="dm",
# adapter.py:1492 (friend-add handler)
chat_type="dm",

Session keys therefore look like agent:main:qqbot:dm:<openid>, which parses to chat_type="dm" and never matches "c2c", so every DM approval click falls through to return False.

Fix

One-line: accept both legacy "c2c" and current "dm" chat_type values.

-        if chat_type == "c2c":
+        if chat_type in ("c2c", "dm"):
             return bool(chat_id) and operator == chat_id

Group/guild branches are unchanged.

Tests

Adds three regression tests in tests/gateway/test_qqbot.py::TestIsAuthorizedInteractionForSession:

  • test_dm_chat_type_authorizes_when_operator_matches_chat_id — the bug case
  • test_c2c_chat_type_still_authorizes — backward-compat guard
  • test_dm_chat_type_rejects_when_operator_mismatched — ensures we still reject impostors

Full file passes: 162 passed.

Risk

Minimal. Pure widening of an existing auth predicate. Operator-equality check is unchanged, so security posture is identical to the c2c path.

Fixes NousResearch#35760

The QQ adapter creates direct-message sessions with chat_type="dm"
(see _on_c2c_message_create / _on_friend_add: chat_type="dm"), but
_is_authorized_interaction_for_session only accepted chat_type=="c2c".
As a result, approval button clicks on QQ DMs were always rejected
with 'Rejected unauthorized approval click', blocking every tool
requiring user approval until the ~280s approval timeout fired.

Accept both legacy 'c2c' and current 'dm' chat_type values. Adds
regression tests covering DM accept, c2c accept, and DM mismatch
reject.
@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 labels May 31, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #32752 (and #31593) — same one-line fix accepting "dm" alongside "c2c" in _is_authorized_interaction_for_session(). Fixes #35760 / #32528.

@luyao618

luyao618 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #32752 / #31593 — same one-line fix accepting "dm" alongside "c2c" in _is_authorized_interaction_for_session(). Both earlier PRs are still open. Thanks to alt-glitch for flagging.

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 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 always rejected due to chat_type mismatch (c2c vs dm)

2 participants