fix(qqbot): accept shared-context group session keys in approval auth gate - #55458
fix(qqbot): accept shared-context group session keys in approval auth gate#55458sablea wants to merge 2 commits into
Conversation
… gate When the gateway runs with group_sessions_per_user=false (shared group context, no per-user isolation), the agent writes group session keys *without* a trailing user_id suffix: agent:main:qqbot:group:<chat_id> The previous _is_authorized_interaction_for_session implementation required a user_id suffix for all group/guild chat_type keys and silently dropped the click — the agent thread then blocked on the dangerous-command approval forever, with no error surfaced to the user. This change makes the authorization gate adapt to whichever key format the agent produced: per-user isolation (user_id present) keeps the existing strict-match contract; shared-context (no user_id) accepts any operator in the matching chat, since real authorization still happens at the platform allowlist layer (QQ_ALLOWED_USERS) above this function. Fixes the follow-up edge case from NousResearch#30737, which made the session_key format itself unambiguous but didn't account for the shared-context shape produced by group_sessions_per_user=false. Tests: TestGroupSharedContextAuthorization covers all six paths (group-without-user_id, guild-without-user_id, group-with-user_id, group-chat-mismatch, c2c, non-qqbot, empty-operator). Full test_qqbot.py suite still passes (166/166).
…click
End-to-end dispatch tests that exercise _default_interaction_dispatch
with the no-user_id group session_key shape produced by
group_sessions_per_user=false. Complements the unit tests added in the
parent commit with full parse → authorize → resolve flow coverage.
* test_approval_click_accepts_group_shared_context: any member of
a shared-context group can resolve approvals.
* test_approval_click_rejects_group_mismatch_in_shared_context:
cross-group click attempts are still blocked.
Full test_qqbot.py suite: 170/170 pass via scripts/run_tests.sh.
|
Updated with the following additions per CONTRIBUTING.md guidance:
No changes to |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary\n\nVerdict: LGTM\n\nFix for QQ bot shared-context group session keys in approval auth gate. When group_sessions_per_user: false, the agent writes session keys without a user_id suffix. The previous implementation required a user_id suffix for all group/guild keys, silently rejecting clicks. The fix correctly adapts to whichever key format the agent produced.\n\n### Looks Good\n- Well-scoped 2-file change with clear root cause\n- Tests added for both per-user and shared-context modes\n- Security preserved: real authorization still happens at the platform allowlist layer\n---\nReviewed by Hermes Agent
|
👋 Friendly ping — this PR is currently in The fix is small, well-scoped, and ready to merge:
Happy to address any review feedback or push additional commits if needed. If fork CI runs are intentionally disabled here, just say the word and I'll paste the test output inline for a maintainer-side local run. |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review: LGTM
Fixes QQBot group shared-context authorization. When group_sessions_per_user=False, the session key has no user_id suffix -- the old code hard-required it and silently dropped the click. The fix accepts any operator from the matching chat in shared-context mode while preserving the strict per-user match when user_id is present. Comprehensive test coverage (8 tests in TestGroupSharedContextAuthorization).
Verdict: LGTM -- correct authorization fix with thorough tests.
|
Thanks for the focused QQBot regression fix. The premise remains live on current main: The added tests cover both the authorization predicate and the dispatch path to Automated hermes-sweeper review. |
What does this PR do?
Fix a follow-up edge case from #30737: when the gateway runs with
group_sessions_per_user: false(shared group context, all membersshare one session), QQ bot's approval-button authorization gate
silently rejects every click — the agent thread then blocks forever
on a dangerous-command approval, with no error surfaced to the user.
The agent writes group session keys without a trailing
user_idsuffix in this mode:
agent:main:qqbot:group:<chat_id>The previous
_is_authorized_interaction_for_sessionimplementationrequired a
user_idsuffix for all group/guild keys and dropped theclick. Result: every shared-context QQ group was unable to use
inline-keyboard approvals (3-minute freeze, then fallback to text
slash command, but the slash command itself works on
/approve once).This PR makes the authorization gate adapt to whichever key format
the agent produced: per-user isolation (
user_idpresent) keeps theexisting strict-match contract; shared-context (no
user_id) acceptsany operator in the matching chat — since real authorization still
happens at the platform allowlist layer (
QQ_ALLOWED_USERS) abovethis function.
Related Issue
Closes the follow-up from #30737. Reproduction is identical:
set
group_sessions_per_user: false, send a heredoc command in agroup chat, click "Allow once" — nothing happens, log shows
Rejected unauthorized approval click.Type of Change
Changes Made
gateway/platforms/qqbot/adapter.py—_is_authorized_interaction_for_session:in the
group/guildbranch, accept a key withoutuser_id(theshared-context shape). When
user_idIS present, behavior isunchanged (per-user isolation still requires a strict match).
tests/gateway/test_qqbot.py— newTestGroupSharedContextAuthorizationclass with 7 tests covering: group-without-user_id, guild-without-user_id,
group-with-user_id, group-chat-mismatch, c2c, non-qqbot, empty-operator.
All 166 tests in
test_qqbot.pypass.How to Test
Checklist
Code
fix(scope):)pytest tests/gateway/test_qqbot.py -vand all 166 tests passDocumentation & Housekeeping
(telegram/slack/feishu/matrix/weixin/wecom/whatsapp), but
that's out of scope here; happy to file follow-up issues
with the same diagnosis if maintainers want
Screenshots / Logs
Pre-fix log (click silently rejected):
Post-fix log (click correctly resolved):
End-to-end round-trip latency: < 1 second (tested with
heredoctriggering the approval, user clicks "Allow once", command output
arrives back in the chat within ~600ms).