From 1e2d963238e75bf885d9fb713280472adb20ac6d Mon Sep 17 00:00:00 2001 From: Joshua Levine <90353749+JoshJAL@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:44:49 -0500 Subject: [PATCH 1/4] feat(server): t3_thread_send can switch the thread's model for the new turn Adds an optional modelSelection {model, options?} to t3_thread_send and `t3 thread send --model/--effort`. It never changes the provider instance. auto queues; steer and restart are refused; unknown models and efforts are rejected. The result reports what applied. --- apps/server/src/cli/thread.test.ts | 72 +++++++++++ apps/server/src/cli/thread.ts | 29 ++++- .../src/mcp/OrchestratorMcpService.test.ts | 119 ++++++++++++++++++ apps/server/src/mcp/OrchestratorMcpService.ts | 49 +++++++- .../src/provider/agentContextBudget.json | 2 +- .../orchestrator-mcp-server.md | 8 ++ docs/user/outside-agents.md | 3 + .../contracts/src/orchestratorMcp.test.ts | 21 ++++ packages/contracts/src/orchestratorMcp.ts | 30 +++++ 9 files changed, 330 insertions(+), 3 deletions(-) diff --git a/apps/server/src/cli/thread.test.ts b/apps/server/src/cli/thread.test.ts index 5252d81b2a22f..ac0aa2fe99b38 100644 --- a/apps/server/src/cli/thread.test.ts +++ b/apps/server/src/cli/thread.test.ts @@ -138,6 +138,78 @@ it.effect( ), ); +it.effect("send --model and --effort switch the thread's model with the queued message", () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const baseDir = yield* fs + .makeTempDirectoryScoped({ prefix: "t3-thread-send-model-" }) + .pipe(Effect.flatMap((directory) => fs.realPath(directory))); + yield* persistServerRuntimeState({ + path: path.join(baseDir, "userdata", "server-runtime.json"), + state: yield* makePersistedServerRuntimeState({ + config: { host: "127.0.0.1", devUrl: undefined }, + port: 3_773, + }), + }); + const sends: Array = []; + using _session = vi.spyOn(McpBridge, "mcpToolSession").mockReturnValue( + Effect.succeed({ + call: (tool, args) => { + if (tool !== "t3_thread_send") return Effect.die(`unexpected ${tool} call`); + sends.push(args); + return Effect.succeed({ + structuredContent: { + threadId, + messageId: "message-1", + runId, + status: "queued", + delivery: "queued", + }, + }); + }, + }), + ); + const run = (...args: ReadonlyArray) => + Command.runWith(threadCommand, { version: "0.0.0" })([ + "send", + threadId, + "go", + "--base-dir", + baseDir, + ...args, + ]); + + yield* run(); + yield* run("--model", "claude-sonnet-5-5", "--effort", "high"); + yield* run("--model", "claude-opus-5-5"); + + assert.deepStrictEqual(sends, [ + { threadId, message: "go", mode: "queue" }, + { + threadId, + message: "go", + mode: "queue", + modelSelection: { + model: "claude-sonnet-5-5", + options: [{ id: "effort", value: "high" }], + }, + }, + { threadId, message: "go", mode: "queue", modelSelection: { model: "claude-opus-5-5" } }, + ]); + }).pipe( + Effect.scoped, + Effect.provide( + Layer.mergeAll( + NodeServices.layer, + NodeCrypto.layer, + NetService.layer, + ConfigProvider.layer(ConfigProvider.fromEnv({ env: { T3CODE_PORT: "3773" } })), + ), + ), + ), +); + it.effect("does not sign in to whatever took over a dead server's port", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; diff --git a/apps/server/src/cli/thread.ts b/apps/server/src/cli/thread.ts index 98d18a6c9d240..5352285149aa0 100644 --- a/apps/server/src/cli/thread.ts +++ b/apps/server/src/cli/thread.ts @@ -859,6 +859,16 @@ const threadSendCommand = Command.make("send", { ...projectLocationFlags, thread: threadArgument, message: messageArgument, + model: Flag.String("model").pipe( + Flag.withDescription( + "Switch the thread to this model, on its own provider, from this message on.", + ), + Flag.optional, + ), + effort: Flag.String("effort").pipe( + Flag.withDescription("Effort for --model, such as high. Pass with --model."), + Flag.optional, + ), wait: waitFlag, json: jsonFlag, }).pipe( @@ -869,6 +879,9 @@ const threadSendCommand = Command.make("send", { Effect.gen(function* () { const threadId = yield* decodeThreadId(flags.thread); const message = yield* readMessageArgument(flags.message); + if (Option.isSome(flags.effort) && Option.isNone(flags.model)) { + return yield* new ThreadUsageError({ detail: "--effort goes with --model." }); + } yield* withThreadTools( flags, Effect.fn("cli.thread.send")(function* (tools) { @@ -876,7 +889,21 @@ const threadSendCommand = Command.make("send", { const followWakes = flags.wait ? yield* threadIsIdle(tools, threadId) : false; const sent = yield* tools.call( "t3_thread_send", - { threadId, message, mode: "queue" }, + { + threadId, + message, + mode: "queue", + ...(Option.isSome(flags.model) + ? { + modelSelection: { + model: flags.model.value, + ...(Option.isSome(flags.effort) + ? { options: [{ id: "effort", value: flags.effort.value }] } + : {}), + }, + } + : {}), + }, OrchestratorMcpThreadSendResult, ); if (flags.wait) { diff --git a/apps/server/src/mcp/OrchestratorMcpService.test.ts b/apps/server/src/mcp/OrchestratorMcpService.test.ts index f49bcc7c9412f..67bb432d9dab4 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.test.ts @@ -4443,6 +4443,125 @@ describe("OrchestratorMcpService provider resolution", () => { }), ); }); + + describe("t3_thread_send modelSelection", () => { + const provider: ServerProvider = { + ...providerSnapshot({ + instanceId: codexInstanceId, + driver: ProviderDriverKind.make("codex"), + }), + models: [ + { + slug: "gpt-6", + name: "Sol", + aliases: ["sol"], + isCustom: false, + capabilities: { + optionDescriptors: [ + { + id: "effort", + label: "Reasoning", + type: "select", + options: [ + { id: "low", label: "Low" }, + { id: "high", label: "High" }, + ], + }, + ], + }, + }, + ], + }; + + const send = ( + input: Parameters< + OrchestratorMcpService.OrchestratorMcpService["Service"]["sendToThread"] + >[1], + ) => + Effect.gen(function* () { + const sent: Array = []; + const dependencies = Layer.mergeAll( + NodeServices.layer, + NodeCrypto.layer, + Layer.mock(ThreadManagementService.ThreadManagementService)({ + getThreadRecords: () => Effect.succeed(parentProjection([])), + sendToThread: (request) => + Effect.sync(() => { + sent.push(request); + return { + run: { id: RunId.make("run:mcp-send-model"), status: "queued" }, + delivery: "queued", + } as never; + }), + }), + ServerSettings.layerTest(), + providerRegistryLayer([provider]), + adapterRegistryLayer([codexInstanceId]), + Layer.mock(ProjectService.ProjectService)({}), + Layer.mock(SecretRequests.SecretRequests)({}), + Layer.mock(RemoteDelegation.RemoteDelegation)({}), + Layer.mock(ScheduledTaskService.ScheduledTaskService)({}), + ); + const result = yield* Effect.gen(function* () { + const service = yield* OrchestratorMcpService.OrchestratorMcpService; + return yield* service.sendToThread(scope, input).pipe(Effect.result); + }).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(dependencies)))); + return { result, sent }; + }); + + it.effect("queues a switch on the thread's own provider and reports what applied", () => + Effect.gen(function* () { + const { result, sent } = yield* send({ + threadId: parentThreadId, + message: "continue", + modelSelection: { model: "sol", options: [{ id: "effort", value: "high" }] }, + }); + assert.isTrue(result._tag === "Success"); + const expected = { model: "gpt-6", options: [{ id: "effort", value: "high" }] }; + assert.deepEqual(sent[0]?.modelSelection, { instanceId: codexInstanceId, ...expected }); + assert.equal(sent[0]?.mode, "queue"); + if (result._tag === "Success") assert.deepEqual(result.success.modelSelection, expected); + }), + ); + + it.effect.each(["steer", "restart"] as const)("refuses a switch with mode %s", (mode) => + Effect.gen(function* () { + const { result, sent } = yield* send({ + threadId: parentThreadId, + message: "continue", + mode, + modelSelection: { model: "gpt-6" }, + }); + assert.isTrue(result._tag === "Failure" && result.failure.code === "invalid_request"); + assert.deepEqual(sent, []); + }), + ); + + it.effect.each([ + { + name: "an unknown model", + model: "gpt-nope", + options: undefined, + code: "model_unavailable", + }, + { + name: "an unknown effort", + model: "gpt-6", + options: [{ id: "effort", value: "max" }], + code: "invalid_request", + }, + ] as const)("refuses $name and sends nothing", ({ model, options, code }) => + Effect.gen(function* () { + const { result, sent } = yield* send({ + threadId: parentThreadId, + message: "continue", + modelSelection: { model, ...(options === undefined ? {} : { options }) }, + }); + assert.isTrue(result._tag === "Failure" && result.failure.code === code); + assert.deepEqual(sent, []); + }), + ); + }); }); describe("OrchestratorMcpService thread lookup", () => { diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index d1bae5d859d65..00d427ff85201 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -3406,7 +3406,43 @@ const make = Effect.gen(function* () { yield* assertLiveCallerForOtherThread(scope, parent, target); yield* assertTargetWithinLimits(limits, target.thread); - const mode = input.mode ?? "auto"; + if ( + input.modelSelection !== undefined && + (input.mode === "steer" || input.mode === "restart") + ) { + return yield* failure( + "invalid_request", + `modelSelection needs a send that starts or queues a turn, not mode:'${input.mode}'.`, + ); + } + // A switch cannot join a running turn, so `auto` queues instead of steering. + const mode = + input.modelSelection !== undefined && (input.mode ?? "auto") === "auto" + ? "queue" + : (input.mode ?? "auto"); + const providers = input.modelSelection === undefined ? [] : yield* loadProviders; + const switchedTo = + input.modelSelection === undefined + ? undefined + : (yield* resolveTargetRechecking({ + parent: target, + target: input.modelSelection, + providers, + })).modelSelection; + const switchedProvider = providers.find( + (provider) => provider.instanceId === switchedTo?.instanceId, + ); + // A model given as an alias is stored under its slug, as the picker would store it. + const switchedSelection = + switchedTo === undefined + ? undefined + : { + ...switchedTo, + model: + (switchedProvider === undefined + ? undefined + : advertisedModel(switchedProvider, switchedTo.model)?.slug) ?? switchedTo.model, + }; const key = yield* requestKey(input.clientRequestId); const messageId = stableOperationMessageId({ scope, @@ -3432,6 +3468,7 @@ const make = Effect.gen(function* () { attachments: [], mode, ...(input.freshContext ? { freshContext: true } : {}), + ...(switchedSelection === undefined ? {} : { modelSelection: switchedSelection }), createdBy: "agent", creationSource: "mcp", }) @@ -3453,6 +3490,16 @@ const make = Effect.gen(function* () { ...(result.run.delegatedTaskId === undefined ? {} : { taskId: result.run.delegatedTaskId }), status: result.run.status, delivery: result.delivery, + ...(switchedSelection === undefined + ? {} + : { + modelSelection: { + model: switchedSelection.model, + ...(switchedSelection.options === undefined + ? {} + : { options: switchedSelection.options }), + }, + }), } satisfies OrchestratorMcpThreadSendResult; }), waitForThread: Effect.fn("OrchestratorMcpService.waitForThread")(function* (scope, input) { diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 0051813371e5b..bb1d17e7f48f2 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 5930, "codexAdditionalContextBytes": 7324, - "mcpToolListJsonBytes": 49736 + "mcpToolListJsonBytes": 50312 } diff --git a/docs/orchestration-v2/orchestrator-mcp-server.md b/docs/orchestration-v2/orchestrator-mcp-server.md index fa2770bb10cf7..e0aee8879a74f 100644 --- a/docs/orchestration-v2/orchestrator-mcp-server.md +++ b/docs/orchestration-v2/orchestrator-mcp-server.md @@ -446,6 +446,14 @@ The target runtime and interaction modes may not be broader than the caller's. Stable command and message IDs are derived from `clientRequestId` for idempotent retries. +`modelSelection` (`model`, optional `options`) switches the thread's model from +the new turn on, like the model picker. It names no provider instance, so a send +never moves a thread to another provider. It starts or queues a turn: `auto` +queues, and `steer` or `restart` are rejected. The model and options are +validated against the thread's provider; an alias is stored as its slug. The +thread takes the selection when the queued run starts, and later messages follow +it. The result's `modelSelection` is what applied. + ### `t3_thread_wait` Waits for a selected run to become `completed`, `failed`, `cancelled`, diff --git a/docs/user/outside-agents.md b/docs/user/outside-agents.md index 84d00cc98b16c..9394b8fcd315d 100644 --- a/docs/user/outside-agents.md +++ b/docs/user/outside-agents.md @@ -143,6 +143,7 @@ without a sign-in: ```sh id=$(t3 thread start . "Find why the tests are slow") t3 thread send "$id" "Now fix it" --wait +t3 thread send "$id" "Review it" --model gpt-6 --effort high t3 thread show "$id" t3 thread list ``` @@ -152,6 +153,8 @@ its repository; a project id also works. A new thread uses the project's default model and permission mode, and runs in the project folder unless you pass `--worktree `. `send` never interrupts: a busy thread gets the message as its next turn. Pass `-` as the message to read it from stdin. +`--model` (and `--effort`) switch the thread to that model of its own provider +from this message on. `--wait` prints the agent's reply. It exits 1 when the run fails or stops, and 2 when the agent waits for an answer you give in the app. Add `--json` for a diff --git a/packages/contracts/src/orchestratorMcp.test.ts b/packages/contracts/src/orchestratorMcp.test.ts index d2908fa42db8c..12b8520f67709 100644 --- a/packages/contracts/src/orchestratorMcp.test.ts +++ b/packages/contracts/src/orchestratorMcp.test.ts @@ -4,14 +4,35 @@ import * as Schema from "effect/Schema"; import { OrchestratorMcpDelegateTaskInput, OrchestratorMcpDelegateTaskResult, + OrchestratorMcpThreadSendInput, OrchestratorMcpThreadWaitResult, } from "./orchestratorMcp.ts"; const decodeDelegateTaskInput = Schema.decodeUnknownSync(OrchestratorMcpDelegateTaskInput); const decodeDelegateTaskResult = Schema.decodeUnknownSync(OrchestratorMcpDelegateTaskResult); +const decodeThreadSendInput = Schema.decodeUnknownSync(OrchestratorMcpThreadSendInput); const decodeThreadWaitResult = Schema.decodeUnknownSync(OrchestratorMcpThreadWaitResult); describe("orchestrator MCP contracts", () => { + it("decodes a send's model switch from the record or the array options form", () => { + const base = { threadId: "thread-1", message: "go", mode: "queue" } as const; + const fromRecord = decodeThreadSendInput({ + ...base, + modelSelection: { model: "claude-opus-5-5", options: { effort: "high" } }, + }); + const fromArray = decodeThreadSendInput({ + ...base, + modelSelection: { model: "claude-opus-5-5", options: [{ id: "effort", value: "high" }] }, + }); + expect(fromRecord.modelSelection).toEqual({ + model: "claude-opus-5-5", + options: [{ id: "effort", value: "high" }], + }); + expect(fromArray).toEqual(fromRecord); + expect(decodeThreadSendInput(base).modelSelection).toBeUndefined(); + expect(() => decodeThreadSendInput({ ...base, modelSelection: {} })).toThrow(); + }); + it("decodes cross-provider delegated task requests and durable results", () => { const request = decodeDelegateTaskInput({ task: "Inspect the workspace and report the result.", diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index ed6a62bf1eb7f..751694a7792a7 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -547,6 +547,23 @@ export const OrchestratorMcpThreadReadResult = Schema.Struct({ }); export type OrchestratorMcpThreadReadResult = typeof OrchestratorMcpThreadReadResult.Type; +/** + * A model switch for a send. It names no provider instance: the target thread's own + * instance is used, so a send never moves a thread to another provider. + */ +export const OrchestratorMcpThreadSendModelSelection = Schema.Struct({ + model: TrimmedNonEmptyString.annotate({ + description: "Slug or alias on the thread's provider.", + }), + options: Schema.optional( + OrchestratorMcpTargetOptions.annotate({ + description: "Such as {effort:'high'}. Overrides the thread's current ones. [] clears.", + }), + ), +}); +export type OrchestratorMcpThreadSendModelSelection = + typeof OrchestratorMcpThreadSendModelSelection.Type; + export const OrchestratorMcpThreadSendInput = Schema.Struct({ environmentId: OrchestratorMcpEnvironmentTarget, threadId: ThreadId, @@ -558,6 +575,12 @@ export const OrchestratorMcpThreadSendInput = Schema.Struct({ "Start a new provider session without the thread's earlier context, like /clear. Never steers.", }), ), + modelSelection: Schema.optional( + OrchestratorMcpThreadSendModelSelection.annotate({ + description: + "Switch the thread's model from the new turn on. `auto` queues; `steer` and `restart` are refused.", + }), + ), clientRequestId: Schema.optional(OrchestratorMcpClientRequestId), }); export type OrchestratorMcpThreadSendInput = typeof OrchestratorMcpThreadSendInput.Type; @@ -570,6 +593,13 @@ export const OrchestratorMcpThreadSendResult = Schema.Struct({ taskId: Schema.optional(NodeId), status: OrchestrationV2RunStatus, delivery: Schema.Literals(["started", "queued", "steered", "restarted"]), + /** Present when the send asked for a model switch: the model and options that applied. */ + modelSelection: Schema.optional( + Schema.Struct({ + model: Schema.String, + options: Schema.optional(Schema.Array(ProviderOptionSelection)), + }), + ), }); export type OrchestratorMcpThreadSendResult = typeof OrchestratorMcpThreadSendResult.Type; From 8fcb6853f2b6a6ccd984689582c833c3175d691d Mon Sep 17 00:00:00 2001 From: Joshua Levine <90353749+JoshJAL@users.noreply.github.com> Date: Mon, 16 Nov 2026 14:35:01 -0500 Subject: [PATCH 2/4] fix(mcp): report the stored model selection and resolve aliases from the refreshed catalog --- .../src/mcp/OrchestratorMcpService.test.ts | 7 ++++++- apps/server/src/mcp/OrchestratorMcpService.ts | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/apps/server/src/mcp/OrchestratorMcpService.test.ts b/apps/server/src/mcp/OrchestratorMcpService.test.ts index 67bb432d9dab4..9cf63ad2309e2 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.test.ts @@ -4489,7 +4489,12 @@ describe("OrchestratorMcpService provider resolution", () => { Effect.sync(() => { sent.push(request); return { - run: { id: RunId.make("run:mcp-send-model"), status: "queued" }, + // The stored run carries the selection the send applied. + run: { + id: RunId.make("run:mcp-send-model"), + status: "queued", + modelSelection: request.modelSelection, + }, delivery: "queued", } as never; }), diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index 00d427ff85201..a28ca7fc420a0 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -3429,9 +3429,14 @@ const make = Effect.gen(function* () { target: input.modelSelection, providers, })).modelSelection; - const switchedProvider = providers.find( - (provider) => provider.instanceId === switchedTo?.instanceId, - ); + // Look the alias up in the catalog that accepted it: resolveTargetRechecking may have + // refreshed the instance, so the list loaded above can be stale. + const switchedProvider = + switchedTo === undefined + ? undefined + : (yield* loadProviders).find( + (provider) => provider.instanceId === switchedTo.instanceId, + ); // A model given as an alias is stored under its slug, as the picker would store it. const switchedSelection = switchedTo === undefined @@ -3493,11 +3498,12 @@ const make = Effect.gen(function* () { ...(switchedSelection === undefined ? {} : { + // Report what the run stored, not what was requested. modelSelection: { - model: switchedSelection.model, - ...(switchedSelection.options === undefined + model: result.run.modelSelection.model, + ...(result.run.modelSelection.options === undefined ? {} - : { options: switchedSelection.options }), + : { options: result.run.modelSelection.options }), }, }), } satisfies OrchestratorMcpThreadSendResult; From 9c12930011b1e1d6f462c02eeb6d6b8f371d970a Mon Sep 17 00:00:00 2001 From: Joshua Levine <90353749+JoshJAL@users.noreply.github.com> Date: Mon, 16 Nov 2026 14:47:43 -0500 Subject: [PATCH 3/4] test(mcp): cover the replayed-send selection report --- .../src/mcp/OrchestratorMcpService.test.ts | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/server/src/mcp/OrchestratorMcpService.test.ts b/apps/server/src/mcp/OrchestratorMcpService.test.ts index 9cf63ad2309e2..9fdb2468ed15f 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.test.ts @@ -4477,6 +4477,8 @@ describe("OrchestratorMcpService provider resolution", () => { input: Parameters< OrchestratorMcpService.OrchestratorMcpService["Service"]["sendToThread"] >[1], + // What a replayed receipt's run kept, when it differs from this request. + storedSelection?: { model: string; options?: ReadonlyArray<{ id: string; value: string }> }, ) => Effect.gen(function* () { const sent: Array = []; @@ -4493,7 +4495,7 @@ describe("OrchestratorMcpService provider resolution", () => { run: { id: RunId.make("run:mcp-send-model"), status: "queued", - modelSelection: request.modelSelection, + modelSelection: storedSelection ?? request.modelSelection, }, delivery: "queued", } as never; @@ -4529,6 +4531,22 @@ describe("OrchestratorMcpService provider resolution", () => { }), ); + it.effect("reports the run's stored selection when a retry replays an older send", () => + Effect.gen(function* () { + const stored = { model: "gpt-6", options: [{ id: "effort", value: "low" }] }; + const { result } = yield* send( + { + threadId: parentThreadId, + message: "continue", + modelSelection: { model: "gpt-6", options: [{ id: "effort", value: "high" }] }, + }, + stored, + ); + assert.isTrue(result._tag === "Success"); + if (result._tag === "Success") assert.deepEqual(result.success.modelSelection, stored); + }), + ); + it.effect.each(["steer", "restart"] as const)("refuses a switch with mode %s", (mode) => Effect.gen(function* () { const { result, sent } = yield* send({ From 50351e5fa107743e7e994ee4e2bd064fd3db139c Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Wed, 18 Nov 2026 13:34:24 +0000 Subject: [PATCH 4/4] fix(cli): use provider effort option for thread sends --- apps/server/src/cli/thread.test.ts | 57 ++++++++++++++++++++++++++++++ apps/server/src/cli/thread.ts | 27 ++++++++++++-- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/apps/server/src/cli/thread.test.ts b/apps/server/src/cli/thread.test.ts index ad361ddab2801..2cc487265ab73 100644 --- a/apps/server/src/cli/thread.test.ts +++ b/apps/server/src/cli/thread.test.ts @@ -158,6 +158,53 @@ it.effect("send --model and --effort switch the thread's model with the queued m using _session = vi.spyOn(McpBridge, "mcpToolSession").mockReturnValue( Effect.succeed({ call: (tool, args) => { + if (tool === "t3_thread_read") { + return Effect.succeed({ + structuredContent: { thread: { providerInstanceId: "provider" } }, + }); + } + if (tool === "orchestrator_capabilities") { + return Effect.succeed({ + structuredContent: { + parentThreadId: null, + inheritedProviderInstanceId: null, + inheritedModel: null, + runtimeMode: "full-access", + interactionMode: "default", + providers: [ + { + providerInstanceId: "provider", + driverKind: args.search === "gpt-6.1-sol" ? "codex" : "claudeAgent", + displayName: null, + models: [ + { + id: args.search, + options: [ + { + id: args.search === "gpt-6.1-sol" ? "reasoningEffort" : "effort", + values: ["high"], + }, + ], + }, + ], + canRunChildTask: true, + canRunCrossProviderChildTask: true, + constraints: [], + }, + ], + features: { + appOwnedSubagents: true, + asyncPolling: true, + cancellation: true, + batchThreadCreation: true, + threadManagement: true, + incrementalThreadRead: true, + scheduledTasks: true, + maxBatchThreads: 10, + }, + }, + }); + } if (tool !== "t3_thread_send") return Effect.die(`unexpected ${tool} call`); sends.push(args); return Effect.succeed({ @@ -185,6 +232,7 @@ it.effect("send --model and --effort switch the thread's model with the queued m yield* run(); yield* run("--model", "claude-sonnet-5-5", "--effort", "high"); yield* run("--model", "claude-opus-5-5"); + yield* run("--model", "gpt-6.1-sol", "--effort", "high"); assert.deepStrictEqual(sends, [ { threadId, message: "go", mode: "queue" }, @@ -198,6 +246,15 @@ it.effect("send --model and --effort switch the thread's model with the queued m }, }, { threadId, message: "go", mode: "queue", modelSelection: { model: "claude-opus-5-5" } }, + { + threadId, + message: "go", + mode: "queue", + modelSelection: { + model: "gpt-6.1-sol", + options: [{ id: "reasoningEffort", value: "high" }], + }, + }, ]); }).pipe( Effect.scoped, diff --git a/apps/server/src/cli/thread.ts b/apps/server/src/cli/thread.ts index beaf305ef5314..ba6c2eef471f6 100644 --- a/apps/server/src/cli/thread.ts +++ b/apps/server/src/cli/thread.ts @@ -1,4 +1,5 @@ import { + OrchestratorMcpCapabilitiesResult, OrchestratorMcpFailure, OrchestratorMcpThreadListResult, OrchestratorMcpThreadReadResult, @@ -914,13 +915,35 @@ const threadSendCommand = Command.make("send", { Command.withHandler((flags) => Effect.gen(function* () { const threadId = yield* decodeThreadId(flags.thread); - const message = yield* readMessageArgument(flags.message); if (Option.isSome(flags.effort) && Option.isNone(flags.model)) { return yield* new ThreadUsageError({ detail: "--effort goes with --model." }); } + const message = yield* readMessageArgument(flags.message); yield* withThreadTools( flags, Effect.fn("cli.thread.send")(function* (tools) { + let effortId = "effort"; + if (Option.isSome(flags.effort) && Option.isSome(flags.model)) { + const requestedModel = flags.model.value; + const { thread } = yield* tools.call( + "t3_thread_read", + { threadId, limit: 1, runLimit: 1 }, + Schema.Struct({ thread: Schema.Struct({ providerInstanceId: Schema.String }) }), + ); + const capabilities = yield* tools.call( + "orchestrator_capabilities", + { search: requestedModel }, + OrchestratorMcpCapabilitiesResult, + ); + const provider = capabilities.providers.find( + (provider) => provider.providerInstanceId === thread.providerInstanceId, + ); + const model = provider?.models.find((model) => model.id === requestedModel); + effortId = + model?.options?.find( + (option) => option.id === "effort" || option.id === "reasoningEffort", + )?.id ?? (provider?.driverKind === "codex" ? "reasoningEffort" : effortId); + } // Work already running when this is sent is not this message's to wait for. const followWakes = flags.wait ? yield* threadIsIdle(tools, threadId) : false; const sent = yield* tools.call( @@ -934,7 +957,7 @@ const threadSendCommand = Command.make("send", { modelSelection: { model: flags.model.value, ...(Option.isSome(flags.effort) - ? { options: [{ id: "effort", value: flags.effort.value }] } + ? { options: [{ id: effortId, value: flags.effort.value }] } : {}), }, }