Skip to content

fix(socket-mode): handle events_api payloads without an inner event - #2787

Open
levenleven wants to merge 1 commit into
slackapi:mainfrom
levenleven:levenleven/fix/socket-mode-app-rate-limited
Open

levenleven wants to merge 1 commit into
slackapi:mainfrom
levenleven:levenleven/fix/socket-mode-app-rate-limited

Conversation

@levenleven

@levenleven levenleven commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Slack sends app_rate_limited notifications as events_api envelopes with no inner event, which crashed the Socket Mode client with Cannot read properties of undefined (reading 'type'). The client now emits the payload type (e.g. app_rate_limited) for these messages. slack_event listeners still receive the message.

Fixes #2167
Fixes #2753

Requirements

@changeset-bot

changeset-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0b075d5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@slack/socket-mode Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@levenleven
levenleven force-pushed the levenleven/fix/socket-mode-app-rate-limited branch from 7e2d80c to d6cd625 Compare October 21, 2026 04:35
@levenleven
levenleven marked this pull request as ready for review October 21, 2026 04:35
@levenleven
levenleven requested a review from a team as a code owner October 21, 2026 04:35
@levenleven
levenleven force-pushed the levenleven/fix/socket-mode-app-rate-limited branch from d6cd625 to 38a11ed Compare October 21, 2026 06:24
@hello-ashleyintech hello-ashleyintech self-assigned this Oct 21, 2026
@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.41%. Comparing base (8730b5e) to head (38a11ed).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2787      +/-   ##
==========================================
+ Coverage   89.34%   89.41%   +0.06%     
==========================================
  Files          65       65              
  Lines       10548    10560      +12     
  Branches      480      483       +3     
==========================================
+ Hits         9424     9442      +18     
+ Misses       1092     1086       -6     
  Partials       32       32              
Flag Coverage Δ
cli-hooks 89.27% <100.00%> (-0.02%) ⬇️
cli-test 89.27% <100.00%> (-0.02%) ⬇️
logger 89.27% <100.00%> (-0.02%) ⬇️
oauth 89.27% <100.00%> (-0.02%) ⬇️
socket-mode 89.27% <100.00%> (-0.02%) ⬇️
web-api 89.27% <100.00%> (-0.02%) ⬇️
webhook 89.27% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hello-ashleyintech

Copy link
Copy Markdown
Contributor

Thanks so much for tracking this down and putting together a fix — this crash has been open for a while and it's great to finally have a proper solution for it!

A couple of small things worth addressing before we merge:

Test consistency (SocketModeClient.test.ts) — the new tests skip the await sleep(30) that every other test in this file uses before asserting. Technically it works here since the emit() calls in onWebSocketMessage are synchronous (no await before them), but it'll look like an oversight to the next person reading these. Either add await sleep(30) to match the rest of the file, or drop a short comment explaining why it's not needed here.

Silent drop in the else branch (SocketModeClient.ts) — when event.payload?.type is absent, the new else if block just does nothing and moves on. That's fine as a fallback, but it makes future debugging harder if Slack ever sends another unexpected events_api shape. A quick this.logger.debug(...) in that case would go a long way toward diagnosing it without any real cost.

Neither of these is a blocker — the core fix is solid — but they're worth a quick pass before merge.

Slack sends app_rate_limited notifications as events_api envelopes with no inner event, which crashed the message handler. Emit the payload type instead so apps can listen for it.
@levenleven
levenleven force-pushed the levenleven/fix/socket-mode-app-rate-limited branch from 38a11ed to 0b075d5 Compare October 22, 2026 08:06
@levenleven

Copy link
Copy Markdown
Contributor Author

Thanks for quick review @hello-ashleyintech. I've applied both suggestions.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants