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

09_connection-runtime.md

51 lines3.3 KB

1# Connection runtime
2​
3Web, desktop, and mobile share one connection owner per environment in `packages/client-runtime`.
4Platform code supplies storage, credentials, network signals, and lifecycle events; React views
5consume the runtime. Keeping retry and session ownership here prevents competing reconnect loops.
6​
7## One transport retry owner
8​
9- The [supervisor](../../packages/client-runtime/src/connection/supervisor.ts) is the sole owner of
10 transport retries. Endpoint resolution and opening an RPC session are single attempts. Transient
11 failures use jittered, capped exponential backoff that resets only after a connection stays up;
12 offline and auth failures wait for an explicit wakeup.
13- Foregrounding, network changes, explicit retries, and offline reports probe the established
14 session rather than blindly reconnecting (OS offline reports are often wrong, especially for
15 loopback). Only a failed probe replaces the socket.
16- The [registry](../../packages/client-runtime/src/connection/registry.ts) scopes connections by
17 environment. An involuntary disconnect keeps the registration and cached projections; explicit
18 removal closes the scope and clears credentials, caches, and drafts. Cloud-account changes apply
19 only to relay registrations and must never discard directly paired environments.
20​
21## HTTP authorization vs. socket lifetime
22​
23RPC sockets authenticate at upgrade, while HTTP requests pull current credentials from the
24[authorization service](../../packages/client-runtime/src/authorization/service.ts). Never tear down
25a healthy socket because an HTTP refresh failed—renewal failure belongs to the HTTP operation. Live
26sockets whose access token nears expiry renew in place on the same session so open conversations are
27not interrupted. Session listings retain unrevoked connected sessions after credential expiry so
28active connections stay manageable without extending the credential's lifetime.
29​
30## Transport health and data freshness are separate
31​
32- An open socket does not mean the environment is usable. The RPC session waits for initial server
33 configuration, and shell and thread subscriptions maintain their own sync state. Never label a
34 failed subscription "reconnecting" when the transport is healthy.
35- Cached projections stay readable offline, but must never imply a live connection or overwrite
36 newer live data on reconnect.
37- **Shell snapshots are intentionally partial.** Servers omit idle subagent children and older
38 settled threads on demand; left-out rows load via thread-family, shelf, and search queries. A
39 missing shell row therefore never proves a thread is deleted—code that deletes data or worktrees
40 on absence must verify with the family or server first.
41​
42## Subscriptions, caching, and mutations
43​
44- [Thread detail](../../packages/client-runtime/src/state/threads.ts) separates subscription
45 lifetime from cache lifetime: mounted consumers share one live stream (stopping when the last
46 unmounts), while a short-lived cache retains state and its replay cursor for fast back navigation.
47- Commit cached state and replay cursor together only after an update completes. Cancellation must
48 not advance the cursor past applied data, and an old scope must not overwrite a newer scope's
49 cache.
50- Durable subscriptions follow replacement sessions automatically. Reconnection never auto-replays
51 mutations—retry and idempotency belong to each operation.