Skip to content

fix: Non-blocking Slack Socket Mode startup with token validation - #214

Merged
vybe merged 3 commits into
mainfrom
slack-fixes
Mar 27, 2026
Merged

vybe merged 3 commits into
mainfrom
slack-fixes

Conversation

@pavshulin

@pavshulin pavshulin commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes production issue where Slack Socket Mode with an invalid token blocks the entire event loop, making the backend unresponsive.

Changes

Non-blocking Socket Mode (adapters/transports/slack_socket.py)

  • Validate xapp- token format before attempting connection
  • Disable auto_reconnect on initial connect (prevents infinite retry with bad token)
  • Add 10s timeout on connect() to prevent blocking startup
  • Clean up client on timeout (disconnect() before nulling)
  • Enable auto_reconnect only after successful connection
  • Add is_connected property (public API instead of _running access)

Startup resilience (main.py)

  • Check is_connected after start() — if connection failed, log warning and continue without Slack

Settings connect endpoint (routers/settings.py)

  • Return HTTP 400 with clear message if Socket Mode connection fails
  • Start new transport before stopping old one (preserves connection on failure)

Note: Dockerfile + deploy script fix for adapters/ was merged separately in PR #194.

Test plan (all verified locally)

  • Start backend with valid token → Socket Mode connects, auto-reconnect enabled
  • Start backend with invalid xapp- token → timed out at 10s, backend healthy
  • Start backend with non-xapp token → instantly rejected, backend healthy
  • Start backend with NO Slack config at all → skips Slack, all APIs work normally
  • Settings > Connect with bad token → returns 400, old connection preserved
  • Production deploy → no ModuleNotFoundError (PR fix: Add adapters/ to backend Dockerfile and deploy script #194)

Fixes #215

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Validation Report

Files Changed: 3 (+43/-16) | Branch: slack-fixes → main

Issues Found

Critical (Block Merge)

  1. Missing changelog entry — docs/memory/changelog.md not updated. All PRs require a changelog entry.

  2. PR description claims Dockerfile + deploy script changes not present in diff — The body lists COPY adapters/ in Dockerfile and adapters in gcp-deploy.sh, but the diff only contains 3 Python files. If the Dockerfile isn't updated, the ModuleNotFoundError this PR claims to fix won't actually be resolved.

Warnings

  1. No GitHub Issue linked — A production-blocking bug fix should have an associated issue for tracking.

  2. Accessing private _running attribute — main.py:311 and settings.py:653 both access transport._running directly. Consider adding a @property is_connected or is_running method to SlackSocketTransport.

  3. Connect-before-stop ordering in settings.py — Starting a new Socket Mode connection before stopping the old one could cause duplicate message processing during the overlap window. The previous stop-then-start approach is safer for Socket Mode.

Minor

  • slack_socket.py:37 — f-string with no interpolated variables (f"Invalid Slack App Token format..."), use a plain string.

Required Changes

  • Add changelog entry to docs/memory/changelog.md
  • Include the Dockerfile and deploy script changes mentioned in description, or update description to match actual scope
  • Link a GitHub Issue

🤖 Generated with Claude Code

@pavshulin pavshulin changed the title fix: Non-blocking Slack Socket Mode startup + add adapters/ to Dockerfile fix: Non-blocking Slack Socket Mode startup with token validation Mar 27, 2026
 Pavlo added 3 commits March 27, 2026 16:30
Socket Mode client with an invalid token enters infinite retry loop,
blocking the event loop and making the entire backend unresponsive.

- Validate xapp- token format before attempting connection
- Disable auto_reconnect on initial connect (prevent infinite retry)
- Add 10s timeout on connect attempt
- Enable auto_reconnect only after successful connection
- Backend continues without Slack if connection fails (non-blocking)
- Settings connect endpoint returns 400 with clear message on failure
…leanup

- Add is_connected property to SlackSocketTransport (avoid _running access)
- Use is_connected in main.py and settings.py
- Fix f-string with no interpolation
- Add changelog entry for 2026-03-27
- Document connect-before-stop trade-off

Fixes #215

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated against Trinity development methodology — all checks pass.

Documentation: Changelog entry present (minor nit: missing emoji prefix, not blocking).
Security: All 6 security checks passed — no secrets, credentials, or PII.
Code Quality: Well-scoped fix. Token validation, 10s timeout, graceful fallback, and is_connected property are all solid patterns.
Traceability: Links to #215.

LGTM ✅

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 blocks event loop on invalid token

2 participants