Connector
The connector enables bidirectional communication between your application (via the Rhesis SDK), the Rhesis backend, and worker processes. It allows remote function execution and automatic endpoint registration without manual configuration.
System Architecture
The connector connects three main components: your target application (via the SDK), the Rhesis backend, and worker processes.
Target Application (SDK):
- Decorates functions with
@endpoint - Maintains WebSocket connection to backend
- Executes functions when requested
- Sends results back via WebSocket
Rhesis Backend:
- Manages WebSocket connections from SDK clients
- Receives function registrations
- Creates/updates endpoint records in database
- Forwards test execution requests to SDK
- Publishes responses to Redis for workers
Workers:
- Execute tests asynchronously via Celery
- Use Redis RPC to invoke SDK functions
- Cannot directly access backend’s in-memory WebSocket connections
- Subscribe to Redis channels for SDK responses
Connection Flow
Initial Connection:
- Target app starts → SDK initializes
RhesisClientwithproject_idandenvironment - SDK establishes an authenticated WebSocket connection to the backend (
/connector/ws) — project/environment binding happens later, not at connect time - SDK sends a
registermessage with function metadata, binding the connection toproject_id/environment - Backend stores the connection routing and creates endpoint records
Test Execution Flow:
- Worker receives test execution task
- Worker looks up which backend instance owns the connection (
ws:routing:{project_id}:{environment}) and pushes the RPC request onto that instance’s queue (ws:rpc:{worker_id}) - Backend pops the request and forwards it to the SDK via WebSocket
- SDK executes the function in the target app
- SDK sends the result back via WebSocket
- Backend publishes the result to Redis (
ws:rpc:response:{test_run_id}) - Worker subscribes to that channel and receives the result
Connector hardening controls
The SDK connector WebSocket endpoint (/connector/ws) applies runtime safeguards configurable
with backend environment variables:
| Variable | Default | Behavior |
|---|---|---|
WS_MAX_MESSAGE_SIZE | 1048576 (1 MiB) | Rejects oversized SDK connector WebSocket messages |
WS_IDLE_TIMEOUT | 300 seconds | Closes inactive SDK connector WebSocket sessions |
WS_RATE_LIMIT | 50 messages/second | Applies per-connection sliding-window rate limiting |
These limits apply specifically to SDK connector traffic, not to all platform WebSocket usage.
Backend Components
Connection Manager
Manages WebSocket connections and RPC routing:
Message Handlers
SDKMessageHandler (services/connector/handler.py) dispatches each WebSocket message to a specialized handler:
handlers/registration.py: processes SDK function registration, syncs endpoints and SDK-registered metricshandlers/test_result.py: handles test execution results; for validation runs, updates endpoint status (Active/Error)handlers/pong.py: keepalive message handlinghandlers/metric_sync.py: syncs SDK-registered metrics into theMetrictable
metric_result messages are handled inline in manager.py rather than through a dedicated handler.
Mapping System
4-tier priority for request/response mapping (services/connector/mapping/mapper_service.py):
- SDK Manual: Explicit mappings from
@endpointdecorator - Existing DB: Preserved manual edits from UI
- Auto-Mapping: Pattern-based heuristics (confidence >= 0.7)
- LLM Fallback: Uses the user’s configured generation model (confidence < 0.7)
RPC Architecture
Problem
Workers run in separate processes and cannot access backend’s in-memory connection dictionary.
Solution: Redis-Based RPC
Flow:
- Worker resolves the owning backend instance via a routing key (
ws:routing:{project_id}:{environment}) - Worker pushes the request onto that instance’s Redis list (
ws:rpc:{worker_id}) - Backend pops the request (
BLPOP) and forwards it over the WebSocket - SDK executes the function and returns the result
- Backend publishes the response to a per-request pub/sub channel (
ws:rpc:response:{test_run_id}) - Worker subscribes to that channel and receives the result
WebSocket Protocol
Message Types
| Type | Direction | Purpose |
|---|---|---|
register | SDK → backend | Registers functions/metrics, optionally binds project_id/environment |
connected | backend → SDK | Sent immediately on connect, before registration |
execute_test | backend → SDK | Requests function execution |
test_result | SDK → backend | Returns execution result |
execute_metric | backend → SDK | Requests metric evaluation |
metric_result | SDK → backend | Returns metric evaluation result |
pong | SDK → backend | Keepalive response |
error | backend → SDK | Oversized, rate-limited, or malformed message |
Registration Message
project_id and environment are optional in register messages for metrics-only sessions.
When they are omitted, the backend skips endpoint synchronization and still syncs registered SDK metrics.
Endpoint Synchronization
When SDK registers functions, backend automatically:
- Creates/updates endpoint records
- Generates or applies mappings
- Validates mappings via test execution
- Updates endpoint status (Active/Error/Inactive)
Key Files
Backend (apps/backend/src/rhesis/backend/app/):
routers/connector.py- WebSocket and REST endpointsservices/connector/manager.py- Connection managementservices/connector/handler.py- Message dispatch facadeservices/connector/handlers/- Specialized message handlersservices/connector/schemas.py- Wire protocol message schemasservices/connector/mapping/- Mapping logicservices/connector/rpc_client.py- Worker RPC clientservices/connector/redis_client.py- Redis connectionservices/endpoint/sdk_sync.py- Endpoint synchronization
SDK (sdk/src/rhesis/sdk/):
clients/rhesis.py-RhesisClientconnector/manager.py- SDK connector managerconnector/connection.py- WebSocket connectionconnector/executor.py- Function dispatchdecorators/endpoint.py-@endpointdecorator
Related Documentation - Backend - Worker - SDK Connector