Skip to content

feat: Channel adapter abstraction with multi-agent Slack support (#63) - #156

Merged
vybe merged 5 commits into
mainfrom
slack-improvements
Mar 25, 2026
Merged

vybe merged 5 commits into
mainfrom
slack-improvements

Conversation

@pavshulin

@pavshulin pavshulin commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Pluggable channel adapter abstraction (ChannelAdapter + ChannelTransport base classes)
  • Multi-agent Slack: one app, multiple agents, each with a dedicated channel
  • Socket Mode transport (default, no public URL needed) + webhook fallback
  • Auto-create Slack channels per agent on "Connect Slack"
  • Processing indicator (⏳→✅ reactions)
  • Thread replies without @mention in bot channels
  • Bot token encrypted at rest (AES-256-GCM)
  • Tool restrictions for public Slack users (WebSearch/WebFetch only)
  • Rate limiting (30 msg/min per user, configurable)
  • TaskExecutionService integration (audit trail, activity tracking, slots)
  • PUBLIC_CHAT_URL moved to Settings DB

Test plan

  • Socket Mode connects on backend startup
  • @mention in agent channel → routed to correct agent
  • "Connect Slack" on second agent → creates separate channel
  • Thread reply without @mention works in bot channel
  • ⏳ reaction appears during processing, ✅ after
  • Agent response shows agent name via chat:write.customize
  • Bot token stored encrypted in DB (not plaintext)
  • Rate limiting blocks rapid messages
  • Tool restriction verified (no Bash/Read/Write for Slack users)
  • Webhook mode still works as fallback

Closes #63

🤖 Generated with Claude Code

@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 — REQUEST CHANGES

The code quality and architecture are solid — the adapter abstraction is clean, SQL is properly parameterized, and the transport layer (Socket Mode + webhook) is well-separated. However, this is a new capability and per Trinity development workflow requires documentation updates across all tiers before merge.

Required Before Merge

  • Changelog — Add entry to docs/memory/changelog.md with timestamp and emoji
  • Requirements — Add entry to docs/memory/requirements.md (new capability: channel adapters + Slack integration)
  • Architecture — Update docs/memory/architecture.md with new DB tables (slack_workspaces, slack_channel_agents), adapters/ module, and API endpoints
  • Feature flow — Create feature flow document for Slack message routing (message → adapter → router → agent → response)

Code Issues to Address

  • Memory leak in rate limiter — _rate_limit_buckets in message_router.py never prunes empty buckets. Add periodic cleanup of stale entries.
  • Configurable limits — Rate limit (30/60s), timeout (120s), and allowed tools list are hardcoded. Move to settings_service for operational flexibility.

Suggestions (Non-blocking)

  • Duck-typed handle_verification via hasattr() breaks the adapter abstraction — consider an optional method on ChannelAdapter base class
  • String-based error matching ("at capacity", "billing") is fragile — prefer structured error types
  • Step-by-step logging (10+ INFO lines per message) will create high volume — consider DEBUG level for intermediate steps
  • Consider Redis-backed rate limiting for multi-instance deployments

Please address the required items and request re-review.

 Pavlo and others added 4 commits March 24, 2026 12:46
      - Extract ChannelAdapter/ChannelTransport base classes for pluggable messaging
      - Implement SlackAdapter with channel-based multi-agent routing
      - Add Socket Mode transport (no public URL needed) + webhook fallback
      - Auto-create Slack channels per agent on "Connect Slack"
      - Per-agent channel routing via slack_channel_agents table
      - chat:write.customize for agent identity on responses
      - TaskExecutionService integration (audit trail, activity tracking, slots)
      - Tool restrictions for public Slack users (WebSearch/WebFetch only)
      - Rate limiting (30 msg/min per Slack user)
      - PUBLIC_CHAT_URL moved to Settings DB with env fallback
      - New DB tables: slack_workspaces, slack_channel_agents

      Closes #63
…s, thread tracking, docs (SLACK-002)

Fix memory leak in _rate_limit_buckets by adding periodic pruning of stale
entries. Move hardcoded rate limit, timeout, and allowed tools to
settings_service for operational flexibility. Add handle_verification() to
ChannelAdapter base class replacing duck-typed hasattr() check. Downgrade
step-by-step router logging from INFO to DEBUG. Add thread watching and
writing mechanism for reply-without-mention support. Add required
documentation: changelog, requirements, architecture (DB tables), and
feature flow document.
- Encrypt bot_token in slack_workspaces table using AES-256-GCM
  (same pattern as subscription_credentials)
- Backward compatible: plaintext xoxb- tokens auto-detected on read
- Updated changelog with full SLACK-002 feature list
- Updated architecture with webhook transport + encryption note
- Updated security findings with encryption fix + health check follow-up

Closes #63

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Feature flow: added User Story, Frontend Layer, Backend Layer,
  Side Effects, Error Handling, Security Considerations, Testing sections
- Changelog: added emoji prefix (✨) and time to timestamp

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@pavshulin
pavshulin force-pushed the slack-improvements branch from c4a99d4 to d944f55 Compare March 24, 2026 13:48
Resolve conflicts in changelog.md and main.py:
- changelog.md: Keep main's new entries (round-robin, docs, recovery, MCP tools) at top,
  move SLACK-002 entry to correct chronological position (2026-03-23), restore Voice Chat date
- main.py: Keep both startup blocks (orphaned execution recovery from main + Slack transport from PR)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@vybe
vybe merged commit 4154d4c into main Mar 25, 2026
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.

Channel Adapter Abstraction

2 participants