The best way to control Claude Code, Codex and more from any computer or phone
fix(server): forwarded calls to a linked environment no longer wait out a silent first address (#35546)
Julius Marminge committed
Nov 14, 2026 at 20:54 UTC
3466f9e99c75b6f0addf32489b87165ba08c9b77
2 files changed
+50
-17
apps/server/src/peer/PeerLinks.test.ts
+32
@@ -444,6 +444,38 @@ it.effect("lists a peer as reachable at another address while its first one slee
444
).pipe(Effect.provide(NodeHttpServer.layerTest)),
445
);
446
447
+it.effect("resolves a link at its answering address without waiting out a sleeping first", () =>
448
+ Effect.scoped(
449
+ Effect.gen(function* () {
450
+ const b = yield* serveB(box);
451
+ const described = yield* HttpClient.get(`${b.url}/.well-known/t3/environment`).pipe(
452
+ Effect.flatMap((response) => response.text),
453
+ Effect.provide(FetchHttpClient.layer),
454
+ );
455
+ const elsewhere = yield* serveRaw(() =>
456
+ Effect.succeed(HttpServerResponse.text(described, { contentType: "application/json" })),
457
+ );
458
+ const a = yield* makeA(laptop);
459
+ const pairing = yield* b.auth.issuePairingCredential();
460
+ yield* a.links.link({
461
+ url: b.url,
462
+ alternateUrls: [elsewhere],
463
+ pairingCode: pairing.credential,
464
+ access: "auto",
465
+ });
466
+
467
+ yield* Ref.set(b.asleep, true);
468
+ const first = yield* a.links.resolve(box.environmentId).pipe(Effect.forkScoped);
469
+ yield* Queue.take(b.unanswered);
470
+ yield* TestClock.adjust(Duration.seconds(3));
471
+ expect((yield* Fiber.join(first)).url).toBe(elsewhere);
472
+
473
+ // The clock no longer moves: a resolve that probes the sleeping address first never returns.
474
+ expect((yield* a.links.resolve(box.environmentId)).url).toBe(elsewhere);
475
+ }),
476
+ ).pipe(Effect.provide(NodeHttpServer.layerTest)),
477
+);
478
+
479
it.effect("cancelling a descriptor probe aborts its request and leaves later resolves fresh", () =>
480
Effect.scoped(
481
Effect.gen(function* () {
apps/server/src/peer/PeerLinks.ts
+18
-17
@@ -658,36 +658,37 @@ const make = Effect.gen(function* () {
658
});
659
}
660
// The token goes only to an address that still answers as this peer,
661
- // so one that now answers as another machine never receives it.
662
- let fenced = true;
663
- let label = link.label;
664
- const url = yield* Effect.findFirst(link.urls, (candidate) =>
665
- answersAs(candidate, environmentId).pipe(
666
- Effect.map((found) => {
667
- if (Option.isNone(found)) return false;
668
- fenced = linkLimitsHold(found.value);
669
- label = found.value.label;
670
- return true;
671
- }),
672
- ),
673
- );
674
- if (Option.isNone(url)) {
661
+ // so one that now answers as another machine never receives it. The
662
+ // addresses race, so a silent one never delays one that answers.
663
+ const answered =
664
+ link.urls.length === 0
665
+ ? Option.none()
666
+ : yield* Effect.raceAll(
667
+ link.urls.map((url) =>
668
+ answersAs(url, environmentId).pipe(
669
+ Effect.flatMap(Effect.fromOption),
670
+ Effect.map((peer) => ({ url, peer })),
671
+ ),
672
+ ),
673
+ ).pipe(Effect.option);
674
+ if (Option.isNone(answered)) {
675
return yield* new PeerLinkError({
676
reason: "unreachable",
677
message: `${link.label} did not answer at ${link.urls.join(", ")}.`,
678
});
679
}
680
+ const { url, peer } = answered.value;
681
// A link made before the peer had to fence linked work, or a peer moved
682
// back to such a version, would carry work past those limits.
682
- if (!fenced) {
683
+ if (!linkLimitsHold(peer)) {
684
return yield* new PeerLinkError({
685
reason: "incompatible",
686
message: `${link.label} runs a T3 Code version that cannot keep a linked agent's limits. Update it, then link again.`,
687
});
688
}
689
return {
689
- link: yield* withLabel(link, label),
690
- url: url.value,
690
+ link: yield* withLabel(link, peer.label),
691
+ url,
692
token: new TextDecoder().decode(stored.value),
693
};
694
},