Repository navigation
feat(server): t3_thread_send can switch the thread's model for the new turn #37714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1e2d963
8fcb685
9c12930
8f81f01
50351e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { | ||
| OrchestratorMcpCapabilitiesResult, | ||
| OrchestratorMcpFailure, | ||
| OrchestratorMcpThreadListResult, | ||
| OrchestratorMcpThreadReadResult, | ||
|
|
@@ -895,6 +896,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( | ||
|
|
@@ -904,15 +915,54 @@ const threadSendCommand = Command.make("send", { | |
| Command.withHandler((flags) => | ||
| Effect.gen(function* () { | ||
| const threadId = yield* decodeThreadId(flags.thread); | ||
| if (Option.isSome(flags.effort) && Option.isNone(flags.model)) { | ||
| return yield* new ThreadUsageError({ detail: "--effort goes with --model." }); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| 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); | ||
|
Comment on lines
+943
to
+945
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolve On an OpenCode model that advertises Resolve the effort shorthand in the send service against the selected model. Preserve
|
||
| } | ||
| // 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( | ||
| "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: effortId, value: flags.effort.value }] } | ||
| : {}), | ||
| }, | ||
| } | ||
| : {}), | ||
| }, | ||
| OrchestratorMcpThreadSendResult, | ||
| ); | ||
| if (flags.wait) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4567,6 +4567,148 @@ 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], | ||
| // 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<ThreadManagementService.ThreadManagementSendInput> = []; | ||
| const dependencies = Layer.mergeAll( | ||
| NodeServices.layer, | ||
| NodeCrypto.layer, | ||
| Layer.mock(ThreadManagementService.ThreadManagementService)({ | ||
| getThreadRecords: () => Effect.succeed(parentProjection([])), | ||
| sendToThread: (request) => | ||
| Effect.sync(() => { | ||
| sent.push(request); | ||
| return { | ||
| // The stored run carries the selection the send applied. | ||
| run: { | ||
| id: RunId.make("run:mcp-send-model"), | ||
| status: "queued", | ||
| modelSelection: storedSelection ?? request.modelSelection, | ||
| }, | ||
| 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("reports the run's stored selection when a retry replays an older send", () => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test an actual receipt replay, or narrow this test's claim. This test makes one call without a Name this case for response mapping. Extend the lowest existing test that exercises a real send receipt: commit a model-switch send, change the catalog, and retry with the same key. Assert that the retry returns the original run and creates no new run. As per path instructions, “Extend an existing case or table before adding a new test, test at the lowest layer that would fail on main, and avoid duplicating coverage across wrappers or call sites.”
|
||
| 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({ | ||
| 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", () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the test distinguish the catalog option from the driver fallback.
Both fixtures advertise the same option ID that the CLI would choose without inspecting the model. Removing the model option lookup would still pass the Claude and Codex assertions. When fixing provider coverage, extend this case with an advertised option that differs from the fallback, such as OpenCode's
variant. Keep the Codex assertion: it catches the previous hard-codedeffortvalue. (raw.githubusercontent.com)As per path instructions, “Extend an existing test or table when it fits, and test at the lowest layer that would fail on main rather than repeating cases across wrappers or call sites.”
Source: Path instructions