← Back to PRs

#17879: fix: prevent Slack auth errors from crashing the entire gateway

by zuyan9 open 2026-02-16 08:16 View on GitHub →
channel: slack stale size: M
## 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