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, 13:30 UTC
fix(server): switching the Claude model no longer blocks a later provider switch (#34498)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Dmitry Farafonov committed
Nov 14, 2026 at 20:15 UTC
3eadb214e837f80cbfd48426b09595877de043ad
2 files changed
+82
-1
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+71
-1
@@ -3453,6 +3453,10 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3453
readonly close?: (sdkMessages: Queue.Queue<SDKMessage>) => Effect.Effect<void>;
3454
readonly interrupt?: Effect.Effect<void, ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerError>;
3455
readonly setPermissionMode?: ClaudeAdapterV2.ClaudeAgentSdkQuerySession["setPermissionMode"];
3456
+ readonly setModel?: (
3457
+ model: string,
3458
+ offerAndWait: (message: SDKMessage) => Effect.Effect<void>,
3459
+ ) => Effect.Effect<void>;
3460
readonly renameSession?: ClaudeAdapterV2.ClaudeAgentSdkQuerySession["renameSession"];
3461
readonly applyFlagSettings?: ClaudeAdapterV2.ClaudeAgentSdkQuerySession["applyFlagSettings"];
3462
readonly stopTask?: (
@@ -3622,7 +3626,9 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3626
setModel: (model) =>
3627
Effect.sync(() => {
3628
liveSelectionChanges.push({ model });
3625
- }),
3629
+ }).pipe(
3630
+ Effect.andThen(() => options?.setModel?.(model, offerAndWait) ?? Effect.void),
3631
+ ),
3632
applyFlagSettings: (settings) =>
3633
Effect.sync(() => {
3634
liveSelectionChanges.push(settings);
@@ -16758,6 +16764,70 @@ describe("ClaudeAdapterV2 background wake turns", () => {
16764
),
16765
);
16766
16767
+ it.effect("does not count the echo of a live model switch as background work", () =>
16768
+ Effect.gen(function* () {
16769
+ const idleUserFrame = (uuid: string, content: string, isReplay: boolean) =>
16770
+ claudeSdkFrame({
16771
+ type: "user",
16772
+ message: { role: "user", content },
16773
+ parent_tool_use_id: null,
16774
+ ...(isReplay ? { isReplay } : {}),
16775
+ uuid,
16776
+ session_id: WAKE_NATIVE_SESSION,
16777
+ });
16778
+ // As the CLI does, answer setModel with its echo before the next turn attaches.
16779
+ const harness = yield* makeWakeHarnessWithOptions({
16780
+ setModel: (model, offerAndWait) =>
16781
+ offerAndWait(
16782
+ idleUserFrame(
16783
+ "00000000-0000-4000-8000-000000000b01",
16784
+ `<local-command-stdout>Set model to \`${model}\`</local-command-stdout>`,
16785
+ true,
16786
+ ),
16787
+ ),
16788
+ });
16789
+ const now = yield* DateTime.now;
16790
+ const turn = (ordinal: number, model: string) =>
16791
+ makeClaudeTestTurnInput({
16792
+ threadId: harness.threadId,
16793
+ providerThread: harness.providerThread,
16794
+ now,
16795
+ attemptId: RunAttemptId.make(`attempt-claude-model-switch-echo:${ordinal}`),
16796
+ text: `Request ${ordinal}`,
16797
+ attachments: [],
16798
+ providerTurnOrdinal: ordinal,
16799
+ modelSelection: { instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID, model },
16800
+ });
16801
+ const settle = Effect.gen(function* () {
16802
+ yield* harness.offerAndWait(turnOneResult);
16803
+ yield* Queue.take(harness.terminalReceipts);
16804
+ });
16805
+ yield* harness.runtime.startTurn(turn(1, "claude-opus-5-5"));
16806
+ yield* settle;
16807
+ yield* harness.runtime.startTurn(turn(2, "claude-sonnet-4-6"));
16808
+ yield* settle;
16809
+
16810
+ assert.deepInclude(harness.liveSelectionChanges, { model: "claude-sonnet-4-6" });
16811
+ assert.lengthOf(harness.continuationRequests, 0);
16812
+ assert.isFalse(yield* harness.hasPendingBackgroundWork);
16813
+
16814
+ // A root user frame the CLI produced on its own still marks a wake.
16815
+ yield* harness.offerAndWait(
16816
+ idleUserFrame("00000000-0000-4000-8000-000000000b02", "A background task finished.", false),
16817
+ );
16818
+ assert.isTrue(yield* harness.hasPendingBackgroundWork);
16819
+ }).pipe(
16820
+ Effect.provide(
16821
+ Layer.mergeAll(
16822
+ IdAllocator.layer,
16823
+ McpProviderSessions.layer,
16824
+ NodeServices.layer,
16825
+ NodeCrypto.layer,
16826
+ ),
16827
+ ),
16828
+ ),
16829
+ );
16830
+
16831
it.effect(
16832
"emits one interrupted terminal for a positive task-notification result racing interrupt",
16833
() =>
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+11
@@ -3675,6 +3675,14 @@ const CLAUDE_SCHEDULED_WAKEUP_TASK: OrchestrationV2PendingBackgroundTask = {
3675
// most 60 s before the minute-rounded scheduledFor it reports; the rest is slack.
3676
const CLAUDE_SCHEDULED_WAKEUP_EARLY_FIRE_MARGIN_MS = 120_000;
3677
3678
+// The CLI answers a control request such as setModel with a replayed local-command user frame.
3679
+// It belongs to no turn, so on an idle session it is not the start of a wake.
3680
+function isClaudeLocalCommandEcho(message: SDKMessage): boolean {
3681
+ if (message.type !== "user" || !("isReplay" in message) || !message.isReplay) return false;
3682
+ const content = message.message.content;
3683
+ return typeof content === "string" && content.startsWith("<local-command-stdout>");
3684
+}
3685
+
3686
function claudePendingBackgroundTasksFromRoster(
3687
roster: ReadonlyMap<string, OrchestrationV2PendingBackgroundTask>,
3688
awaitedTaskIds: ReadonlySet<string>,
@@ -10362,6 +10370,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10370
(yield* Ref.get(activeTurn)) ??
10371
(yield* settledTurnForSubagentFrame(liveQuery.nativeThreadId, message));
10372
if (context === null) {
10373
+ if (isClaudeLocalCommandEcho(message)) {
10374
+ return;
10375
+ }
10376
yield* applyWorkflowProgressWithoutTurn(message);
10377
// Buffer wake evidence before clearing the task from the roster.
10378
if (message.type === "system" && message.subtype === "task_notification") {