Skip to content

Add Discord adapter health check using client.ws.ping#87

Merged
chapel merged 1 commit intomainfrom
test/bot-restart-recovery
Feb 3, 2026
Merged

Add Discord adapter health check using client.ws.ping#87
chapel merged 1 commit intomainfrom
test/bot-restart-recovery

Conversation

@chapel
Copy link
Copy Markdown
Contributor

@chapel chapel commented Feb 3, 2026

Summary

  • Add optional healthCheck() method to ChannelAdapter interface for platform-specific health verification
  • Implement healthCheck() in Discord adapter using client.ws.ping to verify WebSocket connection health
  • Update ChannelLifecycleManager to call adapter's healthCheck() method if available
  • Add comprehensive test coverage (8 tests) for all health check scenarios

Changes

Core Interface (packages/core/src/types/channel-adapter.ts):

  • Added optional healthCheck() method to ChannelAdapter interface

Discord Adapter (packages/channels/src/adapters/discord/adapter.ts):

  • Implemented healthCheck() method that:
    • Returns false if adapter not started
    • Checks WebSocket status (must be 0 = READY)
    • Validates ping latency is >= 0 and < 10000ms
    • Catches and logs exceptions gracefully

Lifecycle Manager (packages/channels/src/lifecycle.ts):

  • Updated performHealthCheck() to call adapter.healthCheck() if available
  • Maintains backward compatibility with adapters that don't implement health checks

Tests (packages/channels/test/adapters/discord/adapter.test.ts):

  • 8 comprehensive tests covering:
    • Not started state
    • Missing WebSocket
    • Wrong WebSocket status
    • Negative ping
    • Excessive ping (> 10s threshold)
    • Healthy connection
    • Edge cases (ping at threshold)
    • Exception handling

Test Plan

  • All 1567 existing tests pass
  • 8 new health check tests pass
  • TypeScript compilation succeeds
  • Linting passes
  • Manual verification of health check logic

Task: @01KGGTRK

🤖 Generated with Claude Code

Implement health check functionality for Discord adapter to verify connection
status using WebSocket ping.

Changes:
- Add optional healthCheck() method to ChannelAdapter interface
- Implement healthCheck() in Discord adapter using client.ws.ping
  - Checks WebSocket status (READY = 0)
  - Validates ping latency (>= 0 and < 10s)
  - Returns false if not started or on errors
- Update ChannelLifecycleManager to call adapter.healthCheck() if available
- Add 8 comprehensive tests for all health check scenarios

Task: @01KGGTRK

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@chapel
Copy link
Copy Markdown
Contributor Author

chapel commented Feb 3, 2026

PR Review Summary

Implementation Review

Quality: Excellent

Changes:

  1. ✅ Added optional healthCheck() method to ChannelAdapter interface (packages/core/src/types/channel-adapter.ts:96-104)
  2. ✅ Implemented healthCheck() in Discord adapter (packages/channels/src/adapters/discord/adapter.ts:221-249)
    • Returns false if not started
    • Checks WebSocket status (must be 0 = READY)
    • Validates ping is >= 0 and < 10000ms
    • Catches and logs exceptions gracefully
  3. ✅ Updated ChannelLifecycleManager.performHealthCheck() to call adapter's health check if available (packages/channels/src/lifecycle.ts:314-346)
  4. ✅ Added 8 comprehensive tests covering all scenarios (packages/channels/test/adapters/discord/adapter.test.ts:1109-1247)

Test Coverage

All health check scenarios covered:

  • ✅ Not started state
  • ✅ Missing WebSocket
  • ✅ Wrong WebSocket status (not READY)
  • ✅ Negative ping
  • ✅ Excessive ping (> 10s threshold)
  • ✅ Healthy connection
  • ✅ Edge cases (ping at 9999ms threshold)
  • ✅ Exception handling

Spec Alignment

Note: This task has no spec_ref, so this is an infrastructure improvement without formal acceptance criteria.

Implementation follows best practices:

  • ✅ Optional method pattern maintains backward compatibility
  • ✅ Comprehensive error handling
  • ✅ Clear logging for diagnostics
  • ✅ Well-documented interface

CI Status

  • ✅ Tests passing (1567 tests)
  • ✅ Unresolved comments check passing
  • ⏳ Claude review still in progress (non-blocking)

Issues Found

None - all quality gates pass.

Verdict

Ready to merge.

Implementation is clean, well-tested, and follows established patterns. The optional health check method enables platform-specific health monitoring without breaking existing adapters.

@claude
Copy link
Copy Markdown

claude bot commented Feb 3, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@chapel chapel merged commit 6376521 into main Feb 3, 2026
3 checks passed
@chapel chapel deleted the test/bot-restart-recovery branch February 3, 2026 09:50
chapel added a commit that referenced this pull request Feb 3, 2026
…thod to ChannelAdapter interface and implemented it in Discord adapter using client.ws.ping for WebSocket health monitoring. Includes 8 comprehensive tests covering all scenarios (not started, missing WS, wrong status, negative/excessive ping, healthy connection, edge cases, exceptions). All 1567 tests passing. Implementation follows optional method pattern for backward compatibility.
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.

1 participant