Skip to main content

Overview

OpenClaw Gateway is a production-ready gateway server designed for orchestrating multiple AI agents at scale. Mission Control connects to OpenClaw Gateway via WebSocket for real-time session management, log streaming, and agent coordination.
For simpler deployments, see CLI Integration for direct REST/SSE connections without a gateway.

Architecture

Key Features:
  • WebSocket Protocol v3: Binary-efficient, fully-typed messaging
  • Device Identity Auth: Ed25519 signature-based authentication
  • Session Management: Multi-session tracking with token accounting
  • Real-time Logs: Structured log streaming from agents to UI
  • Agent Spawning: On-demand process lifecycle management
  • Heartbeat Protocol: 30s ping/pong with RTT tracking

Connection Protocol

1. WebSocket Handshake

Mission Control initiates a WebSocket connection with protocol negotiation:
1

Connect to Gateway

No query parameters needed — authentication happens post-connect.
2

Receive Challenge

Gateway sends a connect.challenge event with a nonce:
3

Send Connect Request with Device Auth

Mission Control signs the nonce with Ed25519 device identity:
Signature Payload (v2 format):
Signed using Ed25519 private key stored in browser IndexedDB.
4

Receive Connection Confirmation

Gateway validates signature and responds:
Connection is now authenticated. Mission Control caches deviceToken for faster reconnects.

2. Heartbeat Protocol

Mission Control sends ping requests every 30 seconds:
Gateway responds:
Timeout Behavior:
  • If 3 consecutive pongs are missed → force reconnect
  • RTT (round-trip time) is calculated: Date.now() - sentTimestamp
  • Displayed in Mission Control UI as connection latency

3. Event Stream

Gateway broadcasts real-time events:

Session Update

Log Entry

Agent Status

Device Identity Authentication

What is Device Identity?

OpenClaw Gateway supports device-based authentication using Ed25519 cryptographic signatures. Each browser generates a unique device identity stored locally, preventing credential sharing and enabling per-device authorization.

Security Benefits

  • No password transmission over network
  • Device-bound sessions cannot be hijacked
  • Revocable per-device access
  • Cryptographic proof of identity

User Experience

  • Automatic authentication after first setup
  • No password re-entry on reconnect
  • Multi-device support (each device has unique identity)
  • Transparent to user (happens in background)

Key Generation

On first connection, Mission Control generates an Ed25519 keypair:
Storage:
  • Private key: IndexedDB (non-extractable, browser-bound)
  • Public key: Sent to gateway during connect
  • Device ID: UUID stored in localStorage
Device identity requires HTTPS or localhost (WebCrypto API restriction). Self-signed certificates are supported.

Signature Process

  1. Gateway sends nonce in connect.challenge
  2. Mission Control builds signature payload:
  3. Sign payload using Ed25519 private key
  4. Send signature + publicKey + nonce in connect request
  5. Gateway verifies signature using public key
  6. Returns deviceToken for faster future reconnects

Device Token Caching

After successful authentication, gateway issues a device token:
  • Short-lived token (e.g., 24 hours)
  • Can be used instead of full signature on reconnect
  • Stored in localStorage as mc_device_token
  • Automatically included in connect params
Reconnect flow:

Gateway Configuration

Control UI Settings

Gateway must explicitly allow Mission Control origin:
If your origin is not in allowedOrigins, you’ll receive:
Add your Mission Control URL to the gateway config and restart.

Device Auth Settings

If requireSignature: true, Mission Control must provide device signature. HTTP-only deployments (without WebCrypto) will fail.

TLS Configuration

Mission Control connects via wss:// (WebSocket Secure).

Spawn Agents

Gateway can spawn agent processes on-demand:
Response:
When process exits:

Error Handling

Non-Retryable Errors

Mission Control stops reconnecting for these errors: User Experience:
  • Error displayed in Mission Control logs panel
  • Notification: “Gateway Handshake Blocked” with actionable help text
  • Reconnect button disabled until error is resolved

Retryable Errors

Auto-reconnect with exponential backoff for:
  • Network errors (DNS, connection refused)
  • WebSocket close codes (except 4001 non-retryable)
  • Heartbeat timeout (3 missed pongs)
Backoff schedule:

Deployment

Docker Compose

Systemd Service

Nginx Reverse Proxy

Proxy WebSocket connections through Nginx:

Monitoring

Connection Health

Mission Control UI displays:
  • Connection Status: Connected / Disconnected / Reconnecting
  • Latency: Real-time RTT from ping/pong (ms)
  • Reconnect Attempts: Counter during reconnection
  • Protocol Version: Negotiated protocol (should be 3)

Gateway Metrics

OpenClaw Gateway exposes Prometheus metrics:
Key metrics:
  • openclaw_gateway_connections_total - Active WebSocket connections
  • openclaw_gateway_messages_sent_total - Messages sent to clients
  • openclaw_gateway_messages_received_total - Messages from clients
  • openclaw_gateway_spawn_requests_total - Agent spawn requests
  • openclaw_gateway_auth_failures_total - Failed authentications

Logs

Gateway structured logs:
Example log entries:

Troubleshooting

Cause: Gateway not sending connect.challenge event.Debug:
  1. Check gateway logs for connection attempt
  2. Verify gateway is running: systemctl status openclaw-gateway
  3. Test WebSocket manually:
  4. Check firewall rules allow port 8080
Error: device_auth_signature_invalidSolutions:
  1. Clear device identity:
    • Chrome DevTools → Application → IndexedDB → Delete device-identity
  2. Reconnect (triggers new key generation)
  3. Check browser console for WebCrypto errors
  4. Ensure HTTPS (or localhost) for WebCrypto access
Error: origin not allowedSolution: Add Mission Control origin to gateway config:
Restart gateway:
Cause: Network instability or proxy timeout.Solutions:
  • Check Mission Control logs for error patterns
  • Verify 30s heartbeats are being sent
  • Increase proxy timeout (nginx: proxy_read_timeout 300s)
  • Check for firewall/NAT issues
  • Monitor RTT — high latency may indicate network issues
Error: spawn_result with status: 'failed'Debug:
  1. Check gateway has permissions to execute command
  2. Verify cwd path exists
  3. Check agent script has execute permission: chmod +x agent.py
  4. Review gateway logs for spawn errors
  5. Test command manually:

Security Considerations

TLS Required

Always use WSS (WebSocket Secure) in production:
Device auth requires HTTPS for WebCrypto API access.

Origin Whitelist

Limit allowedOrigins to trusted domains:
Never use * (wildcard) in production.

Device Limits

Prevent device proliferation:
Users must re-authenticate after token expiry.

Audit Logs

Enable gateway audit logging:

CLI Integration

Simpler REST/SSE alternative

WebSocket Client

Client implementation details

Authentication

API key and role-based auth