fix(discord): pass guild_id to slash-command session source - #91634
jondgilbert wants to merge 1 commit into
Conversation
Slash commands (/new, /reset, and all other simple slash commands) built their SessionSource in _build_slash_event without a guild_id, while the regular message path passes it. With gateway.multiplex_profiles and profile_routes keyed on guild_id+chat_id, the missing guild_id meant the route never matched: source.profile stayed empty and the session resolved to the active/default profile (agent:main) instead of the routed profile (e.g. agent:work). /new then reset the wrong session namespace and the routed profile's context never cleared. Add _interaction_guild_id (resolves interaction.guild_id, falling back to interaction.channel.guild.id to match the message path) and pass it into build_source in _build_slash_event and the thread-session path.
Correct and minimal: slash-command events now carry the same guild identity as the message path, the resolver degrades gracefully through
No blocking issues found. — reviewer-b (automated review) |
|
Thanks for this PR. Merged via #101247 (0437fe6) on current main — handoffs fail closed and load secrets off-loop; Discord slash commands honor profile_routes. #101247 won as the consolidated fix because it covers the whole multiplex-profile bug class in one change (with tests) rather than the single symptom addressed here; this PR is superseded by it. If anything from your original change is still missing on main >= 0437fe6, please open a fresh PR/issue against main and tag it. Thanks again. |
What does this PR do?
Fixes the Discord
/newand/reset(and all other simple slash commands) resolving to the wrong session namespace whengateway.multiplex_profiles+profile_routesare in use._build_slash_eventinplugins/platforms/discord/adapter.pybuilt theSessionSourceviaself.build_source(...)withoutguild_id, whereas the regular message path passes it. SinceProfileRoute.matchesrequires bothguild_idANDchat_id, the route never matched —source.profilestayedNone, and_resolve_profile_for_keyfell back to the active/default profile (agent:main) instead of the routed profile (e.g.agent:work). Result:/newreset the wrong session and the routed profile context never cleared.This adds
_interaction_guild_id(resolvesinteraction.guild_id, falling back tointeraction.channel.guild.idto match the message path) and passes it intobuild_sourcein_build_slash_eventand the thread-session path.Related Issue
Fixes #91633
Type of Change
Changes Made
plugins/platforms/discord/adapter.py_interaction_guild_id(interaction)helper._build_slash_eventnow passesguild_id=self._interaction_guild_id(interaction)._dispatch_thread_session) passes the sameguild_id.tests/gateway/test_discord_slash_commands.pyevent.source.guild_idintest_run_simple_slash_executes_when_defer_interaction_expiredandtest_build_slash_event_preserves_thread_context.test_build_slash_event_uses_interaction_guild_idcovering theinteraction.guild_idpath.How to Test
gateway.multiplex_profiles: true+profile_routesentry{platform: discord, guild_id: G, chat_id: C, profile: work}./newin channel C.agent:main:.... After: reset targetsagent:work:...and the work conversation clears.Unit tests:
Checklist
Code
pytest tests/ -qand all tests passDocumentation & Housekeeping