Skip to content

fix(slack): auto-reconnect Socket Mode on silent death (#278) - #281

Merged
vybe merged 1 commit into
mainfrom
feature/278-slack-socket-watchdog
Apr 8, 2026
Merged

fix(slack): auto-reconnect Socket Mode on silent death (#278)#281
vybe merged 1 commit into
mainfrom
feature/278-slack-socket-watchdog

Conversation

@pavshulin

Copy link
Copy Markdown
Contributor

Summary

  • Adds application-level watchdog to SlackSocketTransport that detects silent WebSocket death and forces reconnect
  • Fixes is_connected to check actual session state instead of just the _running flag
  • 28 unit tests covering health checks, ping/pong, backoff, reconnect, loop orchestration, and crash resilience

Problem

The Slack SDK's built-in monitor_current_session task can silently exit (exception, cancellation, asyncio hiccup), leaving the WebSocket dead forever with no reconnect attempt. This was observed on production every few hours (evidence in #278).

Fix

Independent watchdog in slack_socket.py that runs every 60s:

  1. Session dead? (None or .closed) → reconnect
  2. SDK monitor dead? (task exited or None) → reconnect
  3. Ping/pong — send WebSocket ping, wait 5s for pong → reconnect on timeout

Safeguards:

  • Exponential backoff on failures: 60s → 120s → 240s → 300s cap
  • Prominent ERROR log when backoff hits cap (ops visibility)
  • Never crashes the backend — all exceptions caught and logged
  • SDK's internal connect_operation_lock prevents race conditions

Verified locally

  1. Started Slack Socket Mode → watchdog running
  2. Killed socket with debug endpoint (stale mode — kills SDK monitor + closes session)
  3. is_connected immediately reported False
  4. Watchdog detected dead session within 60s, reconnected automatically
  5. Slack messages sent during downtime were redelivered by Slack after reconnect

Test plan

  • 28 unit tests pass (tests/unit/test_slack_watchdog.py)
  • Manual reproduction: kill socket → watchdog recovers
  • Status endpoint reflects real connection state
  • Monitor on production for 24h after deploy

Closes #278

🤖 Generated with Claude Code

#278)

The Slack SDK's built-in monitor can silently exit, leaving the WebSocket
dead with no reconnect attempt. Adds an independent application-level
watchdog that checks session health, monitor state, and ping/pong every
60s — forces reconnect with exponential backoff (60s→300s cap).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Slack Socket Mode connection silently dies — no auto-reconnect

2 participants