The best way to control Claude Code, Codex and more from any computer or phone
fix(client-runtime): re-pairing at a new address uses the new token (#25591)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
عبدالسلام committed
Nov 1, 2026 at 23:58 UTC
aa46f7ada4718fbe55cb83e278392b2221ede2e4
3 files changed
+53
-5
packages/client-runtime/src/connection/registry.test.ts
+32
@@ -2090,6 +2090,38 @@ describe("EnvironmentRegistry routes", () => {
2090
}),
2091
);
2092
2093
+ it.effect("re-pairing at another loopback address prefers the new route", () =>
2094
+ Effect.gen(function* () {
2095
+ const loopback = (connectionId: string, host: string) =>
2096
+ [
2097
+ new BearerConnectionTarget({ ...LAN_TARGET, connectionId }),
2098
+ new BearerConnectionProfile({
2099
+ ...LAN_PROFILE,
2100
+ connectionId,
2101
+ httpBaseUrl: `http://${host}:3773/`,
2102
+ wsBaseUrl: `ws://${host}:3773/`,
2103
+ }),
2104
+ ] as const;
2105
+ const [savedTarget, savedProfile] = loopback("bearer:ip", "127.0.0.1");
2106
+ const [pastedTarget, pastedProfile] = loopback("bearer:localhost", "localhost");
2107
+ const harness = yield* makeHarness(
2108
+ [savedTarget, RELAY_TARGET],
2109
+ [savedProfile],
2110
+ [[savedTarget.connectionId, BEARER_CREDENTIAL]],
2111
+ );
2112
+ yield* Effect.gen(function* () {
2113
+ const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
2114
+ yield* registry.register(lanRegistration(pastedTarget, pastedProfile));
2115
+
2116
+ expect(routesOf(yield* Ref.get(harness.storedTargets), LAN_TARGET.environmentId)).toEqual([
2117
+ pastedTarget,
2118
+ savedTarget,
2119
+ RELAY_TARGET,
2120
+ ]);
2121
+ }).pipe(Effect.provide(harness.layer), Effect.scoped);
2122
+ }),
2123
+ );
2124
+
2125
it.effect(
2126
"adding a saved SSH host again replaces its route, whatever id it was saved under",
2127
() =>
packages/client-runtime/src/connection/routes.test.ts
+11
@@ -89,6 +89,17 @@ describe("connection routes", () => {
89
expect(upsertRoute([RELAY, LAN], repaired)).toEqual([RELAY, repaired]);
90
});
91
92
+ it("puts a newly paired route ahead of saved routes of the same kind", () => {
93
+ const pasted = direct("lan-2", "http://192.168.1.11:3773/");
94
+ expect(upsertRoute([LAN, TAILNET], pasted)).toEqual([pasted, LAN, TAILNET]);
95
+ });
96
+
97
+ it("keeps a newly paired route behind a different kind of the same rank", () => {
98
+ const vpn = direct("vpn", "http://100.101.102.103:3773/");
99
+ const pasted = direct("ts-2", "http://[fd7a:115c:a1e0::2]:3773/");
100
+ expect(upsertRoute([vpn, TAILNET], pasted)).toEqual([vpn, pasted, TAILNET]);
101
+ });
102
+
103
it("shows a dragged order only until the saved routes catch up or change", () => {
104
const dragged = ["tailnet", "lan"];
105
expect(pendingRouteOrder(dragged, ["lan", "tailnet"])).toBe(dragged);
packages/client-runtime/src/connection/routes.ts
+10
-5
@@ -115,11 +115,14 @@ const ROUTE_KIND_RANK: Record<ConnectionRouteKind, number> = {
115
export function insertRoute(
116
routes: ReadonlyArray<ConnectionRoute>,
117
route: ConnectionRoute,
118
+ { aheadOfSameKind = false }: { readonly aheadOfSameKind?: boolean } = {},
119
): ReadonlyArray<ConnectionRoute> {
119
- const rank = ROUTE_KIND_RANK[connectionRouteKind(route)];
120
- const index = routes.findIndex(
121
- (existing) => ROUTE_KIND_RANK[connectionRouteKind(existing)] > rank,
122
- );
120
+ const kind = connectionRouteKind(route);
121
+ const rank = ROUTE_KIND_RANK[kind];
122
+ const index = routes.findIndex((existing) => {
123
+ const existingKind = connectionRouteKind(existing);
124
+ return ROUTE_KIND_RANK[existingKind] > rank || (aheadOfSameKind && existingKind === kind);
125
+ });
126
return index === -1
127
? [...routes, route]
128
: [...routes.slice(0, index), route, ...routes.slice(index)];
@@ -132,7 +135,9 @@ export function upsertRoute(
135
const id = connectionRouteId(route.target);
136
return routes.some((existing) => connectionRouteId(existing.target) === id)
137
? routes.map((existing) => (connectionRouteId(existing.target) === id ? route : existing))
135
- : insertRoute(routes, route);
138
+ : // A route paired at a new address, such as localhost beside a saved
139
+ // 127.0.0.1, goes first among its kind so its fresh credential connects.
140
+ insertRoute(routes, route, { aheadOfSameKind: true });
141
}
142
143
export function findRouteToSameAddress(