The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 12:15 UTC
fix(server): a linked launch above the link's access names the link, not the parent mode (#27334)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 14, 2026 at 20:53 UTC
dc7ea2c1b0dcc320d7b7e901ce6982cd9f3ecab2
2 files changed
+68
-6
apps/server/src/peer/PeerForwarding.test.ts
+35
@@ -14,10 +14,12 @@ import {
14
} from "@t3tools/contracts";
15
import { expect, it } from "@effect/vitest";
16
import * as Context from "effect/Context";
17
+import * as Duration from "effect/Duration";
18
import * as Effect from "effect/Effect";
19
import * as Layer from "effect/Layer";
20
import * as Option from "effect/Option";
21
import * as Ref from "effect/Ref";
22
+import * as TestClock from "effect/testing/TestClock";
23
import { McpSchema, McpServer } from "effect/ai";
24
25
import * as ServerConfig from "../config.ts";
@@ -705,3 +707,36 @@ it.effect("refuses what a linked environment cannot take before anything leaves"
707
}),
708
).pipe(Effect.provide(NodeHttpServer.layerTest)),
709
);
710
+
711
+it.effect("refuses a launch there above the link's access, naming the link", () =>
712
+ Effect.scoped(
713
+ Effect.gen(function* () {
714
+ const seen = yield* Ref.make<Seen>(nothingSeen);
715
+ const linkSession = yield* Ref.make("");
716
+ const b = yield* serveBox(seen, linkSession);
717
+ const a = yield* makeLaptop;
718
+ yield* linkTo(a.links, b, "auto");
719
+ yield* Ref.set(linkSession, (yield* b.linkedSessions)[0]!.sessionId);
720
+
721
+ // A full-access agent here asks for more than the link allows there.
722
+ const launchAboveLink = a.call("thread:laptop-full", "t3_thread_launch", {
723
+ environmentId: box.environmentId,
724
+ projectId: boxProject,
725
+ title: "Run the suite there",
726
+ modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5" },
727
+ message: "Run the suite.",
728
+ runtimeMode: "full-access",
729
+ });
730
+ const { message } = failureOf(yield* launchAboveLink);
731
+ expect(message).toContain('"Box"');
732
+ expect(message).toContain("auto");
733
+ expect(message).toContain("full-access");
734
+ expect(message).not.toContain("parent mode");
735
+ expect((yield* Ref.get(seen)).launches).toEqual([]);
736
+
737
+ // Once the link has expired, that is what the agent needs to hear.
738
+ yield* TestClock.adjust(Duration.days(31));
739
+ expect(failureOf(yield* launchAboveLink).message).toContain("expired");
740
+ }),
741
+ ).pipe(Effect.provide(NodeHttpServer.layerTest)),
742
+);
apps/server/src/peer/PeerForwarding.ts
+33
-6
@@ -8,6 +8,8 @@ import {
8
OrchestratorMcpThreadReadResult,
9
OrchestratorMcpThreadWaitInput,
10
OrchestratorMcpThreadWaitResult,
11
+ type PeerLinkError,
12
+ RuntimeMode,
13
} from "@t3tools/contracts";
14
import * as Context from "effect/Context";
15
import * as Digest from "effect/crypto/Digest";
@@ -15,9 +17,11 @@ import * as DateTime from "effect/DateTime";
17
import * as Effect from "effect/Effect";
18
import * as Hex from "effect/encoding/Hex";
19
import * as Layer from "effect/Layer";
20
+import * as Option from "effect/Option";
21
import * as Schema from "effect/Schema";
22
import type * as Tool from "effect/ai/Tool";
23
24
+import { runtimeModeRank } from "../mcp/delegatedTaskModes.ts";
25
import { assertNotLinked } from "../mcp/linkOrigin.ts";
26
import * as McpInvocationContext from "../mcp/McpInvocationContext.ts";
27
import { readCaller, unavailable } from "../mcp/threadAccess.ts";
@@ -82,6 +86,11 @@ export const linkedEnvironmentsOff = new OrchestratorMcpFailure({
86
"Linked environments is off on this machine, so no tool can act on another machine. Leave out environmentId to work here; the user can turn it on in Settings → Labs.",
87
});
88
89
+const isRuntimeMode = Schema.is(RuntimeMode);
90
+
91
+const linkStorageFailure = (error: PeerLinkError) =>
92
+ new OrchestratorMcpFailure({ code: "orchestration_error", message: error.message });
93
+
94
/** The linked environment a call names, or nothing when it names this one. */
95
export const remoteTarget = (scope: Scope, environmentId: EnvironmentId | undefined) =>
96
environmentId === scope.environmentId ? undefined : environmentId;
@@ -116,6 +125,28 @@ const make = Effect.gen(function* () {
125
Effect.orDie,
126
);
127
128
+ /**
129
+ * The linked environment refuses a mode above the link's access too, but as
130
+ * "broader than parent mode", which misleads when the parent here is broader.
131
+ * A read-only link refuses the launch there with its own capability error,
132
+ * and an expired one is left to say it expired.
133
+ */
134
+ const assertWithinLinkAccess = Effect.fn("PeerForwarding.assertWithinLinkAccess")(function* (
135
+ environmentId: EnvironmentId,
136
+ requested: unknown,
137
+ ) {
138
+ if (!isRuntimeMode(requested)) return;
139
+ const link = yield* links.get(environmentId).pipe(Effect.mapError(linkStorageFailure));
140
+ if (Option.isNone(link)) return;
141
+ if (DateTime.isLessThanOrEqualTo(link.value.expiresAt, yield* DateTime.now)) return;
142
+ const { label, access } = link.value;
143
+ if (access === "read-only" || runtimeModeRank(requested) <= runtimeModeRank(access)) return;
144
+ return yield* new OrchestratorMcpFailure({
145
+ code: "runtime_mode_escalation_denied",
146
+ message: `Linked environment "${label}" was linked with ${access} access, so work there cannot run in ${requested}. Omit runtimeMode to run it at a mode up to ${access}, or link it again with broader access.`,
147
+ });
148
+ });
149
+
150
/** Tool and contract schemas are plain data: they encode and decode without services. */
151
const forward = Effect.fn("PeerForwarding.forward")(function* <A>(
152
scope: Scope,
@@ -130,6 +161,7 @@ const make = Effect.gen(function* () {
161
params,
162
).pipe(Effect.mapError(unavailable))) as Record<string, unknown>;
163
const { environmentId: _target, ...args } = encoded;
164
+ yield* assertWithinLinkAccess(environmentId, args.runtimeMode);
165
// A pending upload lives here, so it cannot go with the call.
166
if (Array.isArray(args.attachments) && args.attachments.length > 0) {
167
return yield* new OrchestratorMcpFailure({
@@ -230,12 +262,7 @@ const make = Effect.gen(function* () {
262
function* (scope) {
263
yield* forwardingCaller(scope);
264
yield* requireEnabled;
233
- const listed = yield* links.list.pipe(
234
- Effect.mapError(
235
- (error) =>
236
- new OrchestratorMcpFailure({ code: "orchestration_error", message: error.message }),
237
- ),
238
- );
265
+ const listed = yield* links.list.pipe(Effect.mapError(linkStorageFailure));
266
return {
267
environmentId: scope.environmentId,
268
links: listed.map((link) => ({