How tunnels work
This page explains Gambi’s tunnel-first transport: why the participant, not the hub, opens the connection.
The old shape
Section titled “The old shape”An earlier version of Gambi treated each participant as a small HTTP server:
- The participant ran a local provider (Ollama, LM Studio, etc.).
- It told the hub, “my endpoint is reachable at
http://host:port”. - 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.
The tunnel-first shape
Section titled “The tunnel-first shape”Gambi now inverts the connection. The participant opens a WebSocket to the hub. Inference requests travel over that tunnel.
flowchart LR
app["Your app"]
hub(("Hub")):::hub
subgraph machine["Participant machine"]
rt["Participant runtime"]
prov[("Local provider<br/>Ollama, LM Studio, vLLM")]:::model
end
app -->|HTTP| hub
rt ==>|opens WebSocket| hub
rt -->|HTTP on localhost| prov
classDef hub stroke-width:1px
classDef model stroke-width:1.5pxWhat 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.
The opaque ACP relay
Section titled “The opaque ACP relay”flowchart LR
client["Harness client<br/>or application"]
hub(("Hub")):::hub
subgraph machine["Participant machine"]
rt["Participant runtime"]
acp["Harness<br/>ACP v1 process"]:::harness
end
client ==>|HTTP and SSE| hub
rt ==>|participant tunnel| hub
rt <-->|stdio| acp
classDef hub stroke-width:1px
classDef harness stroke-width:1.5pxEach 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.
What you gain
Section titled “What you gain”- Localhost stays localhost. The provider URL you pass to
gambi participant joinorcreateParticipantSession()can behttp://localhost:11434, even when the hub runs on another machine. The hub never needs to reach that address. - Credentials stay local.
authHeadersand 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.
What you give up
Section titled “What you give up”- 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 (
leftwithreason: "refused"). Create the room again and rejoin. - Removal between retries.
participant leavecloses a connected runtime’s tunnel with4002and 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.
Guarantees
Section titled “Guarantees”The tunnel is the only transport the hub uses to reach participants. That gives you two guarantees:
- A participant’s status comes from its tunnel alone. If the tunnel is not open, the participant is
offlineand not available. No stale DNS, no half-open sockets pretending to be live. - If a request names a participant whose tunnel is not open, the hub answers at once with HTTP
503and the codeparticipant_offlineinstead 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.
Further reading
Section titled “Further reading”- Architecture overview: the full picture, including what travels through the tunnel.
- API reference: the tunnel route: the exact HTTP and WebSocket contract.
- SDK reference:
createParticipantSession(): the programmatic runtime that manages a tunnel for you. - Bring your harness: how to join with OpenCode, Claude Code, or Codex.
- Custom participant runtime: how to build your own runtime on top of
createParticipantSession().