Skip to content

How tunnels work

This page explains Gambi’s tunnel-first transport: why the participant, not the hub, opens the connection.

An earlier version of Gambi treated each participant as a small HTTP server:

  1. The participant ran a local provider (Ollama, LM Studio, etc.).
  2. It told the hub, “my endpoint is reachable at http://host:port”.
  3. The hub routed each inference request by making an HTTP call back to that address.

This worked on a flat LAN, but it leaked several constraints into the participant:

  • the participant had to be reachable from the hub
  • NAT, Wi-Fi isolation, and VPN split-tunneling often blocked that path
  • the participant had to expose a port, which is a lot to ask of a teammate on a laptop
  • the hub had to rewrite or trust provider addresses it never owned

The result was a system that demanded network symmetry where there wasn’t any.

Gambi now inverts the connection. The participant opens a WebSocket to the hub. Inference requests travel over that tunnel.

Participant machineHTTPopens WebSocketHTTP on localhostYour appHubParticipant runtimeLocal providerOllama, LM Studio, vLLM
Participant machineHTTPopens WebSocketHTTP on localhostYour appHubParticipant runtimeLocal providerOllama, LM Studio, vLLM
Both connections point at the hub. The provider stays on localhost.

What changes:

  • the hub never initiates a connection to the participant
  • the participant can keep its provider endpoint on localhost
  • authentication headers stay on the participant runtime
  • the hub routes by participant-id, model name, model:<name>, or *, and forwards the request through the tunnel the participant already opened

Harness participants use the same connection direction. Their harness process stays local and sends messages and artifacts through the participant-opened tunnel. A harness client attaches to that participant through the hub, with an event stream and plain HTTP requests. The hub only relays between connections it did not originate. Harness participants are not candidates for inference routing.

Participant machineHTTP and SSEparticipant tunnelstdioHarness clientor applicationHubParticipant runtimeHarnessACP v1 process
Participant machineHTTP and SSEparticipant tunnelstdioHarness clientor applicationHubParticipant runtimeHarnessACP v1 process
The hub relays ACP messages between two connections it did not open.

Each ACP message travels with a sessionId. The hub checks that pair, then forwards the message without reading the ACP JSON-RPC method or parameters. Opening and closing a harness session go through the same relay. Workspace artifacts go up as separate, versioned snapshots.

The local harness login never enters participant registration, lifecycle events, or the tunnel. This is separate from workspace artifacts, which the participant sends deliberately so an attached application can use the harness output.

  • Localhost stays localhost. The provider URL you pass to gambi participant join or createParticipantSession() can be http://localhost:11434, even when the hub runs on another machine. The hub never needs to reach that address.
  • Credentials stay local. authHeaders and API keys only leave the participant runtime when the runtime itself calls the provider, never through the hub.
  • Fewer network prerequisites for participants. A participant needs outbound connectivity to the hub, and nothing else. No port forwarding, no mDNS advertising, no firewall exceptions.
  • Retry-safe registration. Participant registration is idempotent, and the tunnel bootstrap token is single-use. Restarting a participant with the same ID is safe.
  • Reconnection. When the tunnel drops, the participant runtime registers again and reopens it with the same participant ID, waiting 1 second and doubling up to 30. Apps that route to it by ID keep their target.
  • Cancellation. When an app abandons a request, the hub cancels the call in the tunnel and the runtime aborts the request to the provider, so nobody’s machine keeps generating for nothing.
  • WebSocket upgrade must pass. Any proxy between the participant and the hub has to forward Upgrade: websocket. Some corporate proxies block it.
  • One direction, not two. The participant needs to reach the hub. The hub does not need to reach the participant, but nothing gets through if outbound is blocked.
  • Same minor version on both ends. The tunnel speaks the wire format of the RPC library Gambi is built on, which can change between minor versions. A hub refuses a participant from another minor at registration and names the version it expects.
  • Requests in flight do not survive a drop. A request the participant was answering when its tunnel dropped fails with participant_disconnected. The runtime comes back for the next one.
  • A restarted hub forgets its rooms. Rooms live in the hub’s memory. A participant that tries to come back to a restarted hub hears that the room does not exist and stops (left with reason: "refused"). Create the room again and rejoin.
  • Removal between retries. participant leave closes a connected runtime’s tunnel with 4002 and the runtime stops. If someone removes it while it waits between retries, there is no tunnel to receive the close code. Its next registration brings it back.

The tunnel is the only transport the hub uses to reach participants. That gives you two guarantees:

  1. A participant’s status comes from its tunnel alone. If the tunnel is not open, the participant is offline and not available. No stale DNS, no half-open sockets pretending to be live.
  2. If a request names a participant whose tunnel is not open, the hub answers at once with HTTP 503 and the code participant_offline instead of waiting for a timeout.

Attached harness clients do not depend on the participant tunnel. If the participant’s tunnel drops and comes back, existing attach streams stay open, receive harness.disconnected and then harness.connected, and relaying resumes. A message a client sends while no tunnel is open is refused with PARTICIPANT_UNREACHABLE.