[Bug]: After re-pairing, an environment's other routes keep the expired login, and removing a route deletes the new one #17014
Area#
apps/mobile (shared logic in packages/client-runtime, so web and desktop are probably affected too)
Impact#
Blocks work completely
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
What happened#
My iOS app lost access to my Mac (T3 Code Nightly, reached over LAN and Tailscale) and I could not get it back without removing the whole environment.
- 6 Sep: paired the phone over LAN. The server issued a bearer session with the fixed 30-day lifetime (#13055).
- Oct 4–6: the app auto-updated to the 2.0.0 beta and kept connecting fine. Its last successful connection on the old login was Oct 6 04:57 UTC.
- Oct 6 11:37 UTC: the 30-day session expired. The app did not warn me and did not say it had expired.
- Oct 7: I re-paired over LAN with a new one-time code. The server issued a new session, valid until Nov 6, and the phone connected for about 5 minutes.
- Later, on another network: the app showed a connection timeout. Moving the Tailscale route to the top changed nothing: even after force-quitting and relaunching the app several times, it still showed the same timeout.
- Removed the LAN route: the app now showed "The environment credential is invalid." with no way to recover except removing the environment.
The server traces from step 6 show that the network was fine and that the phone sent the old, expired login over Tailscale:
GET http://<mac-tailnet-ip>:3773/.well-known/t3/environment 200 client=<phone-tailnet-ip> UA=T3Code/110 CFNetwork/3860.700.2 Darwin/25.6.0
POST http://<mac-tailnet-ip>:3773/api/auth/websocket-ticket 401 client=<phone-tailnet-ip>
EnvironmentAuth.authenticateHttpRequest → "Rejected authenticated session credential." reason="Session token expired."
The only expired, unrevoked session for this phone in auth_sessions is the one from 6 Sep. The Oct 7 session was still valid and was never used after its first 5 minutes.
Diagnosis (v0.0.46-nightly.20261007.2787)#
Since #15467 (Oct 4), an environment holds several routes, and each route has its own credential. Re-pairing replaces the credential only on the route it pairs through. Every other route keeps the credential it already had, even an expired or revoked one.
- Route ids. Credentials are keyed by route id. Bearer routes are now
bearer:<envId>:<origin>(packages/client-runtime/src/connection/onboarding.ts:100-102). Routes saved before #15467 kept the old idbearer:<envId>(the onboarding line that #15467 changed;apps/mobile/src/connection/migration.ts:67), and nothing migrates them. - Re-pairing.
EnvironmentRegistry.registeradds the new route next to the existing ones. It only replaces a route with the same id or the same address (registry.ts:566-585,routes.ts:146-167). No step copies the new credential onto the environment's other bearer routes, and no step drops credentials that have expired. So a Sept route, or a route learned through it (#15468,routes.ts:268-277,routes.ts:315-333), keeps the dead credential indefinitely. - Removing a route.
removeRoute→routesAfterRemovingdrops the route and deletes its credential (registry.ts:946-968,routes.ts:340-361). Removing the route that holds the new credential therefore leaves only the expired one. - Error precedence hides the cause.
connectOverRoutesskips routes that fail the 2.5 s check on the first pass and tries them last, and reportstransient ?? blocked(driver.ts:70-130). An unreachable LAN address's timeout therefore hides the 401 from the Tailscale route, and reordering routes has no visible effect. - No useful message. Any 401 maps to "The environment credential is invalid." (
errors.ts:121-126), discarding the server's reason ("Session token expired."). The supervisor then sits inblockedwith no re-pair prompt (supervisor.ts:927-942).
The server accepts a bearer session token on any of its addresses, so nothing on the server side requires one credential per direct route. Learned routes already share a credential.
Steps to reproduce#
Revoking a session stands in for waiting 30 days.
- On iOS, remove the environment completely.
- Pair the phone using the host's LAN address. Confirm it connects.
- On the host, revoke that phone session in Settings → Connections. The phone reports "credential invalid", which is correct so far.
- Pair the phone again, this time using the host's Tailscale address.
- Remove the Tailscale route.
- Optional: before step 5, turn off Wi-Fi so the LAN route is unreachable, and note that the error shown is a timeout, not the auth failure.
Expected behavior#
Re-pairing gives the environment a working login on every direct route. An expired or revoked login is never sent again.
Actual behavior#
The other routes keep the dead login. Removing the newly paired route leaves the environment permanently on the dead login, with only "The environment credential is invalid." shown. While any route is unreachable, the auth failure is hidden behind a timeout.
Suggested direction#
- One login per environment for direct routes. LAN, Tailscale and public-URL routes use the newest bearer credential. T3 Connect and SSH keep their own. Re-pairing over any address updates the credential for all of them.
- Drop dead logins. When the server rejects a credential as expired or revoked, delete it from the catalog so it cannot come back.
- Say what happened. Pass the server's reason through: "This login expired on ", with a one-tap Re-pair, rather than "credential invalid". Showing the expiry date before it lapses would avoid the surprise entirely; sliding expiry (#13055) would make it rare.
- Report the meaningful error. When every route fails, prefer the error from a route that reached the right server (a 401) over a timeout from a route that did not.
- Make it visible. Show the login status (issued, expires, last used) per environment, not per route, so it is clear that one login serves all routes.
Version or commit#
iOS beta app 2.0.0 (build 110). Host: T3 Code Nightly 0.0.46-nightly.20261006.2752 desktop app on macOS. Code references checked against v0.0.46-nightly.20261007.2787.
Environment#
macOS 26 host running the server bundled in the desktop app (port 3773), reached over LAN and Tailscale. iPhone on iOS 26 running the TestFlight beta of the app.
Workaround#
Remove the whole environment on the phone (not individual routes) and pair again. This clears every route and credential.
Related#
- #13055: fixed 30-day session lifetime. This is the trigger; this issue covers why the client cannot recover from it.
- #15802: re-pairing at the same address leaves a broken duplicate. Same area, different trigger.
- #15467 and #15468: the changes that introduced per-route credentials and learned routes.
juliusmarminge added labelsbug
juliusmarminge added labelsvia-triage
Thanks, the correction about the expiry reason is fair: it's only logged server-side, so fix 4 needs the contract change you describe.
On your questions:
- I never added a route by hand. I paired by scanning the QR code, and the other routes (Tailscale included) appeared on their own, so they were learned, not added. When the session lapsed, I scanned the QR code again to refresh the credentials. That only refreshed the LAN route; the learned routes kept the old token.
- The host's records agree: the phone only ever redeemed two pairing codes (6 Sep and 7 Oct), both from LAN client IPs on different subnets, so the two pairings were at different base URLs and the second didn't replace the first route. No code was ever redeemed over Tailscale.
From the user side, this is the core problem: scanning the QR code is how the routes came into being, so scanning it again reads as "refresh this machine". Nothing in the UI suggests the routes hold separate credentials, or that a rescan only updates one of them. I'd expect re-pairing to update every direct route of that environment, which is your fixes 1 and 2. Fixes 1–4 all look right to me.
Confirmed workaround: deleting the environment entirely and scanning the QR code again fixed it. It's now connecting over Tailscale. Removing individual routes and rescanning had not.
Another data point, on stable 0.1.7 (desktop app → remote Linux host).
Setup: T3 Code (Beta) desktop app 0.1.7 on macOS (arm64). It connects to a Linux x64 host that runs
t3 serve0.1.7 as a systemd user service, listening on0.0.0.0:3773. The host is reachable over Tailscale. The environment has two routes: a manually added Tailscale Serve HTTPS route (https://<host>.<tailnet>.ts.net/), and an auto-foundhttp://<tailnet-ip>:3773/route.What happened: About 30 days after pairing, the desktop app stopped connecting. The card said "T3 Code on desktop did not accept this device". Under Details it listed Cause
authentication, RouteDirect, and Error "The environment credential is invalid.". The only actions offered were Retry and Copy diagnostics, and retrying can never succeed.Host-side evidence: The client's trace ID shows up in the host's
server.trace.ndjson. There were 67 rejected requests, all with the same reason:EnvironmentAuth.authenticateHttpRequest → "Rejected authenticated session credential." reason="Session token expired." SessionStore.verify → SessionTokenExpiredError: Session token expired.Network and discovery were fine.
/.well-known/t3/environmentreturned 200 from the Mac, and both sides reportserverVersion0.1.7 andorchestrationProtocolVersion2.Still the case at v0.1.7 and on
main:DEFAULT_SESSION_TTL = Duration.days(30)(apps/server/src/auth/SessionStore.ts:429at v0.1.7). Bearer sessions from direct pairing are never renewed, since renewal exists only for DPoP/relay. The expiry reason is never shown in the UI:mapRemoteEnvironmentErrorinpackages/client-runtime/src/connection/errors.tsmaps everyEnvironmentAuthInvalidErrorto the same generic message. So #13055 being closed doesn't help direct-pairing users on stable.Workaround: create a fresh link on the host with
t3 pair --tailscale, remove the environment in the app, and pair again. I removed the whole environment rather than re-pairing in place, to avoid the stale-route problem described above.Side note: the
t3on the host's PATH was still 0.1.5 while the service ran 0.1.7, which matches #14609. I had to call~/.t3/runtime/versions/0.1.7/t3 pairdirectly to be sure the CLI matched the server.Suggested fixes: (1) Pass the expiry reason through to the client and show "Your login to expired on " with a one-tap re-pair, instead of Retry. (2) Sliding or configurable session lifetime for direct-pairing bearer sessions.
Diagnosed via
t3 triageby Claude Opus 5.5 (claude-opus-5-5) running in Claude Code.Another data point on stable 0.1.11, with a host and three clients.
Setup: Linux x64 host running
t3 serve0.1.11 as a systemd user service, reached through Tailscale Serve HTTPS. Clients: macOS desktop 0.1.11, Linux desktop 0.1.11, and the iOS app (user agentT3Code/248).What happened
- The last 30-day login, created under 0.1.3, expired at 2026-11-22 16:31:29 UTC. All clients then showed "
<host>is reconnecting" and "T3 Code on<host>did not answer". The host was healthy, andPOST /api/auth/websocket-ticket/rpcreturned 401 withSession token expired. - 0.1.11 should say "did not accept this device" for this failure (#38041), but these clients still showed "did not answer".
- We re-paired with
t3 pair --tailscalelinks at about 17:31 UTC. All three codes were redeemed, but each created abrowser-session-cookiesession. The Mac and iOS apps kept sending their expired credentials and kept getting 401s. We did not establish whether this was the link opening in a browser or the per-route credential behavior described here.
What fixed it: In each app, remove the environment, add it again, and enter the pairing code in the app.
- macOS and Linux desktop:
dpop-access-tokensessions, no further 401s. - iOS: connected, but received a non-renewing
bearer-access-tokensession even though the same host issued DPoP sessions to both desktops.
Possible separate problem on iOS:
preparePairingRegistrationinpackages/client-runtime/src/connection/onboarding.tsrunscreateProofthroughEffect.option, so a signing failure silently falls back to bearer. That would leave the device on a 30-day login with no warning. Build 248 is the latest iOS release available to this user, so updating does not resolve it. I could not confirm whether the signing step failed or whether this build does not yet use DPoP for pairing.Produced with
t3 triageby Claude Opus 5.5 in Claude Code.- The last 30-day login, created under 0.1.3, expired at 2026-11-22 16:31:29 UTC. All clients then showed "
Sign in to join this conversation.
Note
Grok responding on behalf of Julius.
Thanks for the detailed write-up. I checked it against
main(14fe0158ed) by reading the code; I haven't run the repro on a device.Confirmed in code
bearer:<envId>:<origin>(onboarding.ts#L94-L102, used at L136). The resolver looks up the credential by that id, and a learned route borrows the credential of the route it was learned through (resolver.ts#L150-L161, routes.ts#L311-L333).registerreplaces a route only when it has the same id or the same base URL, and otherwise inserts the new route next to the others (registry.ts#L566-L585, routes.ts#L143-L167). The catalog write stores the credential under the new id only (storageDocument.ts#L136-L160). Nothing updates the other bearer routes. Learned routes the server still reports keep their id, so they keep borrowing from whichever route they were learned through (routes.ts#L268-L274).bearer:<envId>(migration.ts#L67), and #15467 changed onboarding away from that form. I found no code that renames old ids. One caveat: re-pairing at the same base URL does replace a legacy route, becausefindRouteToSameAddresscompares addresses, not ids.removeRoute→routesAfterRemovingdrops the route and any learned routes that borrow from it (registry.ts#L946-L968, routes.ts#L340-L361).setRoutesInCatalogthen deletes the dropped routes' credentials (storageDocument.ts#L77-L133). So in your reduced repro (pair over LAN, revoke, re-pair over Tailscale, remove the Tailscale route), only the LAN route is left, still holding the revoked token.connectOverRoutesreturnstransient ?? blocked, and it tries routes that failed the 2.5 s check last (driver.ts#L78-L135). A timeout on an unreachable LAN route is therefore reported instead of the 401 from Tailscale. The doc comment says this is deliberate, so the supervisor keeps retrying a route that may come back.EnvironmentAuthInvalidErroralways maps to "The environment credential is invalid." (errors.ts#L121-L126).ConnectionBlockedError, the supervisor goes toblockedand waits for a signal (supervisor.ts#L928-L944). The presentation layer turns that into anerrorphase that carries the message (presentation.ts#L51-L56). The shared mobile notice only offers Retry now (EnvironmentConnectionNotice.tsx#L88-L96). I didn't check every mobile screen.One correction
The client isn't dropping "Session token expired." That text is the server's log annotation (EnvironmentAuth.ts#L695-L705, SessionStore.ts#L105-L116). The 401 body only carries
reason: missing_credential | invalid_credential(environmentHttp.ts#L98-L101, http.ts#L96-L112). Showing "expired on " would need a contract change as well as a client change.Not verified
bearer:<envId>LAN route, re-pairing at the same LAN URL should have replaced that route and deleted its credential. The learned route would then point at a missing credential and fail with "Connection credential … is unavailable", not send the old token. Re-pairing doesn't cascade to learned routes the wayroutesAfterRemovingdoes. Can you say whether the Tailscale route was one you added yourself, or one the app learned? And was the September LAN pairing at exactly the same URL as the October one?Possible fixes (untested sketches)
routesAfterRemovingalready does.connectOverRoutes, keep retrying while any route failed transiently, but surface an authenticationblockederror from a route that reached the right server.EnvironmentAuthInvalidReason, and show a Pair again action on authentication failures.Workaround: as you found, remove the whole environment on the phone and pair again.
Related: #13055 (fixed 30-day session lifetime, which triggered this; open PR #13092 is titled as making the lifetime configurable), #15802 (re-pairing at the same address leaves a stale entry), #13072 and #8112 (other "credential is invalid / have to re-pair" reports). #5332 is closed. None of the open PRs I checked change this re-pair or removal path.