The best way to control Claude Code, Codex and more from any computer or phone
fix(server): a link forgotten mid-resolve says it is not linked (#36132)
Julius Marminge committed
Nov 13, 2026 at 03:18 UTC
08be7829df166d6758ff651a993ee3e2ec2de422
2 files changed
+38
-6
apps/server/src/peer/PeerLinks.test.ts
+31
@@ -565,6 +565,37 @@ it.effect("a linked peer that is renamed shows its new name", () =>
565
).pipe(Effect.provide(NodeHttpServer.layerTest)),
566
);
567
568
+it.effect(
569
+ "a link forgotten while it resolves says it is not linked, not that it lost its credential",
570
+ () =>
571
+ Effect.scoped(
572
+ Effect.gen(function* () {
573
+ const b = yield* serveB(box);
574
+ const beforeGet = yield* Ref.make<Effect.Effect<void>>(Effect.void);
575
+ const racing = Layer.effect(
576
+ ServerSecretStore.ServerSecretStore,
577
+ Effect.map(ServerSecretStore.make, (store) =>
578
+ ServerSecretStore.ServerSecretStore.of({
579
+ ...store,
580
+ get: (name) =>
581
+ Ref.getAndSet(beforeGet, Effect.void).pipe(
582
+ Effect.flatten,
583
+ Effect.andThen(store.get(name)),
584
+ ),
585
+ }),
586
+ ),
587
+ );
588
+ const a = yield* makeA(laptop, racing);
589
+ const pairing = yield* b.auth.issuePairingCredential();
590
+ yield* a.links.link({ url: b.url, pairingCode: pairing.credential, access: "auto" });
591
+
592
+ yield* Ref.set(beforeGet, Effect.orDie(Effect.asVoid(a.links.unlink(box.environmentId))));
593
+ const forgotten = yield* probe(a).pipe(Effect.flip);
594
+ expect(forgotten.message).toContain("not linked to");
595
+ }),
596
+ ).pipe(Effect.provide(NodeHttpServer.layerTest)),
597
+);
598
+
599
it.effect("tells the agent to link again once the peer revokes the link or it expires", () =>
600
Effect.scoped(
601
Effect.gen(function* () {
apps/server/src/peer/PeerLinks.ts
+7
-6
@@ -635,13 +635,12 @@ const make = Effect.gen(function* () {
635
636
const resolve: PeerLinks["Service"]["resolve"] = Effect.fn("PeerLinks.resolve")(
637
function* (environmentId) {
638
+ const notLinked = new PeerLinkError({
639
+ reason: "unknown_link",
640
+ message: `This environment is not linked to ${environmentId}. t3_environment_links lists the linked ones.`,
641
+ });
642
const row = yield* readRow(environmentId);
639
- if (Option.isNone(row)) {
640
- return yield* new PeerLinkError({
641
- reason: "unknown_link",
642
- message: `This environment is not linked to ${environmentId}. t3_environment_links lists the linked ones.`,
643
- });
644
- }
643
+ if (Option.isNone(row)) return yield* notLinked;
644
const link = yield* toLink(row.value);
645
if (DateTime.isLessThanOrEqualTo(link.expiresAt, yield* DateTime.now)) {
646
return yield* new PeerLinkError({
@@ -651,6 +650,8 @@ const make = Effect.gen(function* () {
650
}
651
const stored = yield* secrets.get(row.value.secret_name).pipe(Effect.catch(failStorage));
652
if (Option.isNone(stored)) {
653
+ // An unlink between the two reads removes the row before its secret.
654
+ if (Option.isNone(yield* readRow(environmentId))) return yield* notLinked;
655
return yield* new PeerLinkError({
656
reason: "unknown_link",
657
message: `The link to ${link.label} lost its credential. Link it again.`,