Skip to content

Commit e951daa

Browse files
fix(server): switch the Claude model before the steer's last turn check
Applying a steered selection after the final active-turn check let a turn that ended during setModel or applyFlagSettings still receive the steer, starting provider work the orchestrator never tracked. Apply it before the check so such a steer fails and the follow-up turn handles it. AI-assisted; verified with the tests and tools listed above.
1 parent 21fe613 commit e951daa

2 files changed

Lines changed: 65 additions & 6 deletions

File tree

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6268,6 +6268,65 @@ describe("ClaudeAdapterV2 background wake turns", () => {
62686268
),
62696269
);
62706270

6271+
it.effect("fails a model-changing steer when the turn ends during the selection change", () =>
6272+
Effect.scoped(
6273+
Effect.gen(function* () {
6274+
let duringFlags: Effect.Effect<void> = Effect.void;
6275+
const harness = yield* makeWakeHarnessWithOptions({
6276+
applyFlagSettings: () => Effect.suspend(() => duringFlags),
6277+
});
6278+
const idAllocator = yield* IdAllocator.IdAllocatorV2;
6279+
const opus = {
6280+
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
6281+
model: "claude-opus-5-5",
6282+
} satisfies ModelSelection;
6283+
const input = makeClaudeTestTurnInput({
6284+
threadId: harness.threadId,
6285+
providerThread: harness.providerThread,
6286+
now: yield* DateTime.now,
6287+
attemptId: RunAttemptId.make("attempt-steer-model-change-race"),
6288+
text: "Run the slow build.",
6289+
attachments: [],
6290+
modelSelection: opus,
6291+
});
6292+
yield* harness.runtime.startTurn(input);
6293+
duringFlags = harness
6294+
.offerAndWait(turnOneResult)
6295+
.pipe(Effect.andThen(Queue.take(harness.terminalReceipts)), Effect.asVoid);
6296+
const steer = yield* harness.runtime
6297+
.steerTurn({
6298+
threadId: harness.threadId,
6299+
runId: input.runId,
6300+
providerThread: harness.providerThread,
6301+
providerTurnId: idAllocator.derive.providerTurn({
6302+
driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
6303+
nativeTurnId: `turn:${input.attemptId}`,
6304+
}),
6305+
modelSelection: { ...opus, model: "claude-sonnet-4-6" },
6306+
message: {
6307+
createdBy: "user",
6308+
creationSource: "web",
6309+
messageId: MessageId.make("steer-model-change-race"),
6310+
text: "Which model are you?",
6311+
attachments: [],
6312+
},
6313+
})
6314+
.pipe(Effect.result);
6315+
assert.equal(steer._tag, "Failure");
6316+
assert.lengthOf(harness.offeredMessages, 1);
6317+
}).pipe(
6318+
Effect.provide(
6319+
Layer.mergeAll(
6320+
IdAllocator.layer,
6321+
McpProviderSessions.layer,
6322+
NodeServices.layer,
6323+
NodeCrypto.layer,
6324+
),
6325+
),
6326+
),
6327+
),
6328+
);
6329+
62716330
it.effect("re-sends the model on the turn after a live selection change fails", () =>
62726331
Effect.scoped(
62736332
Effect.gen(function* () {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11984,9 +11984,12 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1198411984
Effect.provideService(Path.Path, path),
1198511985
);
1198611986
yield* backgroundForegroundSubagents(existing, backgroundDeadline);
11987-
// The turn can end while the moves are answered. A steer offered
11988-
// then would start a new turn the orchestrator never asked for, so
11989-
// the steer fails and the orchestrator starts the follow-up turn.
11987+
if (liveSteerSelection !== undefined) {
11988+
yield* applySelectionLive(existing, liveSteerSelection);
11989+
}
11990+
// The turn can end while the moves or the selection change are answered.
11991+
// A steer offered then would start a new turn the orchestrator never
11992+
// asked for, so the steer fails and the orchestrator starts the follow-up turn.
1199011993
if (
1199111994
(yield* Ref.get(activeTurn))?.providerTurnId !== turnInput.providerTurnId ||
1199211995
(yield* Ref.get(queryContext)) !== existing
@@ -11996,9 +11999,6 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1199611999
detail: `Claude provider turn ${turnInput.providerTurnId} ended before the steer was sent.`,
1199712000
});
1199812001
}
11999-
if (liveSteerSelection !== undefined) {
12000-
yield* applySelectionLive(existing, liveSteerSelection);
12001-
}
1200212002
yield* Ref.update(steeredTurns, (current) => {
1200312003
const next = new Set(current);
1200412004
next.add(turnInput.providerTurnId);

0 commit comments

Comments
 (0)