Implement endpoint health ws#8
Conversation
…ures - Implemented RGB LED chenillard that runs on startup when connected to rosbridge. - Updated README to include instructions for standalone LED testing and configuration options. - Enhanced telemetry service to monitor linear velocity and critical battery levels, with corresponding audit events. - Updated adapter factory to support new RGB functionality and ensure proper configuration handling. - Added tests for new features, including telemetry checks for battery and velocity thresholds.
Review Summary by QodoAdd RGB chenillard, teleop commands, odometry tracking, and health endpoint
WalkthroughsDescription• Add RGB LED chenillard animation via rosbridge with configurable parameters • Implement teleop velocity commands and emergency stop publishing to robot • Add odometry subscription to track linear velocity with high-velocity alerts • Extend telemetry with battery critical threshold and velocity monitoring • Add health diagnostic endpoint for backend validation • Enhance configuration system with teleop limits, message types, and audit logging Diagramflowchart LR
A["Config<br/>common + env"] -->|"teleop, rgb,<br/>msg_types"| B["Factory"]
B -->|"creates"| C["RosbridgeAdapter"]
C -->|"on connect"| D["RgbChenillard"]
D -->|"publish"| E["rosbridge<br/>/rgb"]
C -->|"subscribe"| F["/odom"]
F -->|"linear_x"| G["TelemetryService"]
G -->|"velocity > threshold"| H["AuditEvent<br/>velocity.high"]
I["WebSocket<br/>teleop.move"] -->|"send_velocity"| C
C -->|"publish"| J["/cmd_vel"]
K["WebSocket<br/>emergency_stop"] -->|"emergency_stop"| C
C -->|"publish"| L["/emergency_stop"]
M["WebSocket<br/>get_health"] -->|"handler"| N["health_response"]
File Changes1. src/robocoop_backend/robocoop_backend/adapters/base_adapter.py
|
Code Review by Qodo
1. Publish spams on disconnect
|
| async def publish(self, topic: str, msg_type: str, msg: Dict[str, Any]) -> None: | ||
| if not self._websocket: | ||
| logger.error("Cannot publish: not connected") | ||
| return | ||
| try: | ||
| await self._websocket.send(json.dumps({ | ||
| "op": "publish", | ||
| "topic": topic, | ||
| "type": msg_type, | ||
| "msg": msg, | ||
| })) | ||
| except Exception as e: | ||
| logger.error(f"Publish failed on {topic}: {e}") |
There was a problem hiding this comment.
1. Publish spams on disconnect 🐞 Bug ☼ Reliability
RosbridgeClient.publish() sends as long as _websocket is non-null, even after the connection is closed, so the new RGB chenillard/teleop publishers will repeatedly attempt sends and emit errors while disconnected. This can generate sustained high-rate error logs (and unnecessary work) until reconnect/shutdown.
Agent Prompt
### Issue description
`RosbridgeClient.publish()` only checks `self._websocket` and does not verify that the connection is actually alive. When the socket is closed (ConnectionClosed), `_is_connected` becomes false but `_websocket` may still be set, so publish attempts will keep failing and logging.
### Issue Context
This PR introduces frequent publishes (RGB chenillard loop + teleop/emergency). During any rosbridge outage/reconnect window, the system can spam logs and waste work.
### Fix Focus Areas
- Ensure `publish()` bails out when disconnected (e.g., `if not self.is_connected(): ...`).
- Clear `self._websocket = None` when the listener observes `ConnectionClosed` (and/or when reconnect begins), so publish fast-fails.
- Consider stopping/suspending the RGB chenillard when the bridge disconnects and restarting it on reconnect.
### Fix Focus Areas (code pointers)
- src/robocoop_backend/robocoop_backend/adapters/rosbridge_client.py[56-69]
- src/robocoop_backend/robocoop_backend/adapters/rosbridge_client.py[105-139]
- src/robocoop_backend/robocoop_backend/adapters/rosbridge_adapter.py[82-109]
- src/robocoop_backend/robocoop_backend/adapters/rosbridge_adapter.py[216-226]
- src/robocoop_backend/robocoop_backend/modules/robot/rgb_chenillard.py[52-65]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Summary
Add WebSocket health diagnostic endpoint and comprehensive frontend integration guide for robocoop backend.
Description
This PR introduces a complete documentation guide for frontend developers and a new diagnostic health endpoint to test the backend in isolation (especially useful with MockRobotAdapter).
The health endpoint allows frontend/testing to verify the backend is functioning correctly without requiring a real robot connection. This is particularly valuable for development and CI/CD validation.
What's Changed
Affected areas:
Key files:
src/robocoop_backend/robocoop_backend/app/contracts.py— Added MSG_GET_HEALTH, MSG_HEALTH_RESPONSE constantssrc/robocoop_backend/robocoop_backend/app/websocket_handler.py— Implemented health handlersrc/robocoop_backend/robocoop_backend/tests/unit/app/test_websocket_handler.py— Added health endpoint testDetails:
get_health(frontend → backend) andhealth_response(backend → frontend)How to Test
Manual testing (requires wscat or similar WebSocket client):