Skip to content

Commit 60efd7c

Browse files
fix(server): t3_thread_launch refuses models the provider does not advertise (#26625)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent bc9c84e commit 60efd7c

4 files changed

Lines changed: 168 additions & 15 deletions

File tree

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

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,17 @@ describe("OrchestratorMcpService provider resolution", () => {
31813181
target: { options: {} },
31823182
expected: { ...inherited, options: [] },
31833183
},
3184+
{
3185+
name: "same model by alias",
3186+
target: { model: "GPT" },
3187+
expected: { ...inherited, model: "GPT" },
3188+
},
3189+
{
3190+
name: "parent named the same model by alias",
3191+
parent: { ...inherited, model: "gpt" },
3192+
target: { model: inherited.model },
3193+
expected: inherited,
3194+
},
31843195
{
31853196
name: "change model",
31863197
target: { model: "other-model" },
@@ -3225,7 +3236,10 @@ describe("OrchestratorMcpService provider resolution", () => {
32253236
getThreadRecords: (threadId) =>
32263237
Effect.succeed(
32273238
threadId === parentThreadId
3228-
? parentProjection(commands.length > 0 ? [task] : [], inherited)
3239+
? parentProjection(
3240+
commands.length > 0 ? [task] : [],
3241+
"parent" in testCase ? testCase.parent : inherited,
3242+
)
32293243
: childProjection,
32303244
),
32313245
dispatch: (command) =>
@@ -3251,6 +3265,7 @@ describe("OrchestratorMcpService provider resolution", () => {
32513265
name: model,
32523266
isCustom: false,
32533267
capabilities: null,
3268+
...(model === inherited.model ? { aliases: ["gpt"] } : {}),
32543269
})),
32553270
{
32563271
slug: "ultracode-model",
@@ -3392,6 +3407,59 @@ describe("OrchestratorMcpService provider resolution", () => {
33923407
}),
33933408
);
33943409

3410+
it.effect("validates options against the model a target names by alias", () =>
3411+
Effect.gen(function* () {
3412+
const dependencies = Layer.mergeAll(
3413+
NodeServices.layer,
3414+
NodeCrypto.layer,
3415+
Layer.mock(ThreadManagementService.ThreadManagementService)({
3416+
hasReceipt: () => Effect.succeed(false),
3417+
assertProviderInstanceEnabled: () => Effect.void,
3418+
getThreadRecords: (threadId) =>
3419+
Effect.succeed(threadId === parentThreadId ? parentProjection([]) : childProjection),
3420+
dispatch: () => Effect.die("an invalid target must not dispatch"),
3421+
}),
3422+
ServerSettings.layerTest(),
3423+
providerRegistryLayer([
3424+
{
3425+
...providerSnapshot({
3426+
instanceId: codexInstanceId,
3427+
driver: ProviderDriverKind.make("codex"),
3428+
}),
3429+
models: [
3430+
{
3431+
slug: "gpt-5.4",
3432+
name: "gpt-5.4",
3433+
aliases: ["gpt"],
3434+
isCustom: false,
3435+
capabilities: {
3436+
optionDescriptors: [{ id: "fastMode", label: "Fast", type: "boolean" }],
3437+
},
3438+
},
3439+
],
3440+
},
3441+
]),
3442+
adapterRegistryLayer([codexInstanceId]),
3443+
Layer.mock(ProjectService.ProjectService)({}),
3444+
Layer.mock(SecretRequests.SecretRequests)({}),
3445+
Layer.mock(RemoteDelegation.RemoteDelegation)({}),
3446+
Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
3447+
);
3448+
const error = yield* Effect.gen(function* () {
3449+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
3450+
return yield* service
3451+
.delegateTask(scope, {
3452+
task: "Review the change.",
3453+
target: yield* decodeTarget({ model: "GPT", options: { bogus: "x" } }),
3454+
mode: "async",
3455+
})
3456+
.pipe(Effect.flip);
3457+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(dependencies))));
3458+
assert.equal(error.code, "invalid_request");
3459+
assert.include(error.message, "Unknown option bogus");
3460+
}),
3461+
);
3462+
33953463
describe("resolveRuntimeMode", () => {
33963464
const muse = {
33973465
modelSelection: { instanceId: ProviderInstanceId.make("muse"), model: "muse-model" },

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,23 @@ function capabilityModelOption(descriptor: ProviderOptionDescriptor): Orchestrat
350350
};
351351
}
352352

353+
const advertisedModel = (provider: ServerProvider, model: string) =>
354+
provider.models.find((candidate) => candidate.slug === model) ??
355+
provider.models.find((candidate) =>
356+
candidate.aliases?.some((alias) => alias.toLowerCase() === model.toLowerCase()),
357+
);
358+
359+
/** A provider that lists no models accepts any slug. */
360+
export const requireAdvertisedModel = (provider: ServerProvider, model: string) =>
361+
provider.models.length > 0 && advertisedModel(provider, model) === undefined
362+
? Effect.fail(
363+
failure(
364+
"model_unavailable",
365+
`Model ${model} is not advertised by provider ${provider.instanceId}.`,
366+
),
367+
)
368+
: Effect.void;
369+
353370
function providerConstraints(
354371
provider: ServerProvider | undefined,
355372
supportsOrchestrationV2: boolean,
@@ -1387,19 +1404,9 @@ const make = Effect.gen(function* () {
13871404
`Provider ${instanceId} has no model available for inheritance.`,
13881405
);
13891406
}
1390-
if (
1391-
requestedModel !== undefined &&
1392-
provider.models.length > 0 &&
1393-
!provider.models.some((candidate) => candidate.slug === requestedModel)
1394-
) {
1395-
return yield* failure(
1396-
"model_unavailable",
1397-
`Model ${requestedModel} is not advertised by provider ${instanceId}.`,
1398-
);
1399-
}
1400-
1401-
const descriptors = provider.models.find((candidate) => candidate.slug === model)?.capabilities
1402-
?.optionDescriptors;
1407+
if (requestedModel !== undefined) yield* requireAdvertisedModel(provider, requestedModel);
1408+
const advertised = advertisedModel(provider, model);
1409+
const descriptors = advertised?.capabilities?.optionDescriptors;
14031410
const requestedOptions = withLegacyUltracodeEffort(descriptors, input.target?.options);
14041411
if (requestedOptions !== undefined) {
14051412
const invalid = invalidOptionSelections(requestedOptions, descriptors);
@@ -1412,7 +1419,9 @@ const make = Effect.gen(function* () {
14121419
}
14131420

14141421
const inheritsOptions =
1415-
instanceId === inheritedSelection.instanceId && model === inheritedSelection.model;
1422+
instanceId === inheritedSelection.instanceId &&
1423+
(advertised?.slug ?? model) ===
1424+
(advertisedModel(provider, inheritedSelection.model)?.slug ?? inheritedSelection.model);
14161425
let options = inheritsOptions
14171426
? knownOptions(
14181427
withLegacyUltracodeEffort(descriptors, inheritedSelection.options),

‎apps/server/src/mcp/toolkits/project/handlers.test.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,74 @@ it.effect("a launch steps an inherited mode down to the provider's, and refuses
332332
}),
333333
);
334334

335+
it.effect("a launch with a model its provider does not advertise creates no thread", () =>
336+
Effect.gen(function* () {
337+
const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];
338+
const providers: ServerProvider[] = ["claudeAgent", "codex"].map((driver) => ({
339+
instanceId: ProviderInstanceId.make(driver),
340+
driver: ProviderDriverKind.make(driver),
341+
enabled: true,
342+
installed: true,
343+
status: "ready",
344+
version: null,
345+
auth: { status: "authenticated" },
346+
checkedAt: "2026-01-01T00:00:00Z",
347+
models: [
348+
driver === "claudeAgent"
349+
? {
350+
slug: "claude-opus",
351+
name: "Opus",
352+
aliases: ["opus"],
353+
isCustom: false,
354+
capabilities: null,
355+
}
356+
: { slug: "gpt-5.4", name: "GPT", isCustom: false, capabilities: null },
357+
],
358+
slashCommands: [],
359+
skills: [],
360+
}));
361+
const { projectId, dependencies } = clientLaunchHarness({
362+
runtimeModeCeiling: "auto",
363+
launched,
364+
providers,
365+
});
366+
const toolkit = yield* ProjectToolkit.pipe(
367+
Effect.provide(
368+
McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(Layer.provide(dependencies)),
369+
),
370+
);
371+
const launchWith = (instanceId: string, model: string) =>
372+
toolkit
373+
.handle("t3_thread_launch", {
374+
title: "Fix",
375+
projectId,
376+
modelSelection: { instanceId: ProviderInstanceId.make(instanceId), model },
377+
})
378+
.pipe(
379+
Stream.unwrap,
380+
Stream.runCollect,
381+
Effect.map((result) => result.at(-1)?.result),
382+
Effect.provide(dependencies),
383+
);
384+
385+
for (const [instanceId, model] of [
386+
["claudeAgent", "claude-unadvertised"],
387+
["codex", "opus"],
388+
] as const) {
389+
expect(yield* launchWith(instanceId, model)).toMatchObject({
390+
code: "model_unavailable",
391+
message: `Model ${model} is not advertised by provider ${instanceId}.`,
392+
});
393+
}
394+
expect(launched).toHaveLength(0);
395+
396+
expect(yield* launchWith("claudeAgent", "Opus")).toMatchObject({
397+
modelSelection: { instanceId: "claudeAgent", model: "Opus" },
398+
});
399+
expect(launched).toHaveLength(1);
400+
}),
401+
);
402+
335403
it.effect("a launch retried with the same clientRequestId replays the first one", () =>
336404
Effect.gen(function* () {
337405
const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];

‎apps/server/src/mcp/toolkits/project/handlers.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
2929
import { resolveRuntimeMode } from "../../delegatedTaskModes.ts";
3030
import * as McpInvocationContext from "../../McpInvocationContext.ts";
3131
import * as McpToolAccess from "../../McpToolAccess.ts";
32+
import * as OrchestrationMcp from "../../OrchestratorMcpService.ts";
3233
import { newCommandId, readCaller, resolveProjectId, unavailable } from "../../threadAccess.ts";
3334
import { ProjectToolkit } from "./tools.ts";
3435

@@ -152,6 +153,13 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
152153
});
153154
yield* assertProjectWorktree(project.workspaceRoot, input.workspaceStrategy.worktreePath);
154155
}
156+
if (!replaying && input.modelSelection !== undefined) {
157+
const { instanceId, model } = input.modelSelection;
158+
const providers = yield* (yield* ProviderRegistry.ProviderRegistry).getProviders;
159+
const provider = providers.find((candidate) => candidate.instanceId === instanceId);
160+
if (provider !== undefined)
161+
yield* OrchestrationMcp.requireAdvertisedModel(provider, model);
162+
}
155163
// Reject unresolved base refs before accepting a launch; worktree provisioning happens later.
156164
const strategy = input.workspaceStrategy;
157165
if (!replaying && strategy?.type === "worktree")

0 commit comments

Comments
 (0)