Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

remote.md

59 lines3.1 KB

1# Remote architecture
2​
3Each connection joins a client to one environment over HTTP and WebSocket. The
4environment owns providers, execution, files, and durable state. Direct access,
5Tailscale, SSH, and T3 Connect change how the client reaches that server; they do
6not introduce another execution model. See
7[remote access](../user/remote-access.md) for setup.
8​
9## Identity is independent of the route
10​
11An environment keeps its ID across server restarts and endpoint changes. Saved
12connections are local to a client profile; the server's identity and state are
13not. A repository identity can correlate clones across environments, but never
14routes work between them. A project and its threads belong to one environment.
15​
16[Environment ID initialization](../../apps/server/src/environment/ServerEnvironment.ts)
17must publish a complete ID atomically. Repair of an empty ID file retains a
18recovery file so concurrent or delayed initializers choose the same winner.
19Removing that recovery state as ordinary temporary-file cleanup can change the
20identity underneath an already-running server.
21​
22Advertised endpoints are reachability hints. Only the connecting device can
23prove that a route works. In particular, a host's loopback address refers to a
24different machine when another device opens it. Endpoint selection must not
25silently fall back to loopback when a shareable endpoint is unavailable.
26​
27## Hosted web is a client
28​
29The hosted web app stores its connection catalog in the browser and connects
30directly to each environment. It does not proxy traffic or hold server-side
31pairing state. Hosting the UI over HTTPS therefore cannot make a plain HTTP LAN
32backend accessible from that browser context.
33​
34A [hosted pairing URL](../../apps/web/src/hostedPairing.ts) identifies the backend
35in its query and carries the pairing secret in its fragment. Fragments stay out
36of requests to the hosted origin. The browser exchanges the secret with the
37environment and strips it from its history. Moving the token into a query
38parameter would disclose it to the wrong origin.
39​
40## Access and process ownership are different
41​
42Tailscale supplies an endpoint for ordinary pairing, so it needs no separate
43environment type. Authentication remains the environment's responsibility for
44every route. See [environment authentication](./environment-auth.md) and the
45[T3 Connect trust boundary](./t3-connect.md).
46​
47SSH can launch a server as well as forward a port. Desktop main owns that
48lifecycle because it can spawn SSH and handle authentication prompts. The
49renderer uses the forwarded endpoint through the shared connection runtime.
50[SSH cleanup](../../packages/ssh/src/tunnel.ts) stops a remote server only if the
51launcher owns it; a server it discovered already running must survive a client
52disconnect. Reconnection restores the forward before opening the application
53transport.
54​
55Remote servers can outlive several client releases. Clients must use advertised
56capabilities and handle their absence, rather than assume their own version
57describes the server. Process replacement belongs to the launcher's
58[update protocol](./server-updates.md); the connection runtime handles the
59resulting disconnect.