#17879: fix: prevent Slack auth errors from crashing the entire gateway
channel: slack
stale
size: M
Cluster:
Slack Gateway Error Handling
## Problem
When `@slack/socket-mode`'s internal reconnection fails with an unrecoverable auth error (`account_inactive`, `invalid_auth`, etc.), the error escapes as an unhandled promise rejection. The global handler then calls `process.exit(1)`, crashing the **entire gateway** — including healthy channels like Telegram.
In practice this causes a crash loop: every restart hits the same auth error, exits again, repeat. The only fix is manual intervention (removing Slack config).
## Root Cause
`@slack/socket-mode`'s `delayReconnectAttempt()` calls `cb.apply(this).then(res)` with **no `.catch()`**. When `retrieveWSSURL()` throws an `UnrecoverableSocketModeStartError` (for errors like `account_inactive`, `invalid_auth`, `team_disabled`), the rejection is never caught.
OpenClaw's global unhandled rejection handler sees this isn't a transient network error → `process.exit(1)`.
## Fix
Register a Slack-specific unhandled rejection handler that catches Slack platform errors and logs them instead of crashing. This follows the **exact same pattern** already used by the Telegram provider for Grammy HTTP errors.
The handler:
- Catches all `slack_webapi_platform_error` rejections
- Logs clearly whether it's an auth error ("channel will stop working until tokens are updated") or a transient API error
- Returns `true` to prevent `process.exit(1)`
- Is scoped to the provider lifecycle (registered on start, unregistered in `finally`)
## Changes
| File | Description |
|------|-------------|
| `src/slack/monitor/slack-error-detection.ts` | Detection helpers: `isSlackPlatformError()`, `isSlackUnrecoverableAuthError()`, `getSlackErrorCode()` |
| `src/slack/monitor/slack-error-detection.test.ts` | 8 unit tests for detection functions |
| `src/slack/monitor/provider.ts` | Registers the unhandled rejection handler |
| `src/slack/monitor/provider.unhandled-rejection.test.ts` | 12 integration tests with the global rejection system |
## Testing
- 195 tests pass across all Slack + unhandled rejection test suites
- Zero breakage in existing tests
- TypeScript compiles cleanly
Fixes #6867
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Prevents Slack authentication errors from crashing the entire gateway by registering a scoped unhandled rejection handler. When `@slack/socket-mode` encounters unrecoverable auth errors (`account_inactive`, `invalid_auth`, etc.) during reconnection, these now log clearly instead of causing `process.exit(1)`.
- Follows the exact same pattern already used by the Telegram provider for Grammy HTTP errors
- Only suppresses unrecoverable auth errors; other Slack platform errors (like `channel_not_found`, `missing_scope`) correctly bubble up
- Handler properly unregistered in `finally` block to prevent memory leaks
- Well-tested with 20 unit and integration tests covering auth errors, non-auth platform errors, cleanup, and edge cases
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The fix is surgical and well-tested. It follows an existing proven pattern from the Telegram provider, only suppresses the specific unrecoverable auth errors that cause crash loops, and has comprehensive test coverage. The previous reviewer concern about suppressing all Slack platform errors has been addressed - the code now only returns `true` for unrecoverable auth errors (lines 355-361 in provider.ts) and explicitly lets other platform errors bubble up.
- No files require special attention
<sub>Last reviewed commit: a7d4bb3</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#12369: fix: register unhandled rejection handler for Slack monitor
by Yida-Dev · 2026-02-09
84.6%
#23787: Handle transient Slack request errors without crashing the gateway
by graysurf · 2026-02-22
82.3%
#21163: Prevent Slack DNS errors from crashing the gateway
by graysurf · 2026-02-19
79.9%
#22096: fix(slack): traverse .original for Slack SDK errors; pass recipient...
by maiclaw · 2026-02-20
78.7%
#22896: Handle Slack SDK .original in transient network detection
by creditblake · 2026-02-21
78.0%
#19083: Slack: preserve per-thread context and consistent thread replies
by jkimbo · 2026-02-17
77.7%
#21967: Harden Slack allow-from resolution against undefined catch crash
by graysurf · 2026-02-20
77.2%
#21809: fix(slack): prevent native command startup crash on options registr...
by graysurf · 2026-02-20
77.1%
#19567: Fix: tighten Slack multi-account event filtering via api_app_id
by TARS-Nolan · 2026-02-17
76.9%
#20479: fix(slack): keep replies flowing for oversized file uploads
by olyashok · 2026-02-19
76.4%