Repository navigation
Description
Problem Statement
Exposure today is two-valued: an environment's server listens on loopback only, or on every interface (0.0.0.0). For someone who reaches T3 Code from a phone or laptop over Tailscale, the only way to get there is to also listen on whatever LAN the desktop happens to be on — home Wi-Fi, an office network, a hotel. There is no way to say "tailnet, but not the LAN", and no way to bind a specific address. On Windows, the WSL backend ignores the choice entirely and always listens on every interface (upstream pingdotgg#9056). Upstream pingdotgg#8082 asks for per-interface binding and is open and unassigned.
Solution
Exposure becomes a set of listen interfaces. Loopback is always included; tailnet and lan are opt-in kinds; a custom preset adds explicit IPv4 addresses. The server resolves kinds to concrete addresses when it starts and opens one listen socket per address — nothing binds 0.0.0.0. The desktop's Connections panel offers the presets (local-only, tailscale-only, lan, custom) in place of the on/off switch; the CLI's --host accepts the same kinds and addresses. Auth posture follows the selection: any non-loopback interface means remote-reachable. Advertised endpoints are derived from the selection, so pairing never offers an address that isn't bound. The WSL backend takes its bind host from exposure like the native backend does.
This is the bind-hosts lane of the fork (fork-main). It ships as one fork-only feature commit stacked on one upstream-bound commit (the WSL fix).
User Stories
Desktop user
- As a desktop user, I want a Tailscale only preset, so that my environment is reachable from my phone over the tailnet without listening on the LAN.
- As a desktop user, I want Local only to stay the default, so that a fresh install never listens beyond loopback.
- As a desktop user, I want a LAN preset that includes tailnet and loopback, so that it behaves like upstream's "network accessible" without picking interfaces one by one.
- As a desktop user, I want a Custom preset where I can toggle kinds and add explicit IPv4 addresses, so that I can bind a VPN or second NIC the kinds don't cover.
- As a desktop user, I want the app to tell me the backend will relaunch before I confirm an exposure change, so that the reconnect isn't a surprise.
- As a desktop user upgrading the fork, I want my existing "network accessible" setting to become the LAN preset and "local only" to stay local-only, so that upgrading neither widens nor narrows exposure.
- As a desktop user who chose tailscale-only while Tailscale is down, I want the server to come up loopback-only with a visible warning, so that the app still works locally and I know why remote isn't reachable.
- As a desktop user, I want the Connections panel to show the concrete addresses currently bound and any resolver warnings, so that I can verify exposure without a terminal.
- As a desktop user, I want the advertised endpoint list (and the pairing QR) to contain only addresses in my selection, so that I'm never handed a LAN URL I didn't expose.
- As a desktop user, I want the Tailscale Serve (HTTPS) toggle to be available only when
tailnetis selected, so that the panel can't offer HTTPS on an interface that isn't bound. - As a desktop user with several LAN interfaces, I want
lanto bind every non-loopback, non-tailnet IPv4 address, so that I don't have to know which NIC is which. - As a desktop user who typed a custom address that isn't on this machine, I want a clear warning naming the address and the remaining addresses to bind anyway, so that one typo doesn't take the server down.
Remote client user
- As a client user on the tailnet, I want the desktop's tailnet address to accept my connection with the same pairing and token flow as before, so that nothing changes on my side.
- As a client user on the same LAN when the preset is tailscale-only, I want my connection refused at the socket, so that exposure is enforced by the kernel rather than by an allowlist.
- As a mobile client user, I want the endpoint list the desktop gives me to contain only reachable, bound addresses, so that the app doesn't show dead endpoints.
CLI user
- As a CLI user, I want
t3 serve --host tailnetto bind the tailnet address only, so that the CLI shares the desktop's model. - As a CLI user, I want
--host lan,--host tailnet,lan, and--host 10.0.0.5,100.64.0.3to all work, so that kinds and explicit addresses compose. - As a CLI user, I want
T3CODE_HOSTto accept the same syntax as--host, so that env and flag stay interchangeable. - As a CLI user, I want an unknown
--hosttoken to fail fast with a message listing the accepted keywords, so that I don't silently get loopback. - As a CLI user, I want the startup output (connection string, pairing URL, QR code) to use a reachable address from my selection, so that pairing works as it does today.
- As a CLI user with an existing script that passes
--host 0.0.0.0or a single IP, I want that to keep working, so that the fork doesn't break my setup.
Windows / WSL user
- As a Windows user on the WSL backend, I want the backend to listen only on what my exposure selects instead of always
0.0.0.0, so that local-only really is local-only ([Bug]: WSL backend binds 0.0.0.0 while "Network access" is off and the UI says "Limited to this machine" pingdotgg/t3code#9056). - As a Windows user on the WSL backend with local-only, I want localhost to keep working through WSL2 localhost forwarding, so that the fix doesn't break the default path.
Fork maintainer
- As the fork maintainer, I want the WSL fix isolated in its own upstream-bound commit expressed in upstream's two-valued model, so that it can be proposed to
pingdotgg/t3codeindependently. - As the fork maintainer, I want upstream files touched only at thin call sites with new logic in fork-only modules, so that rebasing onto upstream releases stays cheap.
- As the fork maintainer, I want the legacy two-valued
modekept in the contract as a derived value, so that upstream consumers I haven't touched keep working after a rebase.
Implementation Decisions
Governing ADR: 0003 — Bind one socket per selected listen interface instead of 0.0.0.0 plus peer filtering. Vocabulary from the fork CONTEXT.md: exposure, listen interface, exposure preset; avoid "network access", "bind host", "mode" in new code and UI copy (legacy identifiers may keep their names).
Contract
-
Exposure state and the set-exposure IPC input gain a
listenInterfacesselection: a set of kinds fromloopback | tailnet | lan, plus an optional list of explicit IPv4 addresses.loopbackis always present; inputs that omit it are normalized to include it. This shape encodes the decision:// illustrative shape, not a code location ListenInterfaces = { kinds: ReadonlySet<"loopback" | "tailnet" | "lan">; addresses: ReadonlyArray<IPv4> }
-
Exposure presets are a pure derivation, not a stored value:
local-only={loopback}tailscale-only={loopback, tailnet}lan={loopback, tailnet, lan}custom= anything else (any kind set with explicit addresses, or a kind set that matches no named preset).
-
The legacy two-valued
mode(local-only | network-accessible) stays in the state as a derived field:local-onlyiff the selection is exactly{loopback}with no addresses. The legacy set-mode input is still accepted and mapped:local-only→{loopback},network-accessible→ thelanpreset. This keeps upstream consumers (including mobile) untouched. -
State additionally carries what the resolver produced: the concrete addresses bound and a list of human-readable warnings (e.g. "tailnet selected but no Tailscale address was found; listening on loopback only").
Shared resolver (kinds → addresses)
- One pure function, living beside
isTailscaleIpv4Addressin the tailscale package, takes a selection and an injectable network-interface map and returns{ addresses, warnings }. NotailscaleCLI, no I/O. - Resolution rules (IPv4 only in v1):
loopback→127.0.0.1.tailnet→ every non-internal IPv4 in the Tailscale CGNAT range.lan→ every non-internal IPv4 that is not a tailnet address.- explicit addresses → included only if present on some interface (or loopback); missing ones are skipped with a warning naming the address.
tailnetselected but no tailnet address → warning; continue with whatever else resolved.- If the selection had any non-loopback kind or address and the result is loopback only → an additional "listening on loopback only" warning.
- Deduplicated, ordered loopback → tailnet → lan → explicit. The desktop calls the same function to display what will bind; the server calls it to bind. The fallback policy exists in exactly one place.
Server
- The server config's single
hoststring becomes a listen selection. Precedence is unchanged:--hostflag >T3CODE_HOSTenv > desktop bootstrap envelope > default{loopback}. - For compatibility, an explicit raw
0.0.0.0/::is still accepted from the CLI and env as a single legacy wildcard listener, treated as remote-reachable. The desktop never sends it. - At launch the server resolves the selection and opens one listen socket per resolved address. Nothing binds a wildcard unless the legacy wildcard was explicitly requested. This must be observable from outside: a TCP connect to a non-selected local address is refused.
- Both runtimes must work: the desktop backend runs under Electron-as-Node,
bun devruns under Bun. The preferred mechanism is one HTTP server instance with one listener per address (e.g. secondary listeners handing accepted connections to the primary server on Node; repeated serve with shared handlers on Bun). Escape hatch, per ADR 0003: only if the HTTP server layer cannot be instantiated once per address, bind0.0.0.0and close any connection whosesocket.localAddressis not in the resolved set — and record that in the ADR. - Auth policy:
remote-reachableiff any resolved address is non-loopback (or the legacy wildcard). The session-cookie naming rule uses the same predicate. No other auth changes. - Runtime state (what the desktop and
t3 pairread) carries the list of resolved addresses and the resolver warnings. Consumers that need a single URL take the first address in the order above; the existing "prefer a concrete external interface for wildcard hosts" logic remains only for the legacy wildcard. - Startup access output (connection string, pairing URL, terminal QR) uses the first non-loopback resolved address, else loopback.
Desktop
- Persisted desktop settings gain a
listenInterfaceskey. On read, if it is absent and the legacyserverExposureModekey is present, migrate one-way:network-accessible→lanpreset,local-only→{loopback}. On write, both keys are written (the legacy one as the derived value) so an upstream build reads something sane after a downgrade. - The bootstrap envelope handed to the backend carries the selection (kinds + addresses), never a pre-resolved IP. The server resolves.
requiresRelaunchis true whenever the selection changes (set inequality on kinds or addresses). Full relaunch stays; there is no hot rebind.- The Tailscale Serve toggle is enabled only when
tailnetis in the selection. Deselectingtailnetdisables Serve, mirroring today's behaviour when switching to local-only. - Advertised endpoints are derived from the selection: loopback endpoint always; tailnet IP endpoint (and the MagicDNS HTTPS endpoint when Serve is on) only when
tailnetis selected and resolved; one LAN endpoint per resolved LAN address only whenlanis selected; one endpoint per explicit custom address. The manual/custom endpoint flow that exists today is unchanged. - Desktop-side interface enumeration is used only for display and endpoint derivation, through the shared resolver.
Web UI (desktop client)
- The exposure on/off switch in Settings → Connections is replaced by a fork-only exposure preset control: a radio/segmented choice of Local only · Tailscale only · LAN · Custom. Custom reveals kind checkboxes (loopback locked on) and a list input for IPv4 addresses. A read-only "Listening on" line shows the resolved addresses; resolver warnings render inline beneath it.
- The existing confirmation dialog is reused whenever a change adds any non-loopback interface; it also states that the backend will relaunch.
- The existing desktop network-access atom exposes the selection, the preset derivation, and the resolved addresses/warnings; the control never computes presets itself.
- The upstream Connections settings file gets one edit: swap the switch for the fork-only component. No other upstream UI files change.
CLI
--hostaccepts a comma-separated list of kind keywords (loopback,tailnet,lan) and/or IPv4 addresses, and may be repeated; all values are unioned.T3CODE_HOSTuses the same syntax. A single IP or0.0.0.0keeps working (legacy forms). Any other token is a hard error whose message lists the accepted forms. Help text is updated.t3 pairneeds no behavioural change; it consumes the runtime state's addresses.
WSL backend (pingdotgg#9056, upstream-bound)
- Upstream-bound commit (first in the stack), expressed in upstream's model: the WSL backend's bind host follows the exposure mode —
local-only→127.0.0.1(relying on WSL2 localhost forwarding),network-accessible→0.0.0.0— instead of being hardcoded to0.0.0.0. Best-effort: no WSL machine is available to verify; the PR description states the localhost-forwarding assumption and asks a WSL user to confirm. - Fork commit: the WSL backend receives the same listen selection as the native backend. Resolution happens inside WSL against WSL's own interfaces; in default (NAT) networking mode that practically means loopback plus WSL's virtual NIC. Documented as a known limitation in the ADR, not worked around.
Rebase hygiene (ADR 0001 stack)
- Stack order:
[upstream-bound] WSL bind host follows exposure→[fork] exposure as a set of listen interfaces. - New logic lives in fork-only modules: the shared resolver, the multi-listener startup, the preset control,
--hostparsing. Upstream files get thin call-site edits only. - Fork glossary entries and ADR 0003 already exist; the ADR gets a one-line note if the escape hatch is taken.
Testing Decisions
What makes a good test here: observe behaviour at a boundary a user or another process could observe — a TCP connect succeeding or being refused, the public environment descriptor's auth policy, IPC state, persisted settings on disk, CLI exit code and message. Do not test how sockets are created or how kinds are stored.
Seam 1 — server listener boundary (new). Boot the server in-process with a listen selection and an injected interface map; probe with real TCP connects; read auth policy from the already-tested public environment-descriptor endpoint. Cases:
{loopback}→127.0.0.1accepts;[::1]is refused (proves no dual-stack wildcard); descriptor reports loopback-only policy.{loopback, lan}withlaninjected as the runner's first real non-internal IPv4 → both addresses accept; descriptor reportsremote-reachable. If the runner has no such address, the case skips with a message rather than faking one.{loopback, tailnet}with an injected map containing no CGNAT address → only127.0.0.1accepts; runtime state carries the "loopback only" warning; policy is loopback-only.- explicit address not present in the injected map → skipped, warning names it, the rest bind.
- legacy
--host 0.0.0.0→ single wildcard,remote-reachable. - If the ADR escape hatch is taken, the same cases must still pass unchanged — that is the point of testing at this seam.
Seam 2 — desktop exposure layer (existing harness, mocked interfaces / Tailscale spawner / settings dir). Migration from the legacy key (both directions of the derived write), persistence round-trip, requiresRelaunch on set change, Serve gating on tailnet, advertised endpoints derived per selection (no LAN endpoint without lan, no tailnet endpoint without tailnet).
Seam 3 — CLI config precedence (existing tests). Every accepted --host form, repeated flags unioning, env vs flag vs bootstrap precedence, legacy single-IP and wildcard, and the error message for an unknown token.
Seam 4 — WSL backend configuration (existing resolveWsl tests). Upstream-bound: bind host is 127.0.0.1 for local-only and 0.0.0.0 for network-accessible. Fork: the selection is passed through unchanged.
Shared resolver. Pure unit tests with synthetic interface maps for every rule above (ordering, dedup, CGNAT detection, missing tailnet, missing explicit address). Prior art: the startup-access helpers already take an injectable interface map and are tested exactly this way.
Not tested: the React preset control beyond typecheck/lint (the atom it reads is tested); real WSL (no machine); Bun-vs-Node listener mechanics beyond running Seam 1 under the runtime CI uses.
Prior art: the server integration suite already boots the server layer in-process and hits the public descriptor; the desktop exposure tests already mock interfaces, the Tailscale spawner, and the settings directory; the CLI config tests already cover flag/env/bootstrap precedence; the desktop backend configuration tests already cover resolveWsl.
Out of Scope
- Peer allowlists or any filtering by remote address (ADR 0003: kernel-enforced binding only).
- Hot rebinding without a backend relaunch.
- IPv6 listen interfaces (explicit
::survives only as the legacy wildcard). - Any change to authentication, pairing, tokens, or session handling beyond the derived
remote-reachablepredicate. - Mobile app changes; mobile keeps reading advertised endpoints.
- Detecting the tailnet via the
tailscaleCLI or daemon; detection is by address range only. - Upstream user documentation (
remote-access.mdand friends); the fork'sCONTEXT.mdand ADR 0003 are the docs of record. CLI--helptext is in scope. - Proposing the
listenInterfacesmodel upstream. Only the WSL fix is upstream-bound. - The other three fork lanes (skills-sources, pxpipe-proxy, fork-workflow).
Further Notes
- Decisions were grilled in the domain-modeling session and recorded as N1–N8 in the fork's decision log; ADR 0003 is the durable record. If implementation forces the escape hatch, update ADR 0003 in the same commit.
- Upstream feat(git): let users choose the worktree branch prefix pingdotgg/t3code#8082 is the feature request; [Bug]: WSL backend binds 0.0.0.0 while "Network access" is off and the UI says "Limited to this machine" pingdotgg/t3code#9056 is the WSL bug. Link both from the fork PR/commit messages.
- The
lanpreset deliberately includestailnetso that migrating upstream'snetwork-accessible(which was0.0.0.0, i.e. everything) is exposure-preserving. - Keep the derived legacy
modeuntil an upstream rebase proves no consumer reads it; removing it is a separate, later cleanup.
Activity
t3 serve --host tailnetbinds the tailnet address only #5--host tailnet,lanand custom lists #6Khang5687 commentedon Sep 16, 2026
Bind-hosts lane complete. Children #3–#9, #15 merged into fork-main (a66bc48); integrated desktop client pass done 2026-09-16. Follow-up cleanup tracked in #19; upstream tracker stays in #2.