Skip to content

Commit 2799d3c

Browse files
committed
fix(server): honour T3-Mode-Inherit only from a peer link
The independent re-reviews of b73f8fe found three gaps. - The receiving /mcp accepted T3-Mode-Inherit from any OAuth client, so a non-link client could start its own omitted-mode launch at its ceiling rather than the project default. That widens no access, but it breaks the rule that a client outside a thread keeps the local default. - No test pinned that an inheriting launch takes the caller's own mode rather than the link's access. - No test pinned the receiver's header rules. Changes: - withModeLimit sets inheritsModes only for a linked client. - PeerForwarding's launch test adds a thread whose mode (auto) sits between the box default and the full-access link. It must start at auto. - McpHttpServer's T3-Mode-Limit test gains a peer-link caller and pins four rules: inherit is honoured beside a valid limit; ignored without one; ignored unless the value is "1"; ignored from a non-link client. - The MODE_LIMIT_HEADER doc now says a broad limit gains no access, rather than nothing. - docs/internals/remote.md states the receiver rule and mixed-version behaviour. - docs/user/remote-access.md tells users what mode a linked task starts in. Fails before: with the linked check removed (b73f8fe's receiver), the McpHttpServer T3-Mode-Limit test fails on the non-link row. After: PeerForwarding 6/6 and the McpHttpServer T3-Mode-Limit test pass. tsc, fmt and lint are clean on the changed files. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01A1D6J2UMPo7YBWQFvbg1br
1 parent b73f8fe commit 2799d3c

6 files changed

Lines changed: 59 additions & 15 deletions

File tree

‎apps/server/src/mcp/McpHttpServer.test.ts‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,7 @@ it.effect(
10821082
Effect.scoped(
10831083
Effect.gen(function* () {
10841084
const clientToken = "client-payload.client-signature";
1085+
const linkToken = "link-payload.link-signature";
10851086
const clientScope: McpInvocationContext.McpInvocationScope = {
10861087
environmentId,
10871088
requestNamespace: "client:linked",
@@ -1090,6 +1091,11 @@ it.effect(
10901091
capabilities: new Set(["orchestration"]),
10911092
issuedAt: 1,
10921093
};
1094+
const linkScope: McpInvocationContext.McpInvocationScope = {
1095+
...clientScope,
1096+
requestNamespace: "client:peer-link",
1097+
client: { sessionId: "peer-link", label: "T3 Code · desk", access: "auto", linked: true },
1098+
};
10931099
// Starts a thread at the modes the gate hands it, so the outcome is those modes.
10941100
const StartsToolkit = Toolkit.make(
10951101
Tool.make("starts", {
@@ -1113,13 +1119,19 @@ it.effect(
11131119
starts: McpToolAccess.startsThreads(
11141120
(input) => input,
11151121
(_, modes) =>
1116-
Effect.succeed({ modes: `${modes.runtimeMode}/${modes.interactionMode}` }),
1122+
Effect.gen(function* () {
1123+
const scope = yield* McpInvocationContext.McpInvocationContext;
1124+
const inherits = scope.client?.inheritsModes === true ? "+inherit" : "";
1125+
return { modes: `${modes.runtimeMode}/${modes.interactionMode}${inherits}` };
1126+
}),
11171127
"stamped",
11181128
),
11191129
}),
11201130
).pipe(
11211131
Layer.provideMerge(
1122-
McpHttpServer.layerMcpTransport.pipe(Layer.provide(ServerSettings.layerTest())),
1132+
McpHttpServer.layerMcpTransport.pipe(
1133+
Layer.provide(ServerSettings.layerTest({ linkedEnvironmentsEnabled: true })),
1134+
),
11231135
),
11241136
Layer.provide(McpToolAccessTestkit.liveThreadsLayer),
11251137
Layer.provide(
@@ -1134,7 +1146,9 @@ it.effect(
11341146
Effect.succeed(
11351147
request.headers.authorization === `Bearer ${clientToken}`
11361148
? clientScope
1137-
: undefined,
1149+
: request.headers.authorization === `Bearer ${linkToken}`
1150+
? linkScope
1151+
: undefined,
11381152
),
11391153
}),
11401154
),
@@ -1161,12 +1175,17 @@ it.effect(
11611175
),
11621176
);
11631177
/** Starts a thread as the client, with `limit` as T3-Mode-Limit; the HTTP status or the outcome. */
1164-
const start = (limit: string | undefined, args: Record<string, string> = {}) =>
1178+
const start = (
1179+
limit: string | undefined,
1180+
args: Record<string, string> = {},
1181+
as: { readonly token?: string; readonly inherit?: string } = {},
1182+
) =>
11651183
Effect.gen(function* () {
11661184
const headers = {
11671185
accept: "application/json, text/event-stream",
1168-
authorization: `Bearer ${clientToken}`,
1186+
authorization: `Bearer ${as.token ?? clientToken}`,
11691187
...(limit === undefined ? {} : { "t3-mode-limit": limit }),
1188+
...(as.inherit === undefined ? {} : { "t3-mode-inherit": as.inherit }),
11701189
};
11711190
const initialize = yield* httpClient.post("/mcp", {
11721191
headers,
@@ -1218,6 +1237,18 @@ it.effect(
12181237
expect(yield* start("auto")).toBe(400);
12191238
expect(yield* start("auto/default/extra")).toBe(400);
12201239
expect(yield* start("root/default")).toBe(400);
1240+
1241+
// T3-Mode-Inherit marks a peer link's limit as its agent's own modes:
1242+
// only from a link, only beside a valid limit, and only as "1".
1243+
const link = { token: linkToken, inherit: "1" };
1244+
expect(yield* start("auto-accept-edits/plan", {}, link)).toBe(
1245+
"auto-accept-edits/plan+inherit",
1246+
);
1247+
expect(yield* start(undefined, {}, link)).toBe("auto/default");
1248+
expect(yield* start("auto/default", {}, { token: linkToken, inherit: "true" })).toBe(
1249+
"auto/default",
1250+
);
1251+
expect(yield* start("auto/default", {}, { inherit: "1" })).toBe("auto/default");
12211252
}),
12221253
).pipe(Effect.provide(NodeHttpServer.layerTest)),
12231254
);

‎apps/server/src/mcp/McpHttpServer.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ const withModeLimit = (
185185
client: {
186186
...invocation.client,
187187
narrowedTo: limit.value,
188-
...(request.headers[McpInvocationContext.MODE_INHERIT_HEADER] === "1"
188+
...(invocation.client.linked === true &&
189+
request.headers[McpInvocationContext.MODE_INHERIT_HEADER] === "1"
189190
? { inheritsModes: true }
190191
: {}),
191192
},

‎apps/server/src/mcp/McpInvocationContext.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ export interface McpClientCaller {
5555
* `T3-Mode-Limit: <runtimeMode>/<interactionMode>` lets an OAuth client cap
5656
* a request below what it was approved with: another environment passes on
5757
* the limits of the agent it calls for. It can only narrow (see
58-
* `clientModeCeiling`), so a client gains nothing by sending a broad one.
58+
* `clientModeCeiling`), so a client gains no access by sending a broad one.
5959
*/
6060
export const MODE_LIMIT_HEADER = "t3-mode-limit";
6161

6262
/**
6363
* `T3-Mode-Inherit: 1` beside `T3-Mode-Limit` marks that limit as the calling agent's own
64-
* modes, so a launch naming no mode starts there instead of at the project default. An
65-
* environment sends it only for a calling thread: a client outside one has a ceiling, not a mode.
64+
* modes, so a launch naming no mode starts there, not at the project default. Only a peer
65+
* link's is honoured, and a link sends it only for a thread: a client has a ceiling, not modes.
6666
*/
6767
export const MODE_INHERIT_HEADER = "t3-mode-inherit";
6868

‎apps/server/src/peer/PeerForwarding.test.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ const makeLaptop = Effect.gen(function* () {
292292
threadId,
293293
threadId === ThreadId.make("thread:laptop-plan")
294294
? { runtimeMode: "full-access", interactionMode: "plan" }
295-
: { runtimeMode: "full-access" },
295+
: threadId === ThreadId.make("thread:laptop-auto")
296+
? { runtimeMode: "auto" }
297+
: { runtimeMode: "full-access" },
296298
),
297299
),
298300
getProjectThreadRecords: ({ threadId }) =>
@@ -532,11 +534,16 @@ it.effect("launches in a linked environment with the caller's modes, retry-safe"
532534
expect(yield* Ref.get(b.bearers)).toEqual([]);
533535
expect((yield* Ref.get(seen)).launches).toHaveLength(2);
534536

537+
// A thread's own mode below the link carries over as itself: auto, not
538+
// the link's full access, and not the box default.
539+
const fromAuto = yield* launch("thread:laptop-auto", { clientRequestId: "launch-3" });
540+
expect(fromAuto.isError).toBe(false);
541+
expect((yield* Ref.get(seen)).launches[2]).toMatchObject({ runtimeMode: "auto" });
535542
// A client outside a thread has a ceiling, not modes to inherit, so its
536543
// launch there starts at that project's default, as it would here.
537-
const fromClient = yield* launch("client:outside", { clientRequestId: "launch-3" });
544+
const fromClient = yield* launch("client:outside", { clientRequestId: "launch-4" });
538545
expect(fromClient.isError).toBe(false);
539-
expect((yield* Ref.get(seen)).launches[2]).toMatchObject({
546+
expect((yield* Ref.get(seen)).launches[3]).toMatchObject({
540547
runtimeMode: "approval-required",
541548
});
542549
}),

‎docs/internals/remote.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ Unlinking on the linking side only forgets the token.
9595
approved access with. A plan-mode agent therefore cannot start full-access
9696
work through a full-access link.
9797
- **A launch that names no mode inherits a calling thread's modes**, capped by
98-
the link: the forwarder adds `T3-Mode-Inherit: 1` only for a thread. A client
99-
outside a thread sends a ceiling, not modes, so the far side starts it at the
100-
project default, as here. Environments without the header keep that default.
98+
the link: the forwarder adds `T3-Mode-Inherit: 1` only for a thread, and the
99+
receiving `/mcp` honours it only from a peer link. A client outside a thread
100+
sends a ceiling, not modes, so the far side starts its launch at the project
101+
default, within that ceiling and the link, as here. If either side predates
102+
the header, every linked launch keeps that project default.
101103
- **The token goes only to an address that proves it is the linked
102104
environment**: its descriptor must report the linked environment id. A LAN
103105
address that now belongs to another machine never receives it.

‎docs/user/remote-access.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ and the access, then approve.
294294

295295
- The access you pick is the most agents from this machine may do there. An
296296
agent also never gets more there than its own mode here.
297+
- A thread or task an agent starts there without naming a mode runs in the
298+
agent's own mode, up to the link's access. Both machines need a SynthOS
299+
version with this behaviour; otherwise it starts at that machine's default.
297300
- Threads a link starts are marked **From** and this machine's name there.
298301
- A full-access link works there like that machine's own agents. Below full
299302
access, the link's agents can change only threads it started, not that

0 commit comments

Comments
 (0)