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

05_remote.md

78 lines5.0 KB

1# Remote architecture
2​
3Each connection joins a client to one environment over HTTP and WebSocket. Direct access, Tailscale,
4SSH, and T3 Connect change how the client reaches the server; they do not introduce a different
5execution model.
6​
7## Identity is independent of the route
8​
9- An environment keeps its ID across restarts and endpoint changes. Repository identity can
10 correlate clones across environments (preferring `upstream` for PR features, grouping forks by
11 `origin`), but work never silently crosses environments.
12- [Environment ID initialization](../../apps/server/src/environment/ServerEnvironment.ts) publishes
13 atomically and retains repair state so concurrent initializers choose the same winner; do not
14 sweep that recovery state as temp cleanup.
15- **Routes are untrusted hints.** Only the connecting client can prove reachability. Never fall back
16 to loopback when a shareable endpoint is unavailable (loopback names the client's own machine).
17 Verify a direct or learned route answers as the expected environment before sending credentials,
18 and never let a token paired over HTTPS downgrade to plain HTTP.
19- Pull request routing trust covers the saved route set: adding or changing a route revokes trust;
20 reordering does not.
21​
22## Peer links
23​
24A [peer link](../../apps/server/src/peer/PeerLinks.ts) lets one environment's agents work in another
25by signing in to the target's `/mcp` as an ordinary OAuth client (`t3code-peer-link`). The receiving
26side lists and revokes it in Sharing & access like any other session, and owns its expiry/renewal.
27​
28- **Mode ceilings always narrow.** Forwarded calls carry the calling agent's modes in
29 `T3-Mode-Limit`, which the receiving `/mcp` can only intersect downward with the link's approved
30 access.
31- **Non-full-access links are fenced by `linkOrigin`.** Threads launched by a peer link (and their
32 derived forks, subagents, and spawned threads) carry an immutable `linkOrigin` stamp enforced in
33 shared access rules ([`mcp/linkOrigin.ts`](../../apps/server/src/mcp/linkOrigin.ts)). Below full
34 access, linked work can mutate only threads with the same origin, cannot touch projects, settings,
35 scheduled tasks, or further links, and skips project setup scripts and worktree layout commands
36 (in a project that declares a layout, a worktree launch or handoff for such a thread fails;
37 restoring a missing folder brings back plain checkouts). Full-access links are not fenced because
38 their agents already run as the receiving OS user. Being unfenced only answers who asked: a
39 layout command still runs only with a person's approval of its text, and for an agent only from
40 a thread in Full access, both checked in
41 [`TaskFolders`](../../apps/server/src/workspace/TaskFolders.ts) at every run.
42- **Namespace idempotency keys.** All callers on the linking side share one session on the receiving
43 side, so idempotency keys must be hashed with the caller's namespace before forwarding.
44- **Clients read linked threads as standard thread streams.**
45 [`PeerThreadRelay`](../../apps/server/src/peer/PeerThreadRelay.ts) proxies the same stream format
46 read-only so there is no second transcript schema to maintain.
47​
48## Hosted web is a client
49​
50The hosted web app stores its connection catalog in the browser and connects directly to each
51environment without proxying traffic. A [hosted pairing URL](../../apps/web/src/hostedPairing.ts)
52puts the backend target in the query and the pairing secret in the URL fragment so the secret never
53reaches the hosted origin, then strips it from history.
54​
55## Desktop previews tunnel loopback
56​
57A desktop webview for a remote environment keeps `localhost` URLs and tunnels loopback connections
58through `/api/preview/tunnel` on the environment's own origin:
59​
60- **Fixed SOCKS5 proxy, not PAC.** Chromium ignores PAC scripts for loopback hosts. Use a fixed
61 proxy that routes only loopback through the tunnel (excluding link-local addresses) and never
62 falls back directly—a failed or disabled tunnel must error rather than silently load the
63 reviewer's own localhost.
64- **Media tickets and local-owner check.** Desktop main holds no environment credentials, so the
65 renderer supplies a media ticket per connection (also tracking route switches). Because Chromium
66 cannot authenticate to SOCKS5 and a forwarded port is a plain local port, on Linux and macOS both
67 listeners serve only connections the system attributes to the current OS user (`/proc/net/tcp`
68 on Linux, `lsof` on macOS), and a connection whose owner cannot be read is refused. On Windows
69 the listeners do not check the owner.
70​
71## Access and process ownership are separate
72​
73- Tailscale supplies an endpoint for normal pairing; auth remains the environment's responsibility.
74- [SSH cleanup](../../packages/ssh/src/tunnel.ts) stops a remote server only if the launcher started
75 it; a server discovered already running must survive client disconnect.
76- Remote servers outlive client releases. Clients negotiate features via advertised capabilities
77 rather than assuming version parity. Process replacement uses the
78 [update protocol](./07_server-updates.md).