fix(slack): warn when configured token is a user token, not a bot token - #55332
Closed
benbarclay wants to merge 1 commit into
Closed
fix(slack): warn when configured token is a user token, not a bot token#55332benbarclay wants to merge 1 commit into
benbarclay wants to merge 1 commit into
Conversation
A Slack user/legacy token (xoxp-...) makes auth.test resolve to the installing human's member ID with no bot_id, so the adapter binds its identity (_bot_user_id / _team_bot_user_ids) to that human. Every "is this the bot?" check then misfires: that person's <@...> mentions wake the bot and are stripped as the bot's own mention, so the agent is genuinely told it was @mentioned and replies to messages merely addressed to that human (symptom: bot responds to "@trevor ..." and insists it was explicitly mentioned). There is no runtime API error to catch — a user token still sends/receives — so the only detectable moment is connect time. Add a warning-only nudge (_warn_if_not_bot_token) alongside the existing group-DM scope nudge: when auth.test resolves a user_id but no bot_id, log that the token is a user token and to use the xoxb-... Bot User OAuth Token. Warning-only: does not block a working-but-misconfigured install. Fires once per workspace per process.
Contributor
🔎 Lint report:
|
tonydwb
reviewed
Jun 30, 2026
tonydwb
left a comment
There was a problem hiding this comment.
LGTM. Connect-time detection of user tokens vs bot tokens with actionable warning. Well-documented, tests included.
Code Review SummaryVerdict: Approved Detects when a configured Slack token authenticates as a human user (no bot_id in auth.test response) and warns the operator. This prevents the misrouting bug where the bot mistakes human mentions for self-mentions. ✅ Looks Good
Reviewed by Hermes Agent |
Contributor
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.
Infographic
Problem
A Slack user/legacy token (
xoxp-…) configured inSLACK_BOT_TOKENmakesauth.testresolve to the installing human's member ID — and the response carries nobot_id. The adapter trusts thatuser_idblindly:From then on,
self._bot_user_idis bound to a human's member ID, so every "is this the bot?" check misfires. The channel mention gate fires on that person's mentions:So when someone writes
@thatperson …, the adapter classifies it as a bot @mention, strips the token, and the agent is genuinely told it was mentioned — it then replies to a message that was only addressed to that human, and (correctly, given the bad input) insists it was "explicitly mentioned." Other users'<@…>tokens are untouched and non-triggering; the misbehaviour is isolated to whichever human the token authenticates as.There is no runtime API error to catch — a user token still sends and receives — so the only point this is observable is connect time, by noticing
bot_idis absent fromauth.test.Fix (warning-only)
Add
_warn_if_not_bot_token(auth_response, team_name), called in the per-token auth loop right next to the existing_warn_if_missing_group_dm_scopesnudge. Whenauth.testresolves auser_idbut nobot_id, it logs an actionable warning naming the misbound member ID and pointing at thexoxb-…Bot User OAuth Token. It is warning-only — a misconfigured-but-working install is not hard-failed on connect — and fires once per workspace per process (mirrors the group-DM nudge'swarnedset). Diagnostics are wrapped so they can never breakconnect().Tests
tests/gateway/test_slack_user_token_warning.py(mirrorstest_slack_group_dm_scope_warning.py):bot_idis absent (user token) and names the member IDbot_idis present (real bot token).data, not dict.get())Prove-fail verified: with the adapter change stashed, all 5 fail with
AttributeError: 'SlackAdapter' object has no attribute '_warn_if_not_bot_token'; with the fix applied, all 5 pass (and the 5 sibling group-DM-scope tests stay green).