@devries-cameron20 / t3code Mirror · read-only / commits / 60efd7c869
Fork 0

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, 23:30 UTC

fix(server): t3_thread_launch refuses models the provider does not advertise (#26625)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 11, 2026 at 11:29 UTC 60efd7c8697d409a629672966f523f33f51aac4f
4 files changed +168 -15
apps/server/src/mcp/OrchestratorMcpService.test.ts
+69 -1
@@ -3181,6 +3181,17 @@ describe("OrchestratorMcpService provider resolution", () => {
3181 target: { options: {} },
3182 expected: { ...inherited, options: [] },
3183 },
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 + },
3195 {
3196 name: "change model",
3197 target: { model: "other-model" },
@@ -3225,7 +3236,10 @@ describe("OrchestratorMcpService provider resolution", () => {
3236 getThreadRecords: (threadId) =>
3237 Effect.succeed(
3238 threadId === parentThreadId
3228 - ? parentProjection(commands.length > 0 ? [task] : [], inherited)
3239 + ? parentProjection(
3240 + commands.length > 0 ? [task] : [],
3241 + "parent" in testCase ? testCase.parent : inherited,
3242 + )
3243 : childProjection,
3244 ),
3245 dispatch: (command) =>
@@ -3251,6 +3265,7 @@ describe("OrchestratorMcpService provider resolution", () => {
3265 name: model,
3266 isCustom: false,
3267 capabilities: null,
3268 + ...(model === inherited.model ? { aliases: ["gpt"] } : {}),
3269 })),
3270 {
3271 slug: "ultracode-model",
@@ -3392,6 +3407,59 @@ describe("OrchestratorMcpService provider resolution", () => {
3407 }),
3408 );
3409
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 +
3463 describe("resolveRuntimeMode", () => {
3464 const muse = {
3465 modelSelection: { instanceId: ProviderInstanceId.make("muse"), model: "muse-model" },
apps/server/src/mcp/OrchestratorMcpService.ts
+23 -14
@@ -350,6 +350,23 @@ function capabilityModelOption(descriptor: ProviderOptionDescriptor): Orchestrat
350 };
351 }
352
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 +
370 function providerConstraints(
371 provider: ServerProvider | undefined,
372 supportsOrchestrationV2: boolean,
@@ -1387,19 +1404,9 @@ const make = Effect.gen(function* () {
1404 `Provider ${instanceId} has no model available for inheritance.`,
1405 );
1406 }
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;
1410 const requestedOptions = withLegacyUltracodeEffort(descriptors, input.target?.options);
1411 if (requestedOptions !== undefined) {
1412 const invalid = invalidOptionSelections(requestedOptions, descriptors);
@@ -1412,7 +1419,9 @@ const make = Effect.gen(function* () {
1419 }
1420
1421 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);
1425 let options = inheritsOptions
1426 ? knownOptions(
1427 withLegacyUltracodeEffort(descriptors, inheritedSelection.options),
apps/server/src/mcp/toolkits/project/handlers.test.ts
+68
@@ -332,6 +332,74 @@ it.effect("a launch steps an inherited mode down to the provider's, and refuses
332 }),
333 );
334
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 +
403 it.effect("a launch retried with the same clientRequestId replays the first one", () =>
404 Effect.gen(function* () {
405 const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];
apps/server/src/mcp/toolkits/project/handlers.ts
+8
@@ -29,6 +29,7 @@ import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
29 import { resolveRuntimeMode } from "../../delegatedTaskModes.ts";
30 import * as McpInvocationContext from "../../McpInvocationContext.ts";
31 import * as McpToolAccess from "../../McpToolAccess.ts";
32 +import * as OrchestrationMcp from "../../OrchestratorMcpService.ts";
33 import { newCommandId, readCaller, resolveProjectId, unavailable } from "../../threadAccess.ts";
34 import { ProjectToolkit } from "./tools.ts";
35
@@ -152,6 +153,13 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
153 });
154 yield* assertProjectWorktree(project.workspaceRoot, input.workspaceStrategy.worktreePath);
155 }
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 + }
163 // Reject unresolved base refs before accepting a launch; worktree provisioning happens later.
164 const strategy = input.workspaceStrategy;
165 if (!replaying && strategy?.type === "worktree")