@@ -48,6 +48,7 @@ import {
4848 type OrchestrationV2ProviderThread,
4949 type OrchestrationV2ProviderTurn,
5050 type OrchestrationV2RemoteTaskChild,
51+ type OrchestrationV2ModelSwitch,
5152 type OrchestrationV2Run,
5253 type OrchestrationV2RunAttempt,
5354 type OrchestrationV2ThreadShell,
@@ -75,6 +76,7 @@ import {
7576 managedRuntimeModeCeilingMessage,
7677} from "@t3tools/contracts";
7778import { modelSelectionsEqual } from "@t3tools/shared/model";
79+ import { modelSwitchSince } from "./modelSwitch.ts";
7880import { recordThreadOpen } from "@t3tools/shared/paletteSearch";
7981import {
8082 backgroundWorkHoldsCompletion,
@@ -2055,6 +2057,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
20552057 startedAt: now,
20562058 completedAt: now,
20572059 updatedAt: now,
2060+ ...(activeHandoff === null ? modelSwitchSince(projection, queuedRun.modelSelection) : {}),
20582061 };
20592062 const handoffTurnItem: OrchestrationV2TurnItem | null =
20602063 activeHandoff === null
@@ -4796,6 +4799,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
47964799 readonly providerTurnId: typeof providerTurn.id | null;
47974800 readonly providerThreadId: OrchestrationV2ProviderThread["id"];
47984801 readonly providerInstanceId: ProviderInstanceId;
4802+ readonly modelSwitch?: OrchestrationV2ModelSwitch | undefined;
47994803 }) {
48004804 const message: OrchestrationV2ConversationMessage = {
48014805 createdBy: input.createdBy,
@@ -4851,6 +4855,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
48514855 text: input.text,
48524856 attachments: input.attachments,
48534857 ...(input.context ? { context: input.context } : {}),
4858+ ...(messageInput.modelSwitch === undefined
4859+ ? {}
4860+ : { modelSwitch: messageInput.modelSwitch }),
48544861 };
48554862 yield* emitEvent({
48564863 type: "message.updated",
@@ -5311,6 +5318,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
53115318 providerTurnId: null,
53125319 providerThreadId: restartProviderThread.id,
53135320 providerInstanceId: input.modelSelection.instanceId,
5321+ // Measured on the pre-restart projection, so the rewritten run is not its own baseline.
5322+ ...(restartHandoff === null ? modelSwitchSince(input.projection, input.modelSelection) : {}),
53145323 });
53155324 const interruptedAttemptId = targetRun.activeAttemptId;
53165325 if (interruptedAttemptId === null) {
@@ -6424,6 +6433,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
64246433 text: dispatchText,
64256434 ...(command.context ? { context: command.context } : {}),
64266435 attachments: command.attachments,
6436+ ...(run.contextHandoffId === null ? modelSwitchSince(projection, modelSelection) : {}),
64276437 };
64286438 const preparationTurnItem: OrchestrationV2TurnItem | null =
64296439 dispatchMode.type === "defer_start"
@@ -7175,6 +7185,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
71757185 text: dispatchText,
71767186 ...(command.context ? { context: command.context } : {}),
71777187 attachments: command.attachments,
7188+ ...(run.contextHandoffId === null
7189+ ? modelSwitchSince(projection, modelSelection, sourceRun?.modelSelection)
7190+ : {}),
71787191 };
71797192 const activeHandoff = portableForkHandoff ?? mergeBackHandoff ?? providerSwitchHandoff;
71807193 const handoffSourceRuns =
@@ -9349,7 +9362,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
93499362 "runtimeRequests",
93509363 "subagents",
93519364 ],
9352- { turnItemTypes: [], messageRoles: ["user"] },
9365+ // User messages measure a restart's model switch.
9366+ { turnItemTypes: ["user_message"], messageRoles: ["user"] },
93539367 );
93549368 if (projection.thread.archivedAt !== null || projection.thread.deletedAt !== null) {
93559369 return yield* new OrchestratorDispatchError({
0 commit comments