Skip to content
TypeScript

fix(server): side chats no longer open with a model switch from the parent's turn (#29752)

Alex Southwell55ea365a8f16
diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts
index 600764704e5..59b708f5ba1 100644
--- a/apps/server/src/orchestration-v2/Orchestrator.ts
+++ b/apps/server/src/orchestration-v2/Orchestrator.ts
@@ -7274,7 +7274,12 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
...(command.context ? { context: command.context } : {}),
attachments: command.attachments,
...(run.contextHandoffId === null
- ? modelSwitchSince(projection, modelSelection, sourceRun?.modelSelection)
+ ? modelSwitchSince(
+ projection,
+ modelSelection,
+ // Side chats do not show the parent's runs.
+ sideChatFork ? undefined : sourceRun?.modelSelection,
+ )
: {}),
};
const activeHandoff = portableForkHandoff ?? mergeBackHandoff ?? providerSwitchHandoff;
diff --git a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts
index 96c7263173f..d955755e921 100644
--- a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts
+++ b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts
@@ -852,7 +852,11 @@ const forkSideChat = (commandId: string, sourceThreadId: ThreadId, targetThreadI
});
});
-const askSideChat = (threadId: ThreadId, commandId: string) =>
+const askSideChat = (
+ threadId: ThreadId,
+ commandId: string,
+ modelSelection?: (typeof forkCases)[number]["modelSelection"],
+) =>
Effect.gen(function* () {
const orchestrator = yield* Orchestrator.OrchestratorV2;
yield* orchestrator.dispatch({
@@ -862,6 +866,7 @@ const askSideChat = (threadId: ThreadId, commandId: string) =>
messageId: MessageId.make(commandId),
text: "What is the main thread doing?",
attachments: [],
+ ...(modelSelection === undefined ? {} : { modelSelection }),
dispatchMode: { type: "start_immediately" },
createdBy: "user",
creationSource: "web",
@@ -954,10 +959,17 @@ it.effect("a side chat of an idle parent still starts with the framing note", ()
query.includes("FROM orchestration_v2_projection_context_transfers"),
),
);
- yield* askSideChat(sideChatId, "side-chat-idle-first-message");
+ yield* askSideChat(sideChatId, "side-chat-idle-first-message", {
+ ...forkCases[0]!.modelSelection,
+ model: "side-chat-model",
+ });
const started = yield* orchestrator.getThreadProjection(sideChatId);
assert.isNotNull(started.providerThreads[0]?.forkedFrom);
+ // The side chat does not show the parent's run, so it is no baseline.
+ assert.isFalse(
+ started.turnItems.some((item) => item.type === "user_message" && item.modelSwitch),
+ );
assert.lengthOf(started.contextHandoffs, 1);
const [handoff] = started.contextHandoffs;
assert.isTrue(