Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 1 addition & 35 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ import {
taskPrompt,
} from "./delegatedTaskModes.ts";
import { isLiveCallerShell, threadNotFound } from "./threadAccess.ts";
import { invalidOptionSelections } from "./modelOptionValidation.ts";
import * as SecretRequests from "../secrets/SecretRequests.ts";
import * as PeerForwarding from "../peer/PeerForwarding.ts";
import * as RemoteDelegation from "../peer/RemoteDelegation.ts";
Expand Down Expand Up @@ -410,41 +411,6 @@ function knownOptions(
return options.filter((option) => descriptors.some((descriptor) => descriptor.id === option.id));
}

/** Skip checks without descriptors; reject duplicate IDs because consumers disagree on precedence. */
function invalidOptionSelections(
selections: ReadonlyArray<ProviderOptionSelection>,
descriptors: ReadonlyArray<ProviderOptionDescriptor> | undefined,
): ReadonlyArray<string> {
const problems: Array<string> = [];
const seen = new Set<string>();
for (const selection of selections) {
if (seen.has(selection.id)) {
problems.push(`Option ${selection.id} was specified more than once.`);
continue;
}
seen.add(selection.id);
if (descriptors === undefined) continue;
const descriptor = descriptors.find((candidate) => candidate.id === selection.id);
if (descriptor === undefined) {
const known = descriptors.map((candidate) => candidate.id).join(", ");
problems.push(`Unknown option ${selection.id}; supported options: ${known || "none"}.`);
continue;
}
if (descriptor.type === "boolean" && typeof selection.value !== "boolean") {
problems.push(`Option ${selection.id} expects a boolean value.`);
continue;
}
if (
descriptor.type === "select" &&
!descriptor.options.some((choice) => choice.id === selection.value)
) {
const choices = descriptor.options.map((choice) => choice.id).join(", ");
problems.push(`Option ${selection.id} must be one of: ${choices}.`);
}
}
return problems;
}

function taskStatusForRun(
run: Pick<OrchestrationV2Run, "status" | "restartCancelledBackgroundWork"> | undefined,
): OrchestratorMcpDelegateTaskResult["status"] {
Expand Down
36 changes: 36 additions & 0 deletions apps/server/src/mcp/modelOptionValidation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { ProviderOptionDescriptor, ProviderOptionSelection } from "@t3tools/contracts";

/** Skip checks without descriptors; reject duplicate IDs because consumers disagree on precedence. */
export function invalidOptionSelections(
selections: ReadonlyArray<ProviderOptionSelection>,
descriptors: ReadonlyArray<ProviderOptionDescriptor> | undefined,
): ReadonlyArray<string> {
const problems: Array<string> = [];
const seen = new Set<string>();
for (const selection of selections) {
if (seen.has(selection.id)) {
problems.push(`Option ${selection.id} was specified more than once.`);
continue;
}
seen.add(selection.id);
if (descriptors === undefined) continue;
const descriptor = descriptors.find((candidate) => candidate.id === selection.id);
if (descriptor === undefined) {
const known = descriptors.map((candidate) => candidate.id).join(", ");
problems.push(`Unknown option ${selection.id}; supported options: ${known || "none"}.`);
continue;
}
if (descriptor.type === "boolean" && typeof selection.value !== "boolean") {
problems.push(`Option ${selection.id} expects a boolean value.`);
continue;
}
if (
descriptor.type === "select" &&
!descriptor.options.some((choice) => choice.id === selection.value)
) {
const choices = descriptor.options.map((choice) => choice.id).join(", ");
problems.push(`Option ${selection.id} must be one of: ${choices}.`);
}
}
return problems;
}
85 changes: 85 additions & 0 deletions apps/server/src/mcp/toolkits/project/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,91 @@ it.effect("a retried worktree launch replays after its base ref is gone", () =>
}),
);

it.effect("strict launches reject unsupported provider options before creating a thread", () =>
Effect.gen(function* () {
const launched: ThreadLaunch.ThreadLaunchInput[] = [];
const instanceId = ProviderInstanceId.make("codex");
const model = "gpt-5.6-luna";
const providers: ServerProvider[] = [
{
instanceId,
driver: ProviderDriverKind.make("codex"),
enabled: true,
installed: true,
status: "ready",
version: null,
auth: { status: "authenticated" },
checkedAt: "2026-01-01T00:00:00Z",
models: [
{
slug: model,
name: "Luna",
isCustom: false,
capabilities: {
optionDescriptors: [
{
id: "reasoningEffort",
label: "Reasoning",
type: "select",
options: [{ id: "low", label: "Low" }],
},
],
},
},
],
slashCommands: [],
skills: [],
},
];
const { projectId, dependencies } = clientLaunchHarness({
runtimeModeCeiling: "full-access",
launched,
providers,
});
const toolkit = yield* ProjectToolkit.pipe(
Effect.provide(
McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(Layer.provide(dependencies)),
),
);
const launch = (
id: string,
value: string,
strictModelOptions?: boolean,
clientRequestId?: string,
) =>
toolkit
.handle("t3_thread_launch", {
projectId,
title: "Review",
modelSelection: { instanceId, model, options: [{ id, value }] },
...(strictModelOptions === undefined ? {} : { strictModelOptions }),
...(clientRequestId === undefined ? {} : { clientRequestId }),
})
.pipe(Stream.unwrap, Stream.runCollect, Effect.provide(dependencies));

const wrongKey = yield* launch("effort", "low", true);
expect(wrongKey.at(-1)?.result).toMatchObject({
code: "invalid_request",
message: expect.stringContaining("Unknown option effort"),
});
const wrongValue = yield* launch("reasoningEffort", "high", true);
expect(wrongValue.at(-1)?.result).toMatchObject({ code: "invalid_request" });
expect(launched).toHaveLength(0);

yield* launch("effort", "low");
expect(launched[0]?.modelSelection.options).toEqual([{ id: "effort", value: "low" }]);

const accepted = yield* launch("reasoningEffort", "low", true, "strict-review");
expect(accepted.at(-1)?.result).toMatchObject({ projectId });
expect(launched[1]?.modelSelection.options).toEqual([{ id: "reasoningEffort", value: "low" }]);

providers.length = 0;
const replayed = yield* launch("reasoningEffort", "low", true, "strict-review");
expect(replayed.at(-1)?.result).toMatchObject({ projectId });
expect(launched[2]?.threadId).toBe(launched[1]?.threadId);
}),
);

it.effect("a client launches with the fallback for an exhausted default", () =>
Effect.gen(function* () {
const launched: ThreadLaunch.ThreadLaunchInput[] = [];
Expand Down
23 changes: 20 additions & 3 deletions apps/server/src/mcp/toolkits/project/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { resolveRuntimeMode } from "../../delegatedTaskModes.ts";
import * as McpInvocationContext from "../../McpInvocationContext.ts";
import * as McpToolAccess from "../../McpToolAccess.ts";
import * as OrchestrationMcp from "../../OrchestratorMcpService.ts";
import { invalidOptionSelections } from "../../modelOptionValidation.ts";
import { newCommandId, readCaller, resolveProjectId, unavailable } from "../../threadAccess.ts";
import { ProjectToolkit } from "./tools.ts";

Expand Down Expand Up @@ -247,11 +248,27 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
: runtimeMode;
if (!replaying) {
const providers = yield* (yield* ProviderRegistry.ProviderRegistry).getProviders;
const provider = providers.find(
(candidate) => candidate.instanceId === modelSelection.instanceId,
);
const options = input.modelSelection?.options;
if (input.strictModelOptions && options && options.length > 0) {
const model = provider?.models.find(
(candidate) => candidate.slug === modelSelection.model,
);
const invalid = invalidOptionSelections(
options,
model?.capabilities?.optionDescriptors ?? [],
);
if (invalid.length > 0)
return yield* new OrchestratorMcpFailure({
code: "invalid_request",
message: `Model ${modelSelection.model} rejected options: ${invalid.join(" ")} No thread was created.`,
});
}
startedRuntimeMode = yield* resolveRuntimeMode(startedRuntimeMode, input.runtimeMode, {
modelSelection,
supportedRuntimeModes: providers.find(
(provider) => provider.instanceId === modelSelection.instanceId,
)?.supportedRuntimeModes,
supportedRuntimeModes: provider?.supportedRuntimeModes,
});
}
const result = yield* ThreadMessageIntake.launchThread({
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/mcp/toolkits/project/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ const ThreadLaunchTool = Tool.make("t3_thread_launch", {
),
title: TrimmedNonEmptyString,
modelSelection: Schema.optional(ModelSelection),
strictModelOptions: Schema.optional(
Schema.Boolean.annotate({
description:
"Reject explicit model options that are not advertised for the selected model. Applies only to new launches.",
}),
),
runtimeMode: Schema.optional(RuntimeMode),
interactionMode: Schema.optional(ProviderInteractionMode),
workspaceStrategy: Schema.optional(
Expand Down
8 changes: 6 additions & 2 deletions docs/orchestration-v2/orchestrator-mcp-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,12 @@ its own under the environment's Scratch project. For stacked PRs, use the parent
`startFromOrigin: false`. The new thread may not run with broader runtime or
interaction modes than the caller. As for `delegate_task`, a runtime mode the
provider does not offer is refused, and an inherited or default one steps down
to the broadest mode it offers. Launch has no retry key, so inspect existing threads after a failed or lost response before
launching again. `create_threads` remains the batch option for a shared checkout.
to the broadest mode it offers. With `strictModelOptions: true`, explicit model
options must match the selected model's advertised option IDs and values.
An invalid option is rejected before a thread is created. Retry a failed or lost
response with the same `clientRequestId` and caller. An accepted launch replays
without revalidating its options against the current catalog.
`create_threads` remains the batch option for a shared checkout.

### `t3_thread_list`

Expand Down
Loading