fix(slack): slash commands broken in DM threads due to session key mismatch - #39527
Closed
drafish wants to merge 1 commit into
Closed
fix(slack): slash commands broken in DM threads due to session key mismatch#39527drafish wants to merge 1 commit into
drafish wants to merge 1 commit into
Conversation
teknium1
reviewed
Jul 14, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for isolating a real current-main session-key mismatch: _has_active_session_for_thread() still builds a group source at plugins/platforms/slack/adapter.py:4015-4021, while inbound IM/MPIM messages create dm sources at plugins/platforms/slack/adapter.py:2763,3163-3170.
Problems
- The proposed
D-prefix rule is incomplete. Main treats bothimandmpimas DM-style sessions (plugins/platforms/slack/adapter.py:2763), while the test suite usesG_MPIMfor an MPIM (tests/gateway/test_slack_mention.py:369-374). A non-DMPIM would still be looked up asgroup. - The PR adds no regression test. Existing lookup coverage is group-only (
tests/gateway/test_slack_approval_buttons.py:618-641).
Suggested changes
- During salvage, port this to
plugins/platforms/slack/adapter.pyand pass the event-derivedis_dm/chat type into_has_active_session_for_thread()at both call sites (:2858,:2888) instead of re-inferring it from the ID. - Add an existing-DM-thread test with fetched context and a command, plus an MPIM case.
Automated hermes-sweeper review.
…hread
_has_active_session_for_thread() hardcoded chat_type='group', causing
session key mismatch for DM and MPIM threads. DM sessions key as
agent:main:slack:dm:{chat_id}:{thread_ts} but the lookup built
agent:main:slack:group:{chat_id}:{user_id}:{thread_ts}.
Impact: _has_active_session_for_thread always returned False for DM
threads, causing thread context to be prepended on every message. The
prepended context broke slash command detection (get_command() checks
text.startswith('/')), so /cmd and !cmd never worked in DM threads.
Fix: accept event-derived chat_type parameter instead of hardcoding
'group'. Both call sites pass chat_type='dm' if is_dm else 'group',
where is_dm is already computed from channel_type in {'im', 'mpim'}.
This correctly handles:
- IM channels (D-prefix): chat_type='dm'
- MPIM channels (G-prefix): chat_type='dm' (was missed by D-prefix heuristic)
- Channel messages (C-prefix): chat_type='group' (unchanged)
Added regression tests covering DM thread lookup, MPIM thread lookup,
and negative cases verifying the old hardcoded 'group' behavior fails.
drafish
force-pushed
the
fix/slack-dm-thread-slash-commands
branch
from
July 15, 2026 12:53
8f486fd to
301acc7
Compare
Contributor
|
Merged via #69479 — your commit was cherry-picked/reapplied onto current main with your authorship preserved in git history: your DM-thread session-key fix was cherry-picked directly. Thanks for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Slash commands (
/usage,/stop,!cmdetc.) are broken inside Slack DM threads — they get treated as regular text messages and forwarded to the agent instead of being intercepted as commands.Root Cause
_has_active_session_for_thread()(line 2869 ingateway/platforms/slack.py) hardcodeschat_type="group"when building the session key for lookup:This generates a key like
agent:main:slack:group:D0ASJ8Q7TDG:{user_id}:{thread_ts}, but the actual DM session key isagent:main:slack:dm:D0ASJ8Q7TDG:{thread_ts}. The keys never match, so the function always returnsFalsefor DM threads.Impact chain:
_has_active_session_for_thread()returnsFalse→ thread context is prepended to every messagetextbecomes[Thread context — ...]\n/usageinstead of/usageget_command()checkstext.startswith("/")→False→ returnsNoneThis affects all slash commands in DM threads, not just the
!prefix workaround.Fix
Detect DM vs group from the channel ID (Slack DM channel IDs start with
"D"):Testing
Verified locally: after the fix,
!usagein a DM thread is correctly intercepted as a command and returns the usage report instead of being forwarded to the agent.