fix(slack): read real SDK responses instead of gating on isinstance dict - #18
Merged
nikitaBarkov merged 1 commit intoJul 30, 2026
Conversation
Slack Web API calls return `SlackResponse`/`AsyncSlackResponse`, which are
mapping-like but not `dict` subclasses, so every `isinstance(resp, dict)`
gate took its "unexpected shape" branch at runtime: user and channel names
collapsed to raw IDs, every user resolved as a non-bot (defeating the
allow_bots loop guard), ephemeral replies were reported as failures, and
uploads/caption fallbacks lost their message_id.
Normalize responses through a single `_slack_response_payload()` helper
(dict passes through, SDK response yields `.data`, anything else yields
`{}` so callers keep their fallbacks) and use it at every call site.
Existing Slack tests injected plain dicts, which is why the defect was
invisible; the new tests run each behavioral case against a real
`AsyncSlackResponse` as well.
nikitaBarkov
force-pushed
the
nikita.barkov/slack-sdk-response-not-dict
branch
from
July 30, 2026 06:57
ca0b0f4 to
4289f26
Compare
Author
|
Hermes PR: NousResearch#74658 |
nikitaBarkov
merged commit Jul 30, 2026
c334fd8
into
sync/upstream-2026-07-27
36 of 41 checks passed
Alexander Prendota (AlexanderPrendota)
deleted the
nikita.barkov/slack-sdk-response-not-dict
branch
July 30, 2026 08:44
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.
What does this PR do?
Fixes a regression that arrived with the upstream sync: Slack user and channel names collapse to raw IDs, so the agent sees
[U0BCE4NRVKN | Slack user <@U0BCE4NRVKN>]instead of[Nikita | Slack user <@U0BCE4NRVKN>].Root cause:
slack_sdkWeb API calls returnSlackResponse/AsyncSlackResponse. Those objects are mapping-like (they expose.get()and.data) but they are notdictsubclasses. Upstream commit3f08201ba("Fix Slack peer bot status routing loops", PR NousResearch#51627) addedisinstance(result, dict)guards around those responses, so at runtime the guard is always False and every call site takes its "unexpected shape" degradation branch:_resolve_user_name→ name becomes the user id, and the wrong value is cached for the lifetime of the gateway process_resolve_user_is_bot→ every user resolves as a non-bot, which defeats theallow_botsloop guard the same commit was meant to add_resolve_channel_name→ channel name degrades toC0…_post_ephemeral_fallback→ successful slash-command replies are reported asunexpected_responsefailures_standalone_upload_file/ standalonechat.postMessage→message_idis lost, caption fallback is never marked deliveredThe fix normalizes every Slack response through one helper —
_slack_response_payload(): a plaindictpasses through, an SDK response yields.data, anything else (including a binary.data) yields{}so callers keep their existing fallbacks. No behavior other than the degradation is changed.The premise was verified before writing the fix, not assumed:
slack_sdk(3.40.1) and the version pinned inpyproject.toml(3.43.0),SlackResponse/AsyncSlackResponseMRO ends atobject— they are notdictsubclasses. The return type is fixed in the SDK signatures (users_info(...) -> AsyncSlackResponse), and Bolt hands out the sameAsyncWebClient. Nothing about bot settings, scopes, the relay, or a Slack-side API change can flip this.[U0BCE4NRVKN | Slack user <@U0BCE4NRVKN>].users.infowith the bot token through our proxy returnsdisplay_name: "Nikita".AsyncSlackResponse:_resolve_user_namereturnedU_HUMANinstead ofNikita; after the fix it returns the name.Note this branch targets
sync/upstream-2026-07-27, notmain: commit3f08201bais not contained inorigin/main, so the regression only exists on the sync branch (verified withgit branch -r --contains 3f08201ba).Related Issue
No fork issue. Upstream has no open issue for this; the only PR with the same diagnosis (NousResearch#72062) was closed by its own author without maintainer review, so the defect is still present in
upstream/main. Submitted upstream separately as a standalone fix.Type of Change
Changes Made
plugins/platforms/slack/adapter.py: new_slack_response_payload()normalizer, and every Slack Web API call site routed through it —_resolve_user_name,_resolve_user_is_bot,_resolve_channel_name,_post_ephemeral_fallback, the thread seed-posttsread,_standalone_upload_file, and standalonechat.postMessageincluding the caption fallback. Allisinstance(resp, dict)gates on SDK responses are gone.tests/gateway/test_slack_sdk_response.py(new): every behavioral case is parametrized and runs both against a hand-rolled stand-in and against a realAsyncSlackResponse. Injecting plain dicts is exactly what hid this bug from the existing Slack suite for a month, so the real SDK shape is now part of the contract. Includes the normalizer's contract (dict passthrough,.data, binary.data→{}, unknown shape →{}) and preserves the "genuinely unreadable response still falls back to the id" degradation.How to Test
sync/upstream-2026-07-27, send a message in a shared channel — the prefix the model receives is[U… | Slack user <@U…>](name replaced by the id).[Nikita | Slack user <@U…>].scripts/run_tests.sh tests/gateway/test_slack_sdk_response.py tests/gateway/test_slack.py tests/gateway/test_slack_mention.py -q→ 528 passed, 0 failed (on this branch's base). The full Slack surface (29 suites +tests/tools/test_send_message_slack.py) was also run green: 876 passed.tests/gateway/as a whole has 8 pre-existing failures unrelated to this change (wecom_callback×3,background_command,readiness,shutdown_forensics,api_server,systemd_notify) — the same 8 fail with this change stashed.Checklist
Code
fix(slack): …) is intended as the squash-merge messagescripts/run_tests.shand all tests passDocumentation & Housekeeping
cli-config.yaml.exampleif I added/changed config keys — N/A (no config keys)CONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AScreenshots / Logs
Before (prefix seen by the model, taken from the live agent's request dump):
After:
Side effect worth knowing:
_resolve_user_is_botnow actually recognizes bots, so theallow_botspolicy starts working the way commit3f08201baintended.