The best way to control Claude Code, Codex and more from any computer or phone
fix(server): linked environments pick up the other machine's new name (#29779)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alex Southwell committed
Nov 3, 2026 at 23:25 UTC
ddaf9996a180ad1b452262dcaf7407ca32fded8a
2 files changed
+60
-21
apps/server/src/peer/PeerLinks.test.ts
+21
@@ -453,6 +453,27 @@ it.effect("reads one stored link without asking the peer", () =>
453
).pipe(Effect.provide(NodeHttpServer.layerTest)),
454
);
455
456
+it.effect("a linked peer that is renamed shows its new name", () =>
457
+ Effect.scoped(
458
+ Effect.gen(function* () {
459
+ const b = yield* serveB(box);
460
+ const a = yield* makeA(laptop);
461
+ const pairing = yield* b.auth.issuePairingCredential();
462
+ yield* a.links.link({ url: b.url, pairingCode: pairing.credential, access: "auto" });
463
+
464
+ yield* Ref.set(b.descriptor, descriptorOf(box.environmentId, "Box Mini"));
465
+ expect((yield* a.links.resolve(box.environmentId)).link.label).toBe("Box Mini");
466
+ const stored = yield* a.links.get(box.environmentId);
467
+ expect(Option.map(stored, (link) => link.label)).toEqual(Option.some("Box Mini"));
468
+
469
+ yield* Ref.set(b.descriptor, descriptorOf(box.environmentId, "Box Studio"));
470
+ expect((yield* a.links.list).map((link) => link.label)).toEqual(["Box Studio"]);
471
+ const storedAfterList = yield* a.links.get(box.environmentId);
472
+ expect(Option.map(storedAfterList, (link) => link.label)).toEqual(Option.some("Box Studio"));
473
+ }),
474
+ ).pipe(Effect.provide(NodeHttpServer.layerTest)),
475
+);
476
+
477
it.effect("tells the agent to link again once the peer revokes the link or it expires", () =>
478
Effect.scoped(
479
Effect.gen(function* () {
apps/server/src/peer/PeerLinks.ts
+39
-21
@@ -9,7 +9,6 @@ import {
9
type PeerLink,
10
type PeerLinkCreateInput,
11
PeerLinkError,
12
- type PeerLinkStatus,
12
type PeerLinkSummary,
13
} from "@t3tools/contracts";
14
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
@@ -496,29 +495,42 @@ const make = Effect.gen(function* () {
495
Effect.orElseSucceed(() => Option.none()),
496
);
497
499
- const statusOf = (link: PeerLink, now: DateTime.Utc) =>
500
- DateTime.isLessThanOrEqualTo(link.expiresAt, now)
501
- ? Effect.succeed<PeerLinkStatus>("expired")
502
- : Effect.findFirst(link.urls, (url) =>
503
- describe(url).pipe(
504
- Effect.map(
505
- (found) => Option.isSome(found) && found.value.environmentId === link.environmentId,
506
- ),
507
- ),
508
- ).pipe(
509
- Effect.map((answered): PeerLinkStatus =>
510
- Option.isSome(answered) ? "reachable" : "unreachable",
511
- ),
512
- );
498
+ /** A peer's label follows its machine name, so the link takes the one its own address answers with. */
499
+ const withLabel = (link: PeerLink, label: string) =>
500
+ label === link.label
501
+ ? Effect.succeed(link)
502
+ : sql`
503
+ UPDATE peer_environment_links SET label = ${label}
504
+ WHERE environment_id = ${link.environmentId}
505
+ `.pipe(Effect.ignoreCause({ log: true }), Effect.as({ ...link, label }));
506
+
507
+ const statusOf = Effect.fn("PeerLinks.statusOf")(function* (
508
+ link: PeerLink,
509
+ now: DateTime.Utc,
510
+ ): Effect.fn.Return<PeerLinkSummary> {
511
+ if (DateTime.isLessThanOrEqualTo(link.expiresAt, now)) return { ...link, status: "expired" };
512
+ let label = link.label;
513
+ const answered = yield* Effect.findFirst(link.urls, (url) =>
514
+ describe(url).pipe(
515
+ Effect.map((found) => {
516
+ if (Option.isNone(found) || found.value.environmentId !== link.environmentId) {
517
+ return false;
518
+ }
519
+ label = found.value.label;
520
+ return true;
521
+ }),
522
+ ),
523
+ );
524
+ if (Option.isNone(answered)) return { ...link, status: "unreachable" };
525
+ return { ...(yield* withLabel(link, label)), status: "reachable" };
526
+ });
527
528
const list: PeerLinks["Service"]["list"] = Effect.gen(function* () {
529
const links = yield* Effect.forEach(yield* readRows, toLink);
530
const now = yield* DateTime.now;
517
- return yield* Effect.forEach(
518
- links,
519
- (link) => statusOf(link, now).pipe(Effect.map((status) => ({ ...link, status }))),
520
- { concurrency: "unbounded" },
521
- );
531
+ return yield* Effect.forEach(links, (link) => statusOf(link, now), {
532
+ concurrency: "unbounded",
533
+ });
534
});
535
536
const get: PeerLinks["Service"]["get"] = (environmentId) =>
@@ -570,11 +582,13 @@ const make = Effect.gen(function* () {
582
// The token goes only to an address that proves it is this peer, so a
583
// reused LAN address or a moved hostname never receives it.
584
let fenced = true;
585
+ let label = link.label;
586
const url = yield* Effect.findFirst(link.urls, (candidate) =>
587
describe(candidate).pipe(
588
Effect.map((found) => {
589
if (Option.isNone(found) || found.value.environmentId !== environmentId) return false;
590
fenced = linkLimitsHold(found.value);
591
+ label = found.value.label;
592
return true;
593
}),
594
),
@@ -593,7 +607,11 @@ const make = Effect.gen(function* () {
607
message: `${link.label} runs a T3 Code version that cannot keep a linked agent's limits. Update it, then link again.`,
608
});
609
}
596
- return { link, url: url.value, token: new TextDecoder().decode(stored.value) };
610
+ return {
611
+ link: yield* withLabel(link, label),
612
+ url: url.value,
613
+ token: new TextDecoder().decode(stored.value),
614
+ };
615
},
616
);
617