From 40351d092311de7f02770faf5bdfa0a0dc2f520e Mon Sep 17 00:00:00 2001 From: Rob Zolkos Date: Fri, 22 May 2026 09:41:25 -0400 Subject: [PATCH] fix(slack): resolve file events with cached workspace team --- plugins/platforms/slack/adapter.py | 6 ++++++ tests/gateway/test_slack.py | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.py index 8fa88d95625f..68ca3f2dfa00 100644 --- a/plugins/platforms/slack/adapter.py +++ b/plugins/platforms/slack/adapter.py @@ -4338,6 +4338,12 @@ class SlackAdapter(BasePlatformAdapter): if not channel_id: channel_id = assistant_meta.get("channel_id", "") team_id = outer_team_id or assistant_meta.get("team_id", "") + + # File-upload events sometimes omit team_id. Resolve from the channel + # workspace cache so multi-workspace token lookup uses the right bot. + if not team_id and channel_id in self._channel_team: + team_id = self._channel_team[channel_id] + agent_context = self._agent_view_context_for_event( event, str(team_id or ""), str(user_id or "") ) diff --git a/tests/gateway/test_slack.py b/tests/gateway/test_slack.py index 8cb37e30d364..89fa0092645a 100644 --- a/tests/gateway/test_slack.py +++ b/tests/gateway/test_slack.py @@ -2103,6 +2103,33 @@ class TestIncomingDocumentHandling: assert os.path.exists(msg_event.media_urls[0]) assert msg_event.media_types == ["application/pdf"] + @pytest.mark.asyncio + async def test_uses_cached_channel_team_for_file_events_without_team_id(self, adapter): + """File events use the channel workspace cache when Slack omits team_id.""" + content = b"Hello from workspace two" + adapter._channel_team["D123"] = "T_SECOND" + + with patch.object(adapter, "_download_slack_file_bytes", new_callable=AsyncMock) as dl: + dl.return_value = content + event = self._make_event( + text="summarize this", + files=[{ + "mimetype": "text/plain", + "name": "workspace-two.txt", + "url_private_download": "https://files.slack.com/workspace-two.txt", + "size": len(content), + }], + ) + assert "team" not in event + assert "team_id" not in event + + await adapter._handle_slack_message(event) + + dl.assert_awaited_once() + assert dl.await_args.kwargs["team_id"] == "T_SECOND" + msg_event = adapter.handle_message.call_args[0][0] + assert "Hello from workspace two" in msg_event.text + @pytest.mark.asyncio async def test_txt_document_injects_content(self, adapter): """A .txt file under 100KB should have its content injected into event text."""