@devries-cameron20 / t3code Mirror · read-only / commits / 5984bbb36e
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, 22:15 UTC

fix(server): a model change sent with a Claude steer now applies to the running turn (#34564)

Julius Marminge committed Nov 11, 2026 at 14:39 UTC 5984bbb36ebc16c49c5a7b1f534827879eaeba8e
9 files changed +160 -12
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+114
@@ -6361,6 +6361,120 @@ describe("ClaudeAdapterV2 background wake turns", () => {
6361 ),
6362 );
6363
6364 + // regression: #34549 a model change sent with a steer was shown but never applied to the turn.
6365 + it.effect("applies a model change sent with a steer to the running turn", () =>
6366 + Effect.scoped(
6367 + Effect.gen(function* () {
6368 + const harness = yield* makeWakeHarness;
6369 + const idAllocator = yield* IdAllocator.IdAllocatorV2;
6370 + const opus = {
6371 + instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
6372 + model: "claude-opus-5-5",
6373 + } satisfies ModelSelection;
6374 + const input = makeClaudeTestTurnInput({
6375 + threadId: harness.threadId,
6376 + providerThread: harness.providerThread,
6377 + now: yield* DateTime.now,
6378 + attemptId: RunAttemptId.make("attempt-steer-model-change"),
6379 + text: "Run the slow build.",
6380 + attachments: [],
6381 + modelSelection: opus,
6382 + });
6383 + yield* harness.runtime.startTurn(input);
6384 + yield* harness.runtime.steerTurn({
6385 + threadId: harness.threadId,
6386 + runId: input.runId,
6387 + providerThread: harness.providerThread,
6388 + providerTurnId: idAllocator.derive.providerTurn({
6389 + driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
6390 + nativeTurnId: `turn:${input.attemptId}`,
6391 + }),
6392 + modelSelection: { ...opus, model: "claude-sonnet-4-6" },
6393 + message: {
6394 + createdBy: "user",
6395 + creationSource: "web",
6396 + messageId: MessageId.make("steer-model-change"),
6397 + text: "Which model are you?",
6398 + attachments: [],
6399 + },
6400 + });
6401 + assert.deepEqual(harness.liveSelectionChanges, [
6402 + { model: "claude-sonnet-4-6" },
6403 + { effortLevel: "high", fastMode: null, ultracode: null },
6404 + ]);
6405 + assert.lengthOf(harness.offeredMessages, 2);
6406 + }).pipe(
6407 + Effect.provide(
6408 + Layer.mergeAll(
6409 + IdAllocator.layer,
6410 + McpProviderSessions.layer,
6411 + NodeServices.layer,
6412 + NodeCrypto.layer,
6413 + ),
6414 + ),
6415 + ),
6416 + ),
6417 + );
6418 +
6419 + it.effect("fails a model-changing steer when the turn ends during the selection change", () =>
6420 + Effect.scoped(
6421 + Effect.gen(function* () {
6422 + let duringFlags: Effect.Effect<void> = Effect.void;
6423 + const harness = yield* makeWakeHarnessWithOptions({
6424 + applyFlagSettings: () => Effect.suspend(() => duringFlags),
6425 + });
6426 + const idAllocator = yield* IdAllocator.IdAllocatorV2;
6427 + const opus = {
6428 + instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
6429 + model: "claude-opus-5-5",
6430 + } satisfies ModelSelection;
6431 + const input = makeClaudeTestTurnInput({
6432 + threadId: harness.threadId,
6433 + providerThread: harness.providerThread,
6434 + now: yield* DateTime.now,
6435 + attemptId: RunAttemptId.make("attempt-steer-model-change-race"),
6436 + text: "Run the slow build.",
6437 + attachments: [],
6438 + modelSelection: opus,
6439 + });
6440 + yield* harness.runtime.startTurn(input);
6441 + duringFlags = harness
6442 + .offerAndWait(turnOneResult)
6443 + .pipe(Effect.andThen(Queue.take(harness.terminalReceipts)), Effect.asVoid);
6444 + const steer = yield* harness.runtime
6445 + .steerTurn({
6446 + threadId: harness.threadId,
6447 + runId: input.runId,
6448 + providerThread: harness.providerThread,
6449 + providerTurnId: idAllocator.derive.providerTurn({
6450 + driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
6451 + nativeTurnId: `turn:${input.attemptId}`,
6452 + }),
6453 + modelSelection: { ...opus, model: "claude-sonnet-4-6" },
6454 + message: {
6455 + createdBy: "user",
6456 + creationSource: "web",
6457 + messageId: MessageId.make("steer-model-change-race"),
6458 + text: "Which model are you?",
6459 + attachments: [],
6460 + },
6461 + })
6462 + .pipe(Effect.result);
6463 + assert.equal(steer._tag, "Failure");
6464 + assert.lengthOf(harness.offeredMessages, 1);
6465 + }).pipe(
6466 + Effect.provide(
6467 + Layer.mergeAll(
6468 + IdAllocator.layer,
6469 + McpProviderSessions.layer,
6470 + NodeServices.layer,
6471 + NodeCrypto.layer,
6472 + ),
6473 + ),
6474 + ),
6475 + ),
6476 + );
6477 +
6478 it.effect("re-sends the model on the turn after a live selection change fails", () =>
6479 Effect.scoped(
6480 Effect.gen(function* () {
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+23 -5
@@ -12018,11 +12018,26 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
12018 }),
12019 persistAttachmentBudget(existing.nativeThreadId),
12020 );
12021 + // A selection sent with the steer applies to the running turn when the live process can switch to it.
12022 + const steerSelection =
12023 + turnInput.modelSelection === undefined
12024 + ? undefined
12025 + : compileClaudeModelSelection(turnInput.modelSelection, modelCatalog);
12026 + const liveSteerSelection =
12027 + steerSelection !== undefined &&
12028 + existing.selection.queryIdentity !== steerSelection.queryIdentity &&
12029 + canApplyClaudeSelectionLive(existing.selection, steerSelection) &&
12030 + (existing.selection.apiModelId === steerSelection.apiModelId ||
12031 + existing.openedPermissionMode === currentTurn.queryPolicy.permissionMode)
12032 + ? steerSelection
12033 + : undefined;
12034 const userMessage = yield* makeClaudeUserMessageWithAttachments({
12035 text: applyClaudePromptEffortPrefix(
12036 turnInput.message.text,
12024 - compileClaudeModelSelection(currentTurn.input.modelSelection, modelCatalog)
12025 - .promptEffort,
12037 + (
12038 + liveSteerSelection ??
12039 + compileClaudeModelSelection(currentTurn.input.modelSelection, modelCatalog)
12040 + ).promptEffort,
12041 ),
12042 attachments: turnInput.message.attachments,
12043 priority: "now",
@@ -12036,9 +12051,12 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
12051 Effect.provideService(Path.Path, path),
12052 );
12053 yield* backgroundForegroundSubagents(existing, backgroundDeadline);
12039 - // The turn can end while the moves are answered. A steer offered
12040 - // then would start a new turn the orchestrator never asked for, so
12041 - // the steer fails and the orchestrator starts the follow-up turn.
12054 + if (liveSteerSelection !== undefined) {
12055 + yield* applySelectionLive(existing, liveSteerSelection);
12056 + }
12057 + // The turn can end while the moves or the selection change are answered.
12058 + // A steer offered then would start a new turn the orchestrator never
12059 + // asked for, so the steer fails and the orchestrator starts the follow-up turn.
12060 if (
12061 (yield* Ref.get(activeTurn))?.providerTurnId !== turnInput.providerTurnId ||
12062 (yield* Ref.get(queryContext)) !== existing ||
apps/server/src/orchestration-v2/EffectOutbox.ts
+1
@@ -64,6 +64,7 @@ export const OrchestrationEffectRequestV2 = Schema.Union([
64 providerThreadId: ProviderThreadId,
65 providerTurnId: ProviderTurnId,
66 messageId: MessageId,
67 + modelSelection: Schema.optional(ModelSelection),
68 }),
69 Schema.Struct({
70 type: Schema.Literal("provider-turn.restart"),
apps/server/src/orchestration-v2/EffectWorker.ts
+3
@@ -257,6 +257,9 @@ export const layerExecutor: Layer.Layer<
257 providerThreadId: effect.request.providerThreadId,
258 providerTurnId: effect.request.providerTurnId,
259 messageId: effect.request.messageId,
260 + ...(effect.request.modelSelection === undefined
261 + ? {}
262 + : { modelSelection: effect.request.modelSelection }),
263 })
264 .pipe(
265 Effect.tap(() =>
apps/server/src/orchestration-v2/Orchestrator.ts
+5 -2
@@ -5611,9 +5611,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5611 if (steeringPolicy === "active_steering") {
5612 const instanceChanged =
5613 input.projection.thread.providerInstanceId !== input.modelSelection.instanceId;
5614 + // Only a user's steer carries the picker's selection; the adapter applies it to the live turn.
5615 + const steerCarriesSelection =
5616 + input.delegatedCompletion === undefined && input.notification === undefined;
5617 if (
5615 - input.delegatedCompletion === undefined &&
5616 - input.notification === undefined &&
5618 + steerCarriesSelection &&
5619 (instanceChanged ||
5620 !modelSelectionsEqual(input.projection.thread.modelSelection, input.modelSelection))
5621 ) {
@@ -5649,6 +5651,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5651 providerThreadId: providerThread.id,
5652 providerTurnId: providerTurn.id,
5653 messageId: input.messageId,
5654 + ...(steerCarriesSelection ? { modelSelection: input.modelSelection } : {}),
5655 },
5656 } satisfies PendingOrchestrationEffectV2,
5657 ]);
apps/server/src/orchestration-v2/ProviderTurnControlService.ts
+4
@@ -68,6 +68,7 @@ export interface ProviderTurnControlServiceV2Shape {
68 readonly providerThreadId: ProviderThreadId;
69 readonly providerTurnId: ProviderTurnId;
70 readonly messageId: MessageId;
71 + readonly modelSelection?: ModelSelection;
72 }) => Effect.Effect<void, ProviderTurnControlError>;
73 /** Best effort: a turn that ended or moved sessions picks the selection up when it next starts. */
74 readonly applyModelSelection: (input: {
@@ -405,6 +406,9 @@ export const layer: Layer.Layer<
406 runId: run.id,
407 providerThread: loaded.providerThread,
408 providerTurnId: loaded.providerTurn.id,
409 + ...(input.modelSelection === undefined
410 + ? {}
411 + : { modelSelection: input.modelSelection }),
412 message: {
413 messageId: message.id,
414 text: projectComposerContextForProvider({
apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts
+7 -5
@@ -499,6 +499,7 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
499 const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
500 const started: ProviderAdapter.ProviderAdapterV2TurnInput[] = [];
501 const steered: string[] = [];
502 + const steeredSelections: Array<ModelSelection | undefined> = [];
503 const interrupted: ProviderTurnId[] = [];
504 const capabilities = {
505 ...CodexProviderCapabilitiesV2,
@@ -587,6 +588,7 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
588 steerTurn: (turn) =>
589 Effect.sync(() => {
590 steered.push(turn.message.text);
591 + steeredSelections.push(turn.modelSelection);
592 }),
593 interruptTurn: ({ providerTurnId }) =>
594 Effect.sync(() => {
@@ -658,7 +660,7 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
660 yield* Fiber.join(running);
661 return threadId;
662 });
661 - return { cwd, events, started, steered, interrupted, layer, startFirstTurn };
663 + return { cwd, events, started, steered, steeredSelections, interrupted, layer, startFirstTurn };
664 });
665
666 it.effect.each([
@@ -1189,10 +1191,8 @@ it.effect(
1191 () =>
1192 Effect.scoped(
1193 Effect.gen(function* () {
1192 - const { started, steered, layer, startFirstTurn } = yield* nextTurnSelectionHarness(
1193 - "steering-selection-change",
1194 - true,
1195 - );
1194 + const { started, steered, steeredSelections, layer, startFirstTurn } =
1195 + yield* nextTurnSelectionHarness("steering-selection-change", true);
1196 yield* Effect.gen(function* () {
1197 const orchestrator = yield* Orchestrator.OrchestratorV2;
1198 const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
@@ -1252,6 +1252,8 @@ it.effect(
1252 yield* steer("steer-back", runSelection);
1253 const back = yield* orchestrator.getThreadProjection(threadId);
1254 assert.deepEqual(steered, ["steer-changed", "steer-reverted", "steer-back"]);
1255 + // The adapter gets each steer's selection so it can switch the live turn, and back.
1256 + assert.deepEqual(steeredSelections, [composerSelection, runSelection, runSelection]);
1257 assert.equal(back.thread.providerInstanceId, instanceId);
1258 assert.deepEqual(back.thread.modelSelection, runSelection);
1259 }).pipe(Effect.provide(layer));
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+1
@@ -1520,6 +1520,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive", (it) => {
1520 providerThreadId: providerThread.id,
1521 providerTurnId: providerTurn.id,
1522 messageId: steerMessageId,
1523 + modelSelection: run.modelSelection,
1524 },
1525 ],
1526 );
packages/provider-core/src/server/ProviderAdapter.ts
+2
@@ -521,6 +521,8 @@ export interface ProviderAdapterV2SteerInput {
521 readonly providerThread: OrchestrationV2ProviderThread;
522 readonly providerTurnId: ProviderTurnId;
523 readonly message: ProviderAdapterV2TurnMessage;
524 + /** The selection sent with the message when it differs from the running turn's. */
525 + readonly modelSelection?: ModelSelection;
526 }
527
528 export interface ProviderAdapterV2InterruptInput {