fix(qqbot): authorize approval clicks for c2c dm sessions - #40926
fix(qqbot): authorize approval clicks for c2c dm sessions#40926longXboy wants to merge 1 commit into
Conversation
QQ c2c private chats build their session source with chat_type="dm" and chat_id == user_openid (see _handle_c2c_message), so build_session_key() yields "agent:main:qqbot:dm:<user_openid>". _is_authorized_interaction_for_session only handled the "c2c" and "group"/"guild" chat types, so it fell through to return False for every "dm" session and rejected the legitimate user's own approval click with "Rejected unauthorized approval click". Add a "dm" branch that authorizes when the clicking operator matches the session chat_id (== user_openid), mirroring c2c semantics. Guild DMs (_handle_dm_message) instead key chat_id == guild_id, which build_session_key() does not pair with the user id, so their approval clicks remain unauthorized. That is documented inline and pinned by a test; fixing it requires threading the user id into the session key and is tracked separately. Tests: - test_approval_click_dm_session_authorized: c2c dm session authorizes - test_approval_click_guild_dm_currently_rejected: pins guild-DM gap
|
Verified — clean authorization fix with thorough test coverage. What I checked:
|
|
Thanks for the focused regression fix. Current The added Automated hermes-sweeper review. |
Problem
QQBot approval button clicks from private (c2c) chats were rejected with:
The clicking user is the legitimate session owner, yet their own approval was denied.
Root cause
QQ c2c private chats build their session source with
chat_type="dm"andchat_id == user_openid(see_handle_c2c_message), sobuild_session_key()producesagent:main:qqbot:dm:<user_openid>.But
_is_authorized_interaction_for_session()only handled thec2candgroup/guildchat types — it fell through toreturn Falsefor everydmsession, rejecting the user's own click.Fix
Add a
dmbranch that authorizes when the clicking operator matches the sessionchat_id(== user_openid), mirroring c2c semantics.Known limitation (tracked separately)
Guild DMs (
_handle_dm_message) instead keychat_id == guild_id, whichbuild_session_key()does not pair with the user id, so guild-DM approval clicks remain unauthorized. This is documented inline and pinned by a test; fixing it requires threading the user id into the session key and is out of scope for this focused fix.Tests
test_approval_click_dm_session_authorized— c2c dm session authorizes the matching usertest_approval_click_guild_dm_currently_rejected— pins the guild-DM gapFull
tests/gateway/test_qqbot.pypasses (163 passed);ruff checkclean on both files.