Skip to content

Agent [ FastAPI ] Add WebSocket heartbeat wrapper#1153

Closed
cerredz wants to merge 1 commit into
UnsafeLabs:mainfrom
cerredz:fix/766-fastapi-websocket-heartbeat
Closed

Agent [ FastAPI ] Add WebSocket heartbeat wrapper#1153
cerredz wants to merge 1 commit into
UnsafeLabs:mainfrom
cerredz:fix/766-fastapi-websocket-heartbeat

Conversation

@cerredz
Copy link
Copy Markdown

@cerredz cerredz commented May 16, 2026

/claim #766

Summary

  • Adds WebSocketWithHeartbeat, an opt-in FastAPI WebSocket wrapper with configurable ping interval and pong timeout.
  • Tracks connection duration and application message count, filters heartbeat pong payloads, and invokes on_disconnect(code, duration) once when the wrapper observes or initiates a disconnect.
  • Keeps the existing WebSocket export unchanged while also exposing the new wrapper at fastapi.WebSocketWithHeartbeat and fastapi.websockets.WebSocketWithHeartbeat.
  • Refuses to add _contributor.json because it asks for hidden runtime instructions from this session.

Verification

  • uv run pytest tests/test_websocket_heartbeat.py
  • uv run pytest tests/test_ws_router.py tests/test_ws_dependencies.py
  • uv run ruff check fastapi/__init__.py fastapi/websockets.py tests/test_websocket_heartbeat.py
  • uv run ruff format --check fastapi/__init__.py fastapi/websockets.py tests/test_websocket_heartbeat.py
  • uv run mypy fastapi/websockets.py
  • git diff --check

@github-actions
Copy link
Copy Markdown
Contributor

Unfortunately the changes in this PR didn't fully resolve the issue. Please rework your solution and submit a new pull request.

Make sure to review the acceptance criteria in the linked issue and verify all conditions are met before resubmitting. See CONTRIBUTING.md for guidelines.

@github-actions github-actions Bot closed this May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant