The best way to control Claude Code, Codex and more from any computer or phone
fix(server): changing Claude effort no longer fails while background agents run (#19341)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 14, 2026 at 02:44 UTC
bc95bbd790580ff22bf1351edfa84231493c4ecc
4 files changed
+196
-56
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+90
-52
@@ -132,6 +132,12 @@ const CLAUDE_TEST_MODEL_SELECTION = {
132
model: "claude-sonnet-4-6",
133
options: [{ id: "effort", value: "ultrathink" }],
134
} satisfies ModelSelection;
135
+// Thinking is a launch flag, so switching to this selection needs a new process.
136
+const CLAUDE_TEST_RESTART_MODEL_SELECTION = {
137
+ ...CLAUDE_TEST_MODEL_SELECTION,
138
+ model: "claude-haiku-4-5-20251001",
139
+ options: [{ id: "thinking", value: false }],
140
+} satisfies ModelSelection;
141
const CLAUDE_TEST_RUNTIME_POLICY = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
142
runtimeMode: "full-access",
143
interactionMode: "default",
@@ -1027,6 +1033,7 @@ describe("ClaudeAdapterV2 Auto-accept edits", () => {
1033
messages: Stream.never,
1034
offer: () => Effect.void,
1035
setModel: () => Effect.void,
1036
+ applyFlagSettings: () => Effect.void,
1037
setPermissionMode: () => Effect.void,
1038
stopTask: () => Effect.void,
1039
interrupt: Effect.void,
@@ -1187,6 +1194,7 @@ const captureSdkExecutablePaths = Effect.fn("captureSdkExecutablePaths")(functio
1194
messages: Stream.never,
1195
offer: () => Effect.void,
1196
setModel: () => Effect.void,
1197
+ applyFlagSettings: () => Effect.void,
1198
setPermissionMode: () => Effect.void,
1199
stopTask: () => Effect.void,
1200
interrupt: Effect.void,
@@ -1307,6 +1315,7 @@ describe("ClaudeAdapterV2 resume compaction", () => {
1315
messages: Stream.never,
1316
offer: () => Effect.void,
1317
setModel: () => Effect.void,
1318
+ applyFlagSettings: () => Effect.void,
1319
setPermissionMode: () => Effect.void,
1320
stopTask: () => Effect.void,
1321
interrupt: Effect.void,
@@ -1533,6 +1542,7 @@ describe("ClaudeAdapterV2 attachments", () => {
1542
offeredMessages.push(message);
1543
}),
1544
setModel: () => Effect.void,
1545
+ applyFlagSettings: () => Effect.void,
1546
setPermissionMode: () => Effect.void,
1547
stopTask: () => Effect.void,
1548
interrupt: Effect.void,
@@ -1678,6 +1688,7 @@ describe("ClaudeAdapterV2 attachments", () => {
1688
messages: Stream.never,
1689
offer: () => Effect.void,
1690
setModel: () => Effect.void,
1691
+ applyFlagSettings: () => Effect.void,
1692
setPermissionMode: () => Effect.void,
1693
stopTask: () => Effect.void,
1694
interrupt: Effect.void,
@@ -1773,6 +1784,7 @@ describe("ClaudeAdapterV2 native fork", () => {
1784
messages: Stream.empty,
1785
offer: () => Effect.void,
1786
setModel: () => Effect.void,
1787
+ applyFlagSettings: () => Effect.void,
1788
setPermissionMode: () => Effect.void,
1789
stopTask: () => Effect.void,
1790
interrupt: Effect.void,
@@ -2065,6 +2077,7 @@ describe("ClaudeAdapterV2 native session identity", () => {
2077
messages: Stream.empty,
2078
offer: () => Effect.void,
2079
setModel: () => Effect.void,
2080
+ applyFlagSettings: () => Effect.void,
2081
setPermissionMode: () => Effect.void,
2082
stopTask: () => Effect.void,
2083
interrupt: Effect.void,
@@ -2356,6 +2369,8 @@ describe("ClaudeAdapterV2 background wake turns", () => {
2369
});
2370
const offeredMessages: Array<SDKUserMessage> = [];
2371
const permissionModeChanges: Array<string> = [];
2372
+ // setModel and applyFlagSettings calls on the first process, in order.
2373
+ const liveSelectionChanges: Array<unknown> = [];
2374
const continuationRequests: Array<ProviderContinuationRequests.ProviderContinuationRequest> =
2375
[];
2376
const continuationReceipts =
@@ -2403,6 +2418,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
2418
offeredMessages.push(message);
2419
}),
2420
setModel: () => Effect.void,
2421
+ applyFlagSettings: () => Effect.void,
2422
setPermissionMode: () => Effect.void,
2423
stopTask: options?.stopTask ?? (() => Effect.void),
2424
interrupt: Effect.void,
@@ -2432,7 +2448,14 @@ describe("ClaudeAdapterV2 background wake turns", () => {
2448
Effect.sync(() => {
2449
offeredMessages.push(message);
2450
}),
2435
- setModel: () => Effect.void,
2451
+ setModel: (model) =>
2452
+ Effect.sync(() => {
2453
+ liveSelectionChanges.push({ model });
2454
+ }),
2455
+ applyFlagSettings: (settings) =>
2456
+ Effect.sync(() => {
2457
+ liveSelectionChanges.push(settings);
2458
+ }),
2459
setPermissionMode: (mode) =>
2460
Effect.sync(() => {
2461
permissionModeChanges.push(mode);
@@ -2503,6 +2526,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
2526
return uuid;
2527
},
2528
permissionModeChanges,
2529
+ liveSelectionChanges,
2530
continuationRequests,
2531
continuationReceipts,
2532
events,
@@ -2627,7 +2651,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
2651
);
2652
2653
it.effect(
2630
- "reuses a background shell's query for omitted and explicit Normal, but blocks Fast",
2654
+ "applies model, effort and Fast changes to a process running a background shell, but not thinking or a cleared effort",
2655
() =>
2656
Effect.scoped(
2657
Effect.gen(function* () {
@@ -2648,41 +2672,65 @@ describe("ClaudeAdapterV2 background wake turns", () => {
2672
providerTurnOrdinal: ordinal,
2673
modelSelection,
2674
});
2675
+ const settle = Effect.gen(function* () {
2676
+ yield* harness.offerAndWait(turnOneResult);
2677
+ yield* Queue.take(harness.terminalReceipts);
2678
+ });
2679
yield* harness.runtime.startTurn(turn(1, normal));
2680
const originalOptions = harness.getOpenedOptions();
2681
yield* harness.offerAndWait(wakeTaskStarted);
2654
- yield* harness.offerAndWait(turnOneResult);
2655
- yield* Queue.take(harness.terminalReceipts);
2682
+ yield* settle;
2683
assert.isTrue(yield* harness.hasPendingBackgroundWork);
2684
2685
+ // Omitted and explicit Normal are the same selection.
2686
yield* harness.runtime.startTurn(
2659
- turn(2, {
2687
+ turn(2, { ...normal, options: [{ id: "fastMode", value: false }] }),
2688
+ );
2689
+ yield* settle;
2690
+ assert.deepEqual(harness.liveSelectionChanges, []);
2691
+
2692
+ yield* harness.runtime.startTurn(
2693
+ turn(3, {
2694
...normal,
2661
- options: [{ id: "fastMode", value: false }],
2695
+ options: [
2696
+ { id: "effort", value: "ultracode" },
2697
+ { id: "fastMode", value: true },
2698
+ ],
2699
}),
2700
);
2701
+ yield* settle;
2702
+ yield* harness.runtime.startTurn(turn(4, { ...normal, model: "claude-sonnet-4-6" }));
2703
+ yield* settle;
2704
+ assert.deepEqual(harness.liveSelectionChanges, [
2705
+ { model: "claude-opus-5-5" },
2706
+ { effortLevel: "xhigh", fastMode: true, ultracode: true },
2707
+ { model: "claude-sonnet-4-6" },
2708
+ // Sonnet's default effort; it has no Fast mode.
2709
+ { effortLevel: "high", fastMode: null, ultracode: null },
2710
+ ]);
2711
assert.strictEqual(harness.getOpenedOptions(), originalOptions);
2665
- assert.lengthOf(harness.offeredMessages, 2);
2666
- yield* harness.offerAndWait(turnOneResult);
2667
- yield* Queue.take(harness.terminalReceipts);
2668
-
2669
- const refused = yield* harness.runtime
2670
- .startTurn(
2671
- turn(3, {
2672
- ...normal,
2673
- options: [{ id: "fastMode", value: true }],
2674
- }),
2675
- )
2676
- .pipe(Effect.result);
2677
- assert.equal(refused._tag, "Failure");
2678
- if (refused._tag === "Failure") {
2679
- assert.instanceOf(
2680
- refused.failure.cause,
2681
- ClaudeAdapterV2.ClaudeBackgroundWorkBlocksQueryReplacementError,
2682
- );
2712
+ assert.lengthOf(harness.offeredMessages, 4);
2713
+
2714
+ // Thinking is a launch flag. Haiku 4.5 has no effort, and only a new
2715
+ // process reads the user's configured effort again.
2716
+ for (const [ordinal, selection] of [
2717
+ [5, CLAUDE_TEST_RESTART_MODEL_SELECTION],
2718
+ [6, { ...normal, model: "claude-haiku-4-5-20251001" }],
2719
+ ] as const) {
2720
+ const refused = yield* harness.runtime
2721
+ .startTurn(turn(ordinal, selection))
2722
+ .pipe(Effect.result);
2723
+ assert.equal(refused._tag, "Failure");
2724
+ if (refused._tag === "Failure") {
2725
+ assert.instanceOf(
2726
+ refused.failure.cause,
2727
+ ClaudeAdapterV2.ClaudeBackgroundWorkBlocksQueryReplacementError,
2728
+ );
2729
+ }
2730
}
2731
assert.strictEqual(harness.getOpenedOptions(), originalOptions);
2685
- assert.lengthOf(harness.offeredMessages, 2);
2732
+ assert.lengthOf(harness.offeredMessages, 4);
2733
+ assert.lengthOf(harness.liveSelectionChanges, 4);
2734
assert.isTrue(yield* harness.hasPendingBackgroundWork);
2735
}).pipe(
2736
Effect.provide(
@@ -4948,6 +4996,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4996
messages: Stream.fromQueue(sdkMessages),
4997
offer: () => Effect.void,
4998
setModel: () => Effect.void,
4999
+ applyFlagSettings: () => Effect.void,
5000
setPermissionMode: () => Effect.void,
5001
stopTask: () => Effect.void,
5002
interrupt: Effect.void,
@@ -5208,6 +5257,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
5257
messages: Stream.fromQueue(queue),
5258
offer: () => Effect.void,
5259
setModel: () => Effect.void,
5260
+ applyFlagSettings: () => Effect.void,
5261
setPermissionMode: () => Effect.void,
5262
stopTask: () => Effect.void,
5263
interrupt: Effect.void,
@@ -10299,6 +10349,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
10349
messages: Stream.fromQueue(sdkMessages),
10350
offer: () => Effect.void,
10351
setModel: () => Effect.void,
10352
+ applyFlagSettings: () => Effect.void,
10353
setPermissionMode: () => Effect.void,
10354
stopTask: () => Effect.void,
10355
interrupt: Effect.void,
@@ -10370,10 +10421,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
10421
);
10422
assert.isFalse(yield* hasPendingBackgroundWork);
10423
10373
- const alternateModel = {
10374
- ...CLAUDE_TEST_MODEL_SELECTION,
10375
- model: "claude-haiku-4-5-20251001",
10376
- } satisfies ModelSelection;
10424
+ const alternateModel = CLAUDE_TEST_RESTART_MODEL_SELECTION;
10425
// ProviderTurnStartService marks the thread active before startTurn;
10426
// the process-reset clear must preserve that status.
10427
const activeProviderThread = {
@@ -10489,6 +10537,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
10537
messages: Stream.fromQueue(sdkMessages),
10538
offer: () => Effect.void,
10539
setModel: () => Effect.void,
10540
+ applyFlagSettings: () => Effect.void,
10541
setPermissionMode: () => Effect.void,
10542
stopTask: () => Effect.void,
10543
interrupt: Effect.void,
@@ -10556,10 +10605,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
10605
10606
// User turn changes model, replacing the query while the wake buffer
10607
// stays queued for the later provider continuation.
10559
- const alternateModel = {
10560
- ...CLAUDE_TEST_MODEL_SELECTION,
10561
- model: "claude-haiku-4-5-20251001",
10562
- } satisfies ModelSelection;
10608
+ const alternateModel = CLAUDE_TEST_RESTART_MODEL_SELECTION;
10609
yield* runtime.startTurn(
10610
makeClaudeTestTurnInput({
10611
threadId,
@@ -10731,6 +10777,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
10777
messages: Stream.fromQueue(sdkMessages),
10778
offer: () => Effect.void,
10779
setModel: () => Effect.void,
10780
+ applyFlagSettings: () => Effect.void,
10781
setPermissionMode: () => Effect.void,
10782
stopTask: () => Effect.void,
10783
interrupt: Effect.void,
@@ -10818,10 +10865,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
10865
// Model-changing user turn replaces the query while continuation stays
10866
// queued. Process reset must not invent opaque classification for the
10867
// buffered subagent notification.
10821
- const alternateModel = {
10822
- ...CLAUDE_TEST_MODEL_SELECTION,
10823
- model: "claude-haiku-4-5-20251001",
10824
- } satisfies ModelSelection;
10868
+ const alternateModel = CLAUDE_TEST_RESTART_MODEL_SELECTION;
10869
yield* runtime.startTurn(
10870
makeClaudeTestTurnInput({
10871
threadId,
@@ -10900,7 +10944,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
10944
),
10945
);
10946
10903
- it.effect("refuses a model change that would kill a running background subagent", () =>
10947
+ it.effect("refuses a thinking change that would kill a running background subagent", () =>
10948
Effect.scoped(
10949
Effect.gen(function* () {
10950
const SUBAGENT_TASK_ID = "task-model-change-running-subagent";
@@ -10932,6 +10976,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
10976
messages: Stream.fromQueue(sdkMessages),
10977
offer: () => Effect.void,
10978
setModel: () => Effect.void,
10979
+ applyFlagSettings: () => Effect.void,
10980
setPermissionMode: () => Effect.void,
10981
stopTask: () => Effect.void,
10982
interrupt: Effect.void,
@@ -11004,12 +11049,9 @@ describe("ClaudeAdapterV2 background wake turns", () => {
11049
yield* awaitUntil(() => terminals().length === 1, "first turn terminal");
11050
const settledTurn = terminals()[0]!;
11051
11007
- // The subagent runs inside the first CLI process. Another model needs
11008
- // another process, so the turn must not start and close this one.
11009
- const alternateModel = {
11010
- ...CLAUDE_TEST_MODEL_SELECTION,
11011
- model: "claude-haiku-4-5-20251001",
11012
- } satisfies ModelSelection;
11052
+ // The subagent runs inside the first CLI process. A thinking change
11053
+ // needs another process, so the turn must not start and close this one.
11054
+ const alternateModel = CLAUDE_TEST_RESTART_MODEL_SELECTION;
11055
const switchTurn = (attempt: string) =>
11056
runtime.startTurn(
11057
makeClaudeTestTurnInput({
@@ -11115,6 +11157,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
11157
messages: Stream.fromQueue(sdkMessages),
11158
offer: () => Effect.void,
11159
setModel: () => Effect.void,
11160
+ applyFlagSettings: () => Effect.void,
11161
setPermissionMode: () => Effect.void,
11162
stopTask: () => Effect.void,
11163
interrupt: Effect.void,
@@ -11174,10 +11217,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
11217
);
11218
assert.isTrue(yield* hasPendingBackgroundWork);
11219
11177
- const alternateModel = {
11178
- ...CLAUDE_TEST_MODEL_SELECTION,
11179
- model: "claude-haiku-4-5-20251001",
11180
- } satisfies ModelSelection;
11220
+ const alternateModel = CLAUDE_TEST_RESTART_MODEL_SELECTION;
11221
const failedStart = yield* runtime
11222
.startTurn(
11223
makeClaudeTestTurnInput({
@@ -11254,6 +11294,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
11294
messages: Stream.fromQueue(sdkMessages),
11295
offer: () => Effect.void,
11296
setModel: () => Effect.void,
11297
+ applyFlagSettings: () => Effect.void,
11298
setPermissionMode: () => Effect.void,
11299
stopTask: () => Effect.void,
11300
interrupt: Effect.void,
@@ -11317,10 +11358,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
11358
yield* awaitUntil(() => continuationRequests.length === 1, "first continuation request");
11359
assert.isTrue(yield* hasPendingBackgroundWork);
11360
11320
- const alternateModel = {
11321
- ...CLAUDE_TEST_MODEL_SELECTION,
11322
- model: "claude-haiku-4-5-20251001",
11323
- } satisfies ModelSelection;
11361
+ const alternateModel = CLAUDE_TEST_RESTART_MODEL_SELECTION;
11362
const failedStart = yield* runtime
11363
.startTurn(
11364
makeClaudeTestTurnInput({
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.testkit.ts
+13
@@ -246,6 +246,12 @@ type ClaudeOutboundFrame =
246
| ClaudeQueryOpenFrame
247
| ClaudePromptOfferFrame
248
| ClaudeQuerySetModelFrame
249
+ | {
250
+ readonly type: "query.apply_flag_settings";
251
+ readonly settings: Parameters<
252
+ ClaudeAdapterV2.ClaudeAgentSdkQuerySession["applyFlagSettings"]
253
+ >[0];
254
+ }
255
| ClaudeQuerySetPermissionModeFrame
256
| ClaudeQueryInterruptFrame
257
| ClaudePermissionResponseFrame
@@ -819,6 +825,13 @@ function makeReplayQueryRunner(
825
model,
826
});
827
}),
828
+ applyFlagSettings: (settings) =>
829
+ replayEffect(() => {
830
+ assertNextOutboundFrame({
831
+ type: "query.apply_flag_settings",
832
+ settings,
833
+ });
834
+ }),
835
setPermissionMode: (mode) =>
836
replayEffect(() => {
837
assertNextOutboundFrame({
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+92
-4
@@ -18,6 +18,7 @@ import { normalizeClaudeTurnTokenUsage } from "../../provider/ClaudeTurnTokenUsa
18
import {
19
type CanUseTool,
20
forkSession as forkClaudeSession,
21
+ type EffortLevel,
22
type ForkSessionOptions,
23
type ForkSessionResult,
24
getSubagentMessages,
@@ -109,7 +110,10 @@ import { resolveAttachmentPath } from "../../attachmentStore.ts";
110
import { resolveClaudeSdkExecutablePath } from "../../provider/Drivers/ClaudeExecutable.ts";
111
import { planClaudeSkillDispatch } from "../../provider/Drivers/ClaudeSkillDispatch.ts";
112
import { discoverClaudeSkills } from "../../provider/Drivers/ClaudeSkills.ts";
112
-import { compileClaudeModelSelection } from "../../claudeModelOptions.ts";
113
+import {
114
+ compileClaudeModelSelection,
115
+ type CompiledClaudeModelSelection,
116
+} from "../../claudeModelOptions.ts";
117
import * as ServerConfig from "../../config.ts";
118
import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
119
import { signalProcessGroup } from "@t3tools/provider-core/server/processGroup";
@@ -414,6 +418,9 @@ export interface ClaudeAgentSdkQuerySession {
418
readonly messages: Stream.Stream<SDKMessage, ClaudeAgentSdkQueryRunnerError>;
419
readonly offer: (message: SDKUserMessage) => Effect.Effect<void, ClaudeAgentSdkQueryRunnerError>;
420
readonly setModel: (model: string) => Effect.Effect<void, ClaudeAgentSdkQueryRunnerError>;
421
+ readonly applyFlagSettings: (
422
+ settings: ClaudeFlagSettings,
423
+ ) => Effect.Effect<void, ClaudeAgentSdkQueryRunnerError>;
424
readonly setPermissionMode: (
425
mode: PermissionMode,
426
) => Effect.Effect<void, ClaudeAgentSdkQueryRunnerError>;
@@ -557,6 +564,14 @@ export type ClaudeAgentSdkProtocolLogEvent =
564
readonly model: string;
565
};
566
}
567
+ | {
568
+ readonly direction: "outgoing";
569
+ readonly stage: "decoded";
570
+ readonly payload: {
571
+ readonly type: "query.apply_flag_settings";
572
+ readonly settings: ClaudeFlagSettings;
573
+ };
574
+ }
575
| {
576
readonly direction: "outgoing";
577
readonly stage: "decoded";
@@ -861,6 +876,22 @@ export const layerQueryRunner: Layer.Layer<
876
}),
877
),
878
),
879
+ applyFlagSettings: (settings) =>
880
+ Effect.tryPromise({
881
+ try: () => queryRuntime.applyFlagSettings(settings),
882
+ catch: (cause) => queryRunnerError(cause, "applyFlagSettings"),
883
+ }).pipe(
884
+ Effect.tap(() =>
885
+ logProtocolEvent({
886
+ direction: "outgoing",
887
+ stage: "decoded",
888
+ payload: {
889
+ type: "query.apply_flag_settings",
890
+ settings,
891
+ },
892
+ }),
893
+ ),
894
+ ),
895
setPermissionMode: (mode) =>
896
Effect.tryPromise({
897
try: () => queryRuntime.setPermissionMode(mode),
@@ -993,6 +1024,37 @@ export const layerQueryRunner: Layer.Layer<
1024
}),
1025
);
1026
1027
+type ClaudeFlagSettings = Parameters<ClaudeQuery["applyFlagSettings"]>[0];
1028
+
1029
+/**
1030
+ * Thinking is a launch flag (`--thinking`), so only a new process can change
1031
+ * it. Clearing an explicit effort also needs one: the live reset goes to the
1032
+ * model default, while a new process reads the user's settings files.
1033
+ */
1034
+function canApplyClaudeSelectionLive(
1035
+ live: CompiledClaudeModelSelection,
1036
+ next: CompiledClaudeModelSelection,
1037
+): boolean {
1038
+ return (
1039
+ live.settings.alwaysThinkingEnabled === next.settings.alwaysThinkingEnabled &&
1040
+ (next.effort !== undefined || live.effort === undefined)
1041
+ );
1042
+}
1043
+
1044
+/**
1045
+ * Flag settings that move a live process to `selection`. `null` clears a key
1046
+ * a new process for `selection` would not set.
1047
+ */
1048
+function claudeLiveSelectionFlagSettings(
1049
+ selection: CompiledClaudeModelSelection,
1050
+): ClaudeFlagSettings {
1051
+ return {
1052
+ ...(selection.effort === undefined ? {} : { effortLevel: selection.effort as EffortLevel }),
1053
+ fastMode: selection.settings.fastMode ?? null,
1054
+ ultracode: selection.settings.ultracode ?? null,
1055
+ };
1056
+}
1057
+
1058
export function makeClaudeQueryOptions(input: {
1059
readonly modelSelection: ModelSelection;
1060
readonly nativeThreadId: string;
@@ -3027,7 +3089,8 @@ interface ClaudeLiveQueryContext {
3089
readonly nativeThreadId: string;
3090
readonly query: ClaudeAgentSdkQuerySession;
3091
readonly queryPolicyKey: string;
3030
- readonly selectionKey: string;
3092
+ // The selection this process runs now. Live changes update it.
3093
+ selection: CompiledClaudeModelSelection;
3094
readonly closed: Deferred.Deferred<void, never>;
3095
// Retained for process-exit cleanup even when its last turn failed.
3096
lastTurn: ActiveClaudeTurnContext | null;
@@ -8351,11 +8414,36 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8414
) {
8415
return existing;
8416
}
8417
+ // Model, effort, ultracode and fast mode change on the live process.
8418
+ // A restart would kill its background agents and shells.
8419
+ if (
8420
+ existing !== null &&
8421
+ existing.nativeThreadId === nativeThreadId &&
8422
+ existing.queryPolicyKey === queryPolicyKey &&
8423
+ !existing.stopping &&
8424
+ existing.selection.queryIdentity !== compiledSelection.queryIdentity &&
8425
+ canApplyClaudeSelectionLive(existing.selection, compiledSelection)
8426
+ ) {
8427
+ const live = existing;
8428
+ yield* live.query.setModel(compiledSelection.apiModelId).pipe(
8429
+ Effect.andThen(
8430
+ live.query.applyFlagSettings(claudeLiveSelectionFlagSettings(compiledSelection)),
8431
+ ),
8432
+ // A partial change leaves the process state unknown. A blank
8433
+ // identity matches no selection, so the next turn sends both again.
8434
+ Effect.tapError(() =>
8435
+ Effect.sync(() => {
8436
+ live.selection = { ...live.selection, queryIdentity: "" };
8437
+ }),
8438
+ ),
8439
+ );
8440
+ live.selection = compiledSelection;
8441
+ }
8442
if (
8443
existing !== null &&
8444
existing.nativeThreadId === nativeThreadId &&
8445
existing.queryPolicyKey === queryPolicyKey &&
8358
- existing.selectionKey === compiledSelection.queryIdentity
8446
+ existing.selection.queryIdentity === compiledSelection.queryIdentity
8447
) {
8448
// Claude can switch its own mode mid-session (EnterPlanMode), and
8449
// a denied ExitPlanMode leaves it there. Put the live process back
@@ -8482,7 +8570,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8570
nativeThreadId,
8571
query: querySession,
8572
queryPolicyKey,
8485
- selectionKey: compiledSelection.queryIdentity,
8573
+ selection: compiledSelection,
8574
closed,
8575
lastTurn: null,
8576
promptEchoMode: "unknown",
apps/server/src/orchestration-v2/ClaudeAutomaticDelivery.integration.test.ts
+1
@@ -159,6 +159,7 @@ it.effect.each(["child completion", "scheduled message", "user steering"] as con
159
}
160
}),
161
setModel: () => Effect.void,
162
+ applyFlagSettings: () => Effect.void,
163
setPermissionMode: () => Effect.void,
164
stopTask: () => Effect.void,
165
interrupt: Effect.die("automatic delivery must never interrupt"),