Skip to content

feat(websocket): freshness-based health check with disconnect reason#18

Open
kevinypfan wants to merge 2 commits into
mainfrom
feat/healthcheck-freshness
Open

feat(websocket): freshness-based health check with disconnect reason#18
kevinypfan wants to merge 2 commits into
mainfrom
feat/healthcheck-freshness

Conversation

@kevinypfan

Copy link
Copy Markdown
Collaborator

What

Python counterpart of the Node freshness-based WebSocket health check. Keeps app-level JSON ping/pong.

Behavior

  • last_message_at updated on any inbound message; freshness compared against the last ping each tick.
  • Consecutive misses accumulate; on reaching max_missed_pongs → disconnect. Replaces the old raise Exception inside the Timer thread.
  • Health-check timeout emits the disconnect event with a { reason: 'health-check-timeout' } payload (via pyee); normal disconnect has none. Non-breaking.
  • Config unchanged (enabled default False, ping_interval 30000, max_missed_pongs 2). No auto-reconnect; no error event.

Tests / docs

  • New TestWebSocketHealthCheck in tests/test_websocket_client.py → 29 passed.
  • README: equivalent Health Check section.

Note: the repo's tests/test_http_client.py has a pre-existing breakage fixed separately in #(fix/rest-test-mocks PR). All websocket tests pass.

🤖 Generated with Claude Code

kevinypfan and others added 2 commits June 22, 2026 17:30
Replace the blind missed-pong counter (which raised inside a Timer thread)
with freshness-based detection: track last_message_at (any inbound message)
and last_ping_at, and on each interval tick count a miss only when nothing
arrived since the last ping. Disconnect after max_missed_pongs consecutive
misses and stop the timer.

On a health-check timeout the disconnect event is now emitted via the pyee
EventEmitter with an extra {"reason": "health-check-timeout"} argument;
normal/manual disconnects emit without it, keeping existing listeners
working. Keeps the app-level JSON ping/pong transport.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A value of 0 would disconnect a healthy connection on the first tick
(consecutive_misses starts at 0). Clamp to >= 1.

Co-Authored-By: Claude Opus 4.8 (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.

1 participant