From b71d31f9a94e8c436bf85493fab9f6cb26b1cea6 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 3 Nov 2026 23:14:33 +0000 Subject: [PATCH 1/5] test(server): reproduce #30455 A full-access agent refused project create/clone through an `auto` link is told its calling thread lacks full access instead of the link, and ProjectService.create drops defaultModelSelection. Both tests fail on main. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/peer/PeerForwarding.test.ts | 6 +++++- apps/server/src/project/ProjectService.test.ts | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/server/src/peer/PeerForwarding.test.ts b/apps/server/src/peer/PeerForwarding.test.ts index 4e15b02d04e53..153814838bc61 100644 --- a/apps/server/src/peer/PeerForwarding.test.ts +++ b/apps/server/src/peer/PeerForwarding.test.ts @@ -577,7 +577,11 @@ it.effect("brings a repository to a linked environment, only through full access environmentId: box.environmentId, ...args, }); - expect(failureOf(refused), name).toMatchObject({ code: "capability_denied" }); + const failure = failureOf(refused); + expect(failure, name).toMatchObject({ code: "capability_denied" }); + // The agent's thread is full access; what holds it is the link's access. + expect(failure.message, name).toContain("linked environment"); + expect(failure.message, name).not.toContain("calling thread"); } expect((yield* Ref.get(seen)).clones).toHaveLength(1); expect((yield* Ref.get(seen)).projects).toHaveLength(1); diff --git a/apps/server/src/project/ProjectService.test.ts b/apps/server/src/project/ProjectService.test.ts index 11d3fea8f064a..9b94e617747ac 100644 --- a/apps/server/src/project/ProjectService.test.ts +++ b/apps/server/src/project/ProjectService.test.ts @@ -254,6 +254,7 @@ it.layer(layerTest)("ProjectService", (it) => { ], }); assert.equal(created.workspaceRoot, "/work/project"); + assert.deepEqual(created.defaultModelSelection, modelSelection); assert.isNull(created.repositoryIdentity); assert.isNull(created.faviconPath); From 1f6ba5ea10e717092da625764e25951030c1de99 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 3 Nov 2026 23:25:01 +0000 Subject: [PATCH 2/5] fix(server): linked project creation names the link and keeps its model A linked caller below full access was refused t3_project_create and t3_project_clone with a message blaming the calling thread, when the limit is the link's access. The full-access check now names the link for callers a link fences, in the same words as the other linked-environment refusals. project.create also dropped defaultModelSelection: the command had no field for it and the decider wrote null. The command now carries it and ProjectService.create passes it, which also fixes projects.mutate. Fixes pingdotgg/t3code#30455 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/mcp/McpToolAccess.ts | 14 ++++++++++--- apps/server/src/mcp/linkOrigin.ts | 21 +++++++++++++++++-- .../src/orchestration-v2/ProjectCommands.ts | 3 ++- apps/server/src/project/ProjectService.ts | 3 +++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/apps/server/src/mcp/McpToolAccess.ts b/apps/server/src/mcp/McpToolAccess.ts index b82d9bb5ae59c..0c8ed70c70776 100644 --- a/apps/server/src/mcp/McpToolAccess.ts +++ b/apps/server/src/mcp/McpToolAccess.ts @@ -21,7 +21,12 @@ import { type DispatchModeRefusal, } from "../orchestration-v2/DispatchModeLimit.ts"; import * as PeerForwarding from "../peer/PeerForwarding.ts"; -import { assertNotLinked, assertSameLink, callerLinkOrigin } from "./linkOrigin.ts"; +import { + assertFullAccessNamingLink, + assertNotLinked, + assertSameLink, + callerLinkOrigin, +} from "./linkOrigin.ts"; import * as McpInvocationContext from "./McpInvocationContext.ts"; import { resolveInteractionMode, resolveRuntimeMode } from "./delegatedTaskModes.ts"; import { @@ -283,6 +288,7 @@ export const either = ( const fullAccessRequired = "Changing projects or environment settings needs a live full-access/default calling thread or a full-access client."; +const changesEnvironment = "change projects or environment settings"; /** Recheck after waits before writing; caller modes may have changed. */ export const writesEnvironment = ( @@ -302,9 +308,11 @@ export const writesEnvironment = ( Effect.tap((caller) => options?.linkedCallers === "allowed" ? Effect.void - : assertNotLinked(caller, "change projects or environment settings"), + : assertNotLinked(caller, changesEnvironment), + ), + Effect.tap((caller) => + assertFullAccessNamingLink(caller, fullAccessRequired, changesEnvironment), ), - Effect.tap((caller) => assertFullAccess(caller, fullAccessRequired)), ); return declare( (params: P) => check.pipe(Effect.flatMap(() => handle(params, check))), diff --git a/apps/server/src/mcp/linkOrigin.ts b/apps/server/src/mcp/linkOrigin.ts index 7373fd51d2bd4..8ef3cd52953f9 100644 --- a/apps/server/src/mcp/linkOrigin.ts +++ b/apps/server/src/mcp/linkOrigin.ts @@ -6,7 +6,7 @@ import { } from "@t3tools/contracts"; import * as Effect from "effect/Effect"; -import type { Caller } from "./threadAccess.ts"; +import { assertFullAccess, type Caller } from "./threadAccess.ts"; /** * Below full access, work a link starts here (all of it carries that session in `linkOrigin`) @@ -34,10 +34,13 @@ const fencingLinkOrigin = (caller: Pick) => { return origin !== undefined && linkOriginIsFenced(origin) ? origin : undefined; }; +const outsideLinkMessage = (origin: OrchestrationV2LinkOrigin, message: string) => + `This work was started from ${origin.label} through a linked environment, so ${message} A link paired with full access is not limited this way.`; + const outsideLink = (origin: OrchestrationV2LinkOrigin, message: string) => new OrchestratorMcpFailure({ code: "capability_denied", - message: `This work was started from ${origin.label} through a linked environment, so ${message} A link paired with full access is not limited this way.`, + message: outsideLinkMessage(origin, message), }); /** A thread a fenced caller may change: one its own link started. */ @@ -58,3 +61,17 @@ export const assertNotLinked = (caller: Pick, what: ? Effect.void : Effect.fail(outsideLink(origin, `it cannot ${what}.`)); }; + +/** A fenced caller is held below full access by its link, not its thread, so the refusal names the link. */ +export const assertFullAccessNamingLink = (caller: Caller, message: string, what: string) => { + const origin = fencingLinkOrigin(caller); + return assertFullAccess( + caller, + origin === undefined + ? message + : outsideLinkMessage( + origin, + `it has that link's access, which is below the full access needed to ${what}.`, + ), + ); +}; diff --git a/apps/server/src/orchestration-v2/ProjectCommands.ts b/apps/server/src/orchestration-v2/ProjectCommands.ts index d4c1abb3ceda2..56caa3718f143 100644 --- a/apps/server/src/orchestration-v2/ProjectCommands.ts +++ b/apps/server/src/orchestration-v2/ProjectCommands.ts @@ -22,6 +22,7 @@ export interface ProjectCreateCommand { readonly projectId: ProjectId; readonly title: string; readonly workspaceRoot: string; + readonly defaultModelSelection?: ModelSelection | null; readonly scripts?: ReadonlyArray; } @@ -159,7 +160,7 @@ export function planProjectCommand(input: { projectId: command.projectId, title: command.title, workspaceRoot: command.workspaceRoot, - defaultModelSelection: null, + defaultModelSelection: command.defaultModelSelection ?? null, faviconPath: null, projectIcon: null, scripts: command.scripts ?? [], diff --git a/apps/server/src/project/ProjectService.ts b/apps/server/src/project/ProjectService.ts index 914456a500c51..76e63afcb24d0 100644 --- a/apps/server/src/project/ProjectService.ts +++ b/apps/server/src/project/ProjectService.ts @@ -351,6 +351,9 @@ export const make = Effect.gen(function* () { projectId: input.projectId, title: input.title, workspaceRoot, + ...(input.defaultModelSelection === undefined + ? {} + : { defaultModelSelection: input.defaultModelSelection }), ...(input.scripts === undefined ? {} : { scripts: input.scripts }), }); yield* projectEnrichment.invalidate([workspaceRoot]); From 2270d2a0780d9a567bcaa83f6a2c61bba9fb4fbd Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 3 Nov 2026 23:35:06 +0000 Subject: [PATCH 3/5] fix(server): refuse a create-time model default instead of storing it Project creation records no model default by design (#9164); only t3_project_update does. Restore that rule and have t3_project_create refuse a defaultModelSelection with a reason rather than drop it silently. The link refusal now also names the link's access level. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/mcp/linkOrigin.ts | 2 +- .../src/mcp/toolkits/project/handlers.test.ts | 50 +++++++++++++++++++ .../src/mcp/toolkits/project/handlers.ts | 6 +++ .../src/orchestration-v2/ProjectCommands.ts | 3 +- .../server/src/project/ProjectService.test.ts | 1 - apps/server/src/project/ProjectService.ts | 3 -- 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/apps/server/src/mcp/linkOrigin.ts b/apps/server/src/mcp/linkOrigin.ts index 8ef3cd52953f9..3c8b17f3c7165 100644 --- a/apps/server/src/mcp/linkOrigin.ts +++ b/apps/server/src/mcp/linkOrigin.ts @@ -71,7 +71,7 @@ export const assertFullAccessNamingLink = (caller: Caller, message: string, what ? message : outsideLinkMessage( origin, - `it has that link's access, which is below the full access needed to ${what}.`, + `it has that link's ${origin.access} access, which is below the full access needed to ${what}.`, ), ); }; diff --git a/apps/server/src/mcp/toolkits/project/handlers.test.ts b/apps/server/src/mcp/toolkits/project/handlers.test.ts index 6721e89478550..1b80e1219ec1d 100644 --- a/apps/server/src/mcp/toolkits/project/handlers.test.ts +++ b/apps/server/src/mcp/toolkits/project/handlers.test.ts @@ -621,6 +621,56 @@ it.effect("a client launches with the fallback for an exhausted default", () => }), ); +it.effect("creating a project through MCP refuses a model default instead of dropping it", () => + Effect.gen(function* () { + const created: Array = []; + const harness = clientLaunchHarness({ runtimeModeCeiling: "full-access", launched: [] }); + const dependencies = Layer.merge( + harness.dependencies, + Layer.mock(Project.ProjectService)({ + create: (input) => + Effect.sync(() => { + created.push(input); + return { + id: input.projectId, + title: input.title, + workspaceRoot: input.workspaceRoot, + repositoryIdentity: null, + faviconPath: null, + defaultModelSelection: null, + defaultThreadEnvMode: null, + autoPull: false, + projectIcon: null, + scripts: [], + createdAt: "2026-01-01T00:00:00.000Z", + updatedAt: "2026-01-01T00:00:00.000Z", + deletedAt: null, + } as unknown as ProjectRecord; + }), + }), + ); + const toolkit = yield* ProjectToolkit.pipe( + Effect.provide( + McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(Layer.provide(dependencies)), + ), + ); + + const refused = yield* toolkit + .handle("t3_project_create", { + title: "client-target", + workspaceRoot: "/projects/client-target", + defaultModelSelection: harness.modelSelection, + }) + .pipe(Stream.unwrap, Stream.runCollect, Effect.provide(dependencies)); + + expect(refused.at(-1)?.result).toMatchObject({ + code: "invalid_request", + message: expect.stringContaining("t3_project_update"), + }); + expect(created).toHaveLength(0); + }), +); + it.effect("deleting a project through MCP also discards its clone record", () => Effect.gen(function* () { const discarded: Array = []; diff --git a/apps/server/src/mcp/toolkits/project/handlers.ts b/apps/server/src/mcp/toolkits/project/handlers.ts index 253964cc55146..c3d7b1b7273f6 100644 --- a/apps/server/src/mcp/toolkits/project/handlers.ts +++ b/apps/server/src/mcp/toolkits/project/handlers.ts @@ -345,6 +345,12 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { ...(created.commitError === undefined ? {} : { commitError: created.commitError }), }; } + if (input.defaultModelSelection !== undefined && input.defaultModelSelection !== null) + return yield* new OrchestratorMcpFailure({ + code: "invalid_request", + message: + "Creating a project does not set its default model; set defaultModelSelection afterwards with t3_project_update.", + }); const commandId = yield* newCommandId(); return yield* projects .create({ ...input, workspaceRoot, commandId, projectId: ProjectId.make(commandId) }) diff --git a/apps/server/src/orchestration-v2/ProjectCommands.ts b/apps/server/src/orchestration-v2/ProjectCommands.ts index 56caa3718f143..d4c1abb3ceda2 100644 --- a/apps/server/src/orchestration-v2/ProjectCommands.ts +++ b/apps/server/src/orchestration-v2/ProjectCommands.ts @@ -22,7 +22,6 @@ export interface ProjectCreateCommand { readonly projectId: ProjectId; readonly title: string; readonly workspaceRoot: string; - readonly defaultModelSelection?: ModelSelection | null; readonly scripts?: ReadonlyArray; } @@ -160,7 +159,7 @@ export function planProjectCommand(input: { projectId: command.projectId, title: command.title, workspaceRoot: command.workspaceRoot, - defaultModelSelection: command.defaultModelSelection ?? null, + defaultModelSelection: null, faviconPath: null, projectIcon: null, scripts: command.scripts ?? [], diff --git a/apps/server/src/project/ProjectService.test.ts b/apps/server/src/project/ProjectService.test.ts index 9b94e617747ac..11d3fea8f064a 100644 --- a/apps/server/src/project/ProjectService.test.ts +++ b/apps/server/src/project/ProjectService.test.ts @@ -254,7 +254,6 @@ it.layer(layerTest)("ProjectService", (it) => { ], }); assert.equal(created.workspaceRoot, "/work/project"); - assert.deepEqual(created.defaultModelSelection, modelSelection); assert.isNull(created.repositoryIdentity); assert.isNull(created.faviconPath); diff --git a/apps/server/src/project/ProjectService.ts b/apps/server/src/project/ProjectService.ts index 76e63afcb24d0..914456a500c51 100644 --- a/apps/server/src/project/ProjectService.ts +++ b/apps/server/src/project/ProjectService.ts @@ -351,9 +351,6 @@ export const make = Effect.gen(function* () { projectId: input.projectId, title: input.title, workspaceRoot, - ...(input.defaultModelSelection === undefined - ? {} - : { defaultModelSelection: input.defaultModelSelection }), ...(input.scripts === undefined ? {} : { scripts: input.scripts }), }); yield* projectEnrichment.invalidate([workspaceRoot]); From 0e82b7c086c0943e563e73cc6e190fc763f9af9e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 3 Nov 2026 23:41:38 +0000 Subject: [PATCH 4/5] fix(server): omit an unrecorded link access from the refusal Co-Authored-By: Claude Opus 5.5 --- apps/server/src/mcp/linkOrigin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/mcp/linkOrigin.ts b/apps/server/src/mcp/linkOrigin.ts index 3c8b17f3c7165..e158cf5f5643c 100644 --- a/apps/server/src/mcp/linkOrigin.ts +++ b/apps/server/src/mcp/linkOrigin.ts @@ -71,7 +71,7 @@ export const assertFullAccessNamingLink = (caller: Caller, message: string, what ? message : outsideLinkMessage( origin, - `it has that link's ${origin.access} access, which is below the full access needed to ${what}.`, + `it has that link's ${origin.access === undefined ? "" : `${origin.access} `}access, which is below the full access needed to ${what}.`, ), ); }; From 4b2c0eed06177c953c05e903fbee43cb4b25812f Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 10 Nov 2026 23:28:17 +0000 Subject: [PATCH 5/5] test(server): fail the model-default refusal test on any create call AI-assisted; verified with the tests and tools listed above. --- .../src/mcp/toolkits/project/handlers.test.ts | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/apps/server/src/mcp/toolkits/project/handlers.test.ts b/apps/server/src/mcp/toolkits/project/handlers.test.ts index f38a13467965e..8a99410a850eb 100644 --- a/apps/server/src/mcp/toolkits/project/handlers.test.ts +++ b/apps/server/src/mcp/toolkits/project/handlers.test.ts @@ -623,30 +623,11 @@ it.effect("a client launches with the fallback for an exhausted default", () => it.effect("creating a project through MCP refuses a model default instead of dropping it", () => Effect.gen(function* () { - const created: Array = []; const harness = clientLaunchHarness({ runtimeModeCeiling: "full-access", launched: [] }); const dependencies = Layer.merge( harness.dependencies, Layer.mock(Project.ProjectService)({ - create: (input) => - Effect.sync(() => { - created.push(input); - return { - id: input.projectId, - title: input.title, - workspaceRoot: input.workspaceRoot, - repositoryIdentity: null, - faviconPath: null, - defaultModelSelection: null, - defaultThreadEnvMode: null, - autoPull: false, - projectIcon: null, - scripts: [], - createdAt: "2026-01-01T00:00:00.000Z", - updatedAt: "2026-01-01T00:00:00.000Z", - deletedAt: null, - } as unknown as ProjectRecord; - }), + create: () => Effect.die("the project was created without its model default"), }), ); const toolkit = yield* ProjectToolkit.pipe( @@ -667,7 +648,6 @@ it.effect("creating a project through MCP refuses a model default instead of dro code: "invalid_request", message: expect.stringContaining("t3_project_update"), }); - expect(created).toHaveLength(0); }), );