Skip to content

Commit 5dc0bb4

Browse files
committed
fix(server): changing Claude effort no longer re-sends the model
The live selection switch sent setModel with the unchanged model on every effort, Fast mode or Ultracode change. That logged a model change each time and replaced the model a custom binary path chose by rewriting --model. Send setModel only for a new model, or after a failed live change. Closes #22265.
1 parent e9a5974 commit 5dc0bb4

2 files changed

Lines changed: 71 additions & 4 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
26902690
readonly close?: (sdkMessages: Queue.Queue<SDKMessage>) => Effect.Effect<void>;
26912691
readonly interrupt?: Effect.Effect<void>;
26922692
readonly setPermissionMode?: ClaudeAdapterV2.ClaudeAgentSdkQuerySession["setPermissionMode"];
2693+
readonly applyFlagSettings?: ClaudeAdapterV2.ClaudeAgentSdkQuerySession["applyFlagSettings"];
26932694
readonly stopTask?: (
26942695
taskId: string,
26952696
) => Effect.Effect<void, ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerError>;
@@ -2829,7 +2830,9 @@ describe("ClaudeAdapterV2 background wake turns", () => {
28292830
applyFlagSettings: (settings) =>
28302831
Effect.sync(() => {
28312832
liveSelectionChanges.push(settings);
2832-
}),
2833+
}).pipe(
2834+
Effect.andThen(() => options?.applyFlagSettings?.(settings) ?? Effect.void),
2835+
),
28332836
setPermissionMode: (mode) =>
28342837
Effect.sync(() => {
28352838
permissionModeChanges.push(mode);
@@ -3768,7 +3771,6 @@ describe("ClaudeAdapterV2 background wake turns", () => {
37683771
yield* harness.runtime.startTurn(turn(4, { ...normal, model: "claude-sonnet-4-6" }));
37693772
yield* settle;
37703773
assert.deepEqual(harness.liveSelectionChanges, [
3771-
{ model: "claude-opus-5-5" },
37723774
{ effortLevel: "xhigh", fastMode: true, ultracode: true },
37733775
{ model: "claude-sonnet-4-6" },
37743776
{ effortLevel: "high", fastMode: null, ultracode: null },
@@ -3793,7 +3795,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
37933795
}
37943796
assert.strictEqual(harness.getOpenedOptions(), originalOptions);
37953797
assert.lengthOf(harness.offeredMessages, 4);
3796-
assert.lengthOf(harness.liveSelectionChanges, 4);
3798+
assert.lengthOf(harness.liveSelectionChanges, 3);
37973799
assert.isTrue(yield* harness.hasPendingBackgroundWork);
37983800
}).pipe(
37993801
Effect.provide(
@@ -3803,6 +3805,64 @@ describe("ClaudeAdapterV2 background wake turns", () => {
38033805
),
38043806
);
38053807

3808+
it.effect("re-sends the model on the turn after a live selection change fails", () =>
3809+
Effect.scoped(
3810+
Effect.gen(function* () {
3811+
let failFlags = true;
3812+
const harness = yield* makeWakeHarnessWithOptions({
3813+
applyFlagSettings: () =>
3814+
Effect.suspend(() => {
3815+
if (!failFlags) return Effect.void;
3816+
failFlags = false;
3817+
return Effect.fail(
3818+
new ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerError({
3819+
method: "applyFlagSettings",
3820+
cause: new Error("control request failed"),
3821+
}),
3822+
);
3823+
}),
3824+
});
3825+
const now = yield* DateTime.now;
3826+
const opus = {
3827+
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
3828+
model: "claude-opus-5-5",
3829+
} satisfies ModelSelection;
3830+
const turn = (ordinal: number, modelSelection: ModelSelection) =>
3831+
makeClaudeTestTurnInput({
3832+
threadId: harness.threadId,
3833+
providerThread: harness.providerThread,
3834+
now,
3835+
attemptId: RunAttemptId.make(`attempt-failed-live-change:${ordinal}`),
3836+
text: `Request ${ordinal}`,
3837+
attachments: [],
3838+
providerTurnOrdinal: ordinal,
3839+
modelSelection,
3840+
});
3841+
yield* harness.runtime.startTurn(turn(1, opus));
3842+
yield* harness.offerAndWait(turnOneResult);
3843+
yield* Queue.take(harness.terminalReceipts);
3844+
3845+
const failed = yield* harness.runtime
3846+
.startTurn(turn(2, { ...opus, model: "claude-sonnet-4-6" }))
3847+
.pipe(Effect.result);
3848+
assert.equal(failed._tag, "Failure");
3849+
3850+
// The process may now run Sonnet, so returning to Opus must send it.
3851+
yield* harness.runtime.startTurn(turn(3, opus));
3852+
assert.deepEqual(harness.liveSelectionChanges, [
3853+
{ model: "claude-sonnet-4-6" },
3854+
{ effortLevel: "high", fastMode: null, ultracode: null },
3855+
{ model: "claude-opus-5-5" },
3856+
{ effortLevel: "medium", fastMode: false, ultracode: null },
3857+
]);
3858+
}).pipe(
3859+
Effect.provide(
3860+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
3861+
),
3862+
),
3863+
),
3864+
);
3865+
38063866
it.effect.each(["completed", "interrupted"] as const)(
38073867
"projects Claude thinking blocks when %s",
38083868
(status) =>

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9066,7 +9066,14 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
90669066
existing.openedPermissionMode === queryPolicy.permissionMode)
90679067
) {
90689068
const live = existing;
9069-
yield* live.query.setModel(compiledSelection.apiModelId).pipe(
9069+
// `setModel` bypasses a custom binary's `--model` rewrite, so send it only for a
9070+
// new model, or after a failed change (empty identity) left the live model unknown.
9071+
yield* (
9072+
live.selection.queryIdentity !== "" &&
9073+
live.selection.apiModelId === compiledSelection.apiModelId
9074+
? Effect.void
9075+
: live.query.setModel(compiledSelection.apiModelId)
9076+
).pipe(
90709077
Effect.andThen(
90719078
live.query.applyFlagSettings(claudeLiveSelectionFlagSettings(compiledSelection)),
90729079
),

0 commit comments

Comments
 (0)