On this page
BrainWorkerBridge manages one worker's WebSocket connection on the brain side: sends ExecuteToolCall, matches results by call_id via per-call Futures, and runs heartbeat ping/pong for liveness.
#worker.src.orxtra.worker._brain
#worker.src.orxtra.worker._brain
Brain-worker bridge: manages a single worker WebSocket connection.
The brain side of the protocol. Sends ExecuteToolCall messages to the worker, awaits ToolCallResult responses. Handles heartbeat ping/pong and tracks worker connection state.
#WorkerDisconnectedError
Raised when a tool call is attempted on a disconnected worker.
#ToolCallTimeoutError
Raised when a worker does not respond to a tool call within the timeout.
#BrainWorkerBridge
Manages the WebSocket connection to a single worker.
Thread-safe for concurrent tool calls: each call gets a unique call_id and its own Future. The receive loop dispatches responses to the correct Future.
#connected
def connected(self) -> bool#worker_id
def worker_id(self) -> UUID#start
def start(self) -> NoneStart the receive and heartbeat loops.
#stop
async def stop(self) -> NoneStop the receive and heartbeat loops.
#send_tool_call
async def send_tool_call(self, call: ExecuteToolCall, timeout: float | None=None) -> ToolCallResultSend a tool call to the worker and await the result.
Idempotent: if a result for this call_id is already cached, returns the cached result without re-sending.
#_receive_loop
async def _receive_loop(self) -> NoneContinuously receive messages from the worker WebSocket.
#_dispatch_message
def _dispatch_message(self, raw: str) -> NoneParse and dispatch a single message from the worker.
#_heartbeat_loop
async def _heartbeat_loop(self) -> NoneSend heartbeats and detect timeouts.
#_mark_disconnected
def _mark_disconnected(self) -> NoneMark the worker as disconnected and fail pending calls.
#_serialize_message
def _serialize_message(msg_type: str, model: Any) -> strSerialize a protocol message as a JSON envelope.