- Inbound: the platform accepts an external client connection, such as a sidecar tunnel or browser worker bridge.
- Outbound: the platform dials and holds a connection to an external service, such as a Lark or Feishu long connection.
- Internal: the platform manages an internal worker, bridge, or stream.
What It Gives You
For administrators:- a global list of active or recently disconnected plugin connections
- connection status based on heartbeat and lease
- owner instance, remote address, last seen time, and recent errors
- connection direction, such as inbound tunnel or outbound service connection
- plugin-specific metadata such as account bindings
- management actions such as disconnect
- a shared registry instead of plugin-specific connection tables
- owner-pod command routing for actions such as disconnect or send request
- a consistent pattern for multi-pod production deployments
- a place to store operational metadata without expanding the platform schema
When to Use It
Use Managed Connections when a plugin owns a long-lived resource that is tied to one API instance:- WebSocket or Socket.IO clients
- outbound WebSocket connections to messaging platforms
- reverse tunnel sidecars
- SSE streams
- TCP tunnel clients
- background bridge workers
- custom long-running transport clients
How It Works
Managed Connections use two platform services:- Postgres registry: stores connection identity, owner instance, status, lease, timestamps, tenant/organization scope, and metadata.
- Redis command router: sends a management command to the API pod that owns the live connection.
- A plugin accepts a long-lived client connection.
- The plugin registers the connection with the platform.
- The plugin refreshes heartbeat and metadata while the client remains connected.
- Admin views read the shared registry and show all visible connections.
- Management actions are routed to the owner pod.
- If a connection stops heartbeating, the lease expires and the record becomes stale.
Lark Long Connection Example
@xpert-ai/plugin-lark uses Managed Connections for outbound long connections to Lark or Feishu OpenAPI. When an integration uses long_connection mode, the plugin opens an outbound WebSocket and registers the live session like this:
LarkLongConnectionService refreshes heartbeat and metadata such as tenant or organization scope, integration count, last connected time, last seen time, and recent errors.
In the Lark integration view:
- the Status page shows connection mode, state, connection key, direction, transport, owner instance, heartbeat, last connected time, and errors
- the Connections page lists the active global long connection record
- reconnect and disconnect actions are routed to the pod that owns the live WebSocket
Status Meaning
- Connected: the connection is active and its lease has not expired.
- Stale: the connection stopped heartbeating. The owner pod may have crashed or lost connectivity.
- Disconnected: the plugin or an administrator closed the connection.
- Error: the plugin reported an operational error for the connection.
Metadata
Managed Connection metadata is plugin-defined. It should stay operational and compact. Good metadata examples:- client name
- external instance id
- bindings to plugin business objects
- last sync time
- last ping time
- last error summary
Developer Notes
Plugins access this capability through@xpert-ai/plugin-sdk tokens:
MANAGED_CONNECTION_REGISTRY_TOKENCONNECTION_COMMAND_ROUTER_TOKEN
Current Limits
- The first implementation is scoped to one API cluster and shared database.
- Redis Pub/Sub is used for low-latency commands, not durable command storage.
- If the owner pod disappears, the record becomes stale after the lease TTL.
- Cross-region or cross-cluster connection management should be added as a higher-level platform routing layer.