The best way to control Claude Code, Codex and more from any computer or phone
feat(chat): threads show when you switch models or effort (#28995)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Nov 1, 2026 at 21:53 UTC
c65f8d552baca1b51e15b5fb4737f07e18cce177
15 files changed
+483
-6
apps/mobile/src/features/threads/ThreadFeed.tsx
+15
-1
@@ -15,7 +15,11 @@ import {
15
enrichedSkillReference,
16
} from "../../lib/enrichedLinkPresentation";
17
import { ThreadContextDivider } from "./thread-context-divider";
18
-import { ThreadHandoffDivider, ThreadHandoffRow } from "./thread-handoff-row";
18
+import {
19
+ ThreadHandoffDivider,
20
+ ThreadHandoffRow,
21
+ ThreadModelSwitchDivider,
22
+} from "./thread-handoff-row";
23
import { GuestBubbleTint, GuestMessageName } from "./guestMessageStyle";
24
import { ThreadGuestPendingMessage, useThreadGuestShare } from "./ThreadGuestShareBar";
25
import { LinkRequestCard } from "./LinkRequestCard";
@@ -3590,6 +3594,16 @@ export const ThreadFeed = memo(function ThreadFeed({
3594
workspaceRoot={props.workspaceRoot}
3595
>
3596
<ThreadMediaVisibility>
3597
+ {info.item.type === "message" &&
3598
+ !isCompactionCommandFeedEntry(info.item) &&
3599
+ info.item.message.projectedItem?.item.type === "user_message" &&
3600
+ info.item.message.projectedItem.item.modelSwitch ? (
3601
+ <ThreadModelSwitchDivider
3602
+ environmentId={props.environmentId}
3603
+ modelSwitch={info.item.message.projectedItem.item.modelSwitch}
3604
+ iconColor={iconSubtleColor}
3605
+ />
3606
+ ) : null}
3607
{renderFeedEntry(info, {
3608
userMessageGrouping: info.item.userMessageGrouping,
3609
environmentId: props.environmentId,
apps/mobile/src/features/threads/thread-context-divider.tsx
+4
-2
@@ -6,7 +6,7 @@ import { ShimmeringWorkContent } from "./thread-work-log";
6
7
export function ThreadContextDivider(props: {
8
label: string;
9
- icon: AppSymbolName;
9
+ icon?: AppSymbolName;
10
iconColor: ColorValue;
11
active?: boolean;
12
failed?: boolean;
@@ -16,7 +16,9 @@ export function ThreadContextDivider(props: {
16
<View className="mb-3 flex-row items-center gap-3 px-1 py-1">
17
<View className="h-px min-w-2 flex-1 bg-separator" />
18
<View className="shrink flex-row flex-wrap items-center justify-center gap-1.5">
19
- <SymbolView name={props.icon} size={12} tintColor={props.iconColor} type="monochrome" />
19
+ {props.icon ? (
20
+ <SymbolView name={props.icon} size={12} tintColor={props.iconColor} type="monochrome" />
21
+ ) : null}
22
{props.active ? (
23
<ShimmeringWorkContent
24
className="flex-none"
apps/mobile/src/features/threads/thread-handoff-row.tsx
+34
-1
@@ -1,7 +1,11 @@
1
import * as Dialog from "../../components/ui/Dialog";
2
import { useAtomValue } from "@effect/atom-react";
3
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
4
-import { resolveHandoffEndpoints, type HandoffEndpoints } from "@t3tools/client-runtime/handoff";
4
+import {
5
+ resolveHandoffEndpoints,
6
+ resolveModelSwitchChange,
7
+ type HandoffEndpoints,
8
+} from "@t3tools/client-runtime/handoff";
9
import { resolveModelShortName } from "@t3tools/client-runtime/provider-clients";
10
import {
11
normalizeProviderAccentColor,
@@ -10,6 +14,8 @@ import {
14
} from "@t3tools/client-runtime/state/provider-instance-display";
15
import type {
16
EnvironmentId,
17
+ ModelSelection,
18
+ OrchestrationV2ModelSwitch,
19
OrchestrationV2ProjectedTurnItem,
20
ProviderInstanceId,
21
ServerProvider,
@@ -45,6 +51,33 @@ function handoffEndpointsAtom(
51
});
52
}
53
54
+/** A same-harness model or effort change. Shows only what changed. */
55
+export function ThreadModelSwitchDivider(props: {
56
+ environmentId: EnvironmentId;
57
+ modelSwitch: OrchestrationV2ModelSwitch;
58
+ iconColor: ColorValue;
59
+}) {
60
+ const providers = useAtomValue(serverEnvironment.providersValueAtom(props.environmentId)) ?? [];
61
+ const change = resolveModelSwitchChange(props.modelSwitch, providers);
62
+ if (change === null) return null;
63
+ const describe = (selection: ModelSelection, effort: string | undefined) => {
64
+ const provider = providers.find((candidate) => candidate.instanceId === selection.instanceId);
65
+ const model = provider?.models.find((candidate) => candidate.slug === selection.model);
66
+ const modelName =
67
+ (model ? resolveModelShortName(model, provider?.driver) : undefined) ??
68
+ model?.name ??
69
+ selection.model;
70
+ return [change.modelChanged ? modelName : null, effort].filter(Boolean).join(" ");
71
+ };
72
+ const { from, to } = props.modelSwitch;
73
+ return (
74
+ <ThreadContextDivider
75
+ label={`${describe(from, change.effort?.from)} → ${describe(to, change.effort?.to)}`}
76
+ iconColor={props.iconColor}
77
+ />
78
+ );
79
+}
80
+
81
export function ThreadHandoffRow(props: {
82
environmentId: EnvironmentId;
83
projectedItem: OrchestrationV2ProjectedTurnItem;
apps/mobile/src/lib/filePreview.test.ts
+1
-1
@@ -269,7 +269,7 @@ vi.mock("./openExternalUrl", () => ({}));
269
vi.mock("./attachmentDownload", () => ({}));
270
vi.mock("./uuid", () => ({}));
271
vi.mock("../features/threads/thread-context-divider", () => ({}));
272
-vi.mock("../features/threads/thread-handoff-row", () => ({}));
272
+vi.mock("../features/threads/thread-handoff-row", () => ({ ThreadModelSwitchDivider: () => null }));
273
vi.mock("../features/threads/ThreadGuestShareBar", () => ({ useThreadGuestShare: () => null }));
274
vi.mock("../features/threads/SecretRequestCard", () => ({}));
275
vi.mock("../features/threads/LinkRequestCard", () => ({ LinkRequestCard: () => null }));
apps/server/src/orchestration-v2/Orchestrator.ts
+15
-1
@@ -48,6 +48,7 @@ import {
48
type OrchestrationV2ProviderThread,
49
type OrchestrationV2ProviderTurn,
50
type OrchestrationV2RemoteTaskChild,
51
+ type OrchestrationV2ModelSwitch,
52
type OrchestrationV2Run,
53
type OrchestrationV2RunAttempt,
54
type OrchestrationV2ThreadShell,
@@ -75,6 +76,7 @@ import {
76
managedRuntimeModeCeilingMessage,
77
} from "@t3tools/contracts";
78
import { modelSelectionsEqual } from "@t3tools/shared/model";
79
+import { modelSwitchSince } from "./modelSwitch.ts";
80
import { recordThreadOpen } from "@t3tools/shared/paletteSearch";
81
import {
82
backgroundWorkHoldsCompletion,
@@ -2055,6 +2057,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
2057
startedAt: now,
2058
completedAt: now,
2059
updatedAt: now,
2060
+ ...(activeHandoff === null ? modelSwitchSince(projection, queuedRun.modelSelection) : {}),
2061
};
2062
const handoffTurnItem: OrchestrationV2TurnItem | null =
2063
activeHandoff === null
@@ -4796,6 +4799,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
4799
readonly providerTurnId: typeof providerTurn.id | null;
4800
readonly providerThreadId: OrchestrationV2ProviderThread["id"];
4801
readonly providerInstanceId: ProviderInstanceId;
4802
+ readonly modelSwitch?: OrchestrationV2ModelSwitch | undefined;
4803
}) {
4804
const message: OrchestrationV2ConversationMessage = {
4805
createdBy: input.createdBy,
@@ -4851,6 +4855,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
4855
text: input.text,
4856
attachments: input.attachments,
4857
...(input.context ? { context: input.context } : {}),
4858
+ ...(messageInput.modelSwitch === undefined
4859
+ ? {}
4860
+ : { modelSwitch: messageInput.modelSwitch }),
4861
};
4862
yield* emitEvent({
4863
type: "message.updated",
@@ -5311,6 +5318,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5318
providerTurnId: null,
5319
providerThreadId: restartProviderThread.id,
5320
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) : {}),
5323
});
5324
const interruptedAttemptId = targetRun.activeAttemptId;
5325
if (interruptedAttemptId === null) {
@@ -6424,6 +6433,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6433
text: dispatchText,
6434
...(command.context ? { context: command.context } : {}),
6435
attachments: command.attachments,
6436
+ ...(run.contextHandoffId === null ? modelSwitchSince(projection, modelSelection) : {}),
6437
};
6438
const preparationTurnItem: OrchestrationV2TurnItem | null =
6439
dispatchMode.type === "defer_start"
@@ -7175,6 +7185,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
7185
text: dispatchText,
7186
...(command.context ? { context: command.context } : {}),
7187
attachments: command.attachments,
7188
+ ...(run.contextHandoffId === null
7189
+ ? modelSwitchSince(projection, modelSelection, sourceRun?.modelSelection)
7190
+ : {}),
7191
};
7192
const activeHandoff = portableForkHandoff ?? mergeBackHandoff ?? providerSwitchHandoff;
7193
const handoffSourceRuns =
@@ -9349,7 +9362,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
9362
"runtimeRequests",
9363
"subagents",
9364
],
9352
- { turnItemTypes: [], messageRoles: ["user"] },
9365
+ // User messages measure a restart's model switch.
9366
+ { turnItemTypes: ["user_message"], messageRoles: ["user"] },
9367
);
9368
if (projection.thread.archivedAt !== null || projection.thread.deletedAt !== null) {
9369
return yield* new OrchestratorDispatchError({
apps/server/src/orchestration-v2/SelectionRestart.integration.test.ts
+11
@@ -5,6 +5,7 @@ import {
5
MessageId,
6
type ModelSelection,
7
type OrchestrationV2ProviderCapabilities,
8
+ type OrchestrationV2ThreadProjection,
9
type OrchestrationV2ProviderSession,
10
type OrchestrationV2ProviderThread,
11
ProjectId,
@@ -47,6 +48,10 @@ const seedSelection = {
48
instanceId: providerInstanceId,
49
model: "seed-model",
50
} satisfies ModelSelection;
51
+const modelSwitches = (projection: OrchestrationV2ThreadProjection) =>
52
+ projection.turnItems.flatMap((item) =>
53
+ item.type === "user_message" && item.modelSwitch !== undefined ? [item.modelSwitch] : [],
54
+ );
55
const pooledCapabilities: OrchestrationV2ProviderCapabilities = CodexProviderCapabilitiesV2;
56
const exclusiveCapabilities: OrchestrationV2ProviderCapabilities = {
57
...CodexProviderCapabilitiesV2,
@@ -407,6 +412,9 @@ it.live("retries a failed selection restart session open before completing", ()
412
"selection restart supersede must not project hard-Stop interrupt items",
413
);
414
assert.equal(projection.runs.at(-1)?.modelSelection.model, replacementSelection.model);
415
+ assert.deepEqual(modelSwitches(projection), [
416
+ { from: initialSelection, to: replacementSelection },
417
+ ]);
418
assert.equal(projection.runs.at(-1)?.status, "completed");
419
assert.isTrue(captured.failedReplacementOpen);
420
assert.equal(captured.closedSessionCount, 0);
@@ -690,6 +698,9 @@ it.live(
698
const { projection, captured } = result;
699
assert.lengthOf(projection.runs, 2);
700
assert.equal(projection.runs[1]?.modelSelection.model, replacementSelection.model);
701
+ assert.deepEqual(modelSwitches(projection), [
702
+ { from: seedSelection, to: replacementSelection },
703
+ ]);
704
assert.deepEqual(result.detachedSessionIds, [result.liveSessionId]);
705
assert.equal(captured.closedSessionCount, 1);
706
assert.deepEqual(
apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts
+49
@@ -1175,6 +1175,55 @@ it.effect("steers a promoted queued message with the selection it was queued wit
1175
),
1176
);
1177
1178
+it.effect("marks the model switch on a promoted message that restarts the turn", () =>
1179
+ Effect.scoped(
1180
+ Effect.gen(function* () {
1181
+ const { started, layer, startFirstTurn } = yield* nextTurnSelectionHarness(
1182
+ "promote-restart-switch",
1183
+ true,
1184
+ false,
1185
+ );
1186
+ const otherSelection = { ...runSelection, model: "other-model" };
1187
+ yield* Effect.gen(function* () {
1188
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
1189
+ const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
1190
+ const threadId = yield* startFirstTurn;
1191
+ yield* orchestrator.dispatch({
1192
+ type: "message.dispatch",
1193
+ commandId: CommandId.make("queued"),
1194
+ threadId,
1195
+ messageId: MessageId.make("message:queued"),
1196
+ text: "queued",
1197
+ attachments: [],
1198
+ modelSelection: otherSelection,
1199
+ dispatchMode: { type: "queue_after_active" },
1200
+ createdBy: "user",
1201
+ creationSource: "web",
1202
+ });
1203
+ const queuedRun = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
1204
+ (run) => run.status === "queued",
1205
+ )!;
1206
+ yield* orchestrator.dispatch({
1207
+ type: "queued-message.promote-to-steer",
1208
+ commandId: CommandId.make("promote"),
1209
+ threadId,
1210
+ queuedRunId: queuedRun.id,
1211
+ targetRunId: started[0]!.runId,
1212
+ });
1213
+ yield* worker.drain();
1214
+
1215
+ const promoted = (yield* orchestrator.getThreadProjection(threadId)).turnItems.find(
1216
+ (item) => item.type === "user_message" && item.messageId === "message:queued",
1217
+ );
1218
+ assert.deepEqual(promoted?.type === "user_message" ? promoted.modelSwitch : undefined, {
1219
+ from: runSelection,
1220
+ to: otherSelection,
1221
+ });
1222
+ }).pipe(Effect.provide(layer));
1223
+ }),
1224
+ ),
1225
+);
1226
+
1227
it.effect("keeps a queued message queued when promoted into a run that Stop reached", () =>
1228
Effect.scoped(
1229
Effect.gen(function* () {
apps/server/src/orchestration-v2/modelSwitch.test.ts
new
+107
@@ -0,0 +1,107 @@
1
+import {
2
+ ContextHandoffId,
3
+ MessageId,
4
+ ProviderInstanceId,
5
+ type OrchestrationV2ThreadProjection,
6
+} from "@t3tools/contracts";
7
+import { describe, expect, it } from "vite-plus/test";
8
+
9
+import { modelSwitchSince } from "./modelSwitch.ts";
10
+
11
+const instanceId = ProviderInstanceId.make("codex");
12
+const selection = (model: string) => ({ instanceId, model });
13
+const run = (
14
+ message: string,
15
+ ordinal: number,
16
+ model: string,
17
+ status: OrchestrationV2ThreadProjection["runs"][number]["status"] = "completed",
18
+) =>
19
+ ({
20
+ ordinal,
21
+ status,
22
+ completedAt: null,
23
+ contextHandoffId: null,
24
+ userMessageId: MessageId.make(message),
25
+ modelSelection: selection(model),
26
+ }) as OrchestrationV2ThreadProjection["runs"][number];
27
+const shown = (...messages: ReadonlyArray<string>) =>
28
+ messages.map((message) => ({
29
+ type: "user_message",
30
+ messageId: MessageId.make(message),
31
+ inputIntent: "turn_start",
32
+ status: "completed",
33
+ text: message,
34
+ attachments: [],
35
+ })) as unknown as OrchestrationV2ThreadProjection["turnItems"];
36
+
37
+describe("modelSwitchSince", () => {
38
+ it("measures from the latest run whose message is in the timeline", () => {
39
+ // B failed before it started; its message shows "a -> b", so the next one must show "b -> a".
40
+ expect(
41
+ modelSwitchSince(
42
+ {
43
+ runs: [
44
+ run("first", 1, "a"),
45
+ run("failed", 2, "b", "failed"),
46
+ run("queued", 3, "c", "queued"),
47
+ run("undone", 4, "d", "rolled_back"),
48
+ ],
49
+ turnItems: shown("first", "failed", "queued", "undone"),
50
+ },
51
+ selection("a"),
52
+ ),
53
+ ).toEqual({ modelSwitch: { from: selection("b"), to: selection("a") } });
54
+ });
55
+
56
+ it("skips messages clients hide", () => {
57
+ const [first, pending, compact, answer] = shown(
58
+ "first",
59
+ "pending",
60
+ "/compact",
61
+ "async-answer:question",
62
+ );
63
+ expect(
64
+ modelSwitchSince(
65
+ {
66
+ runs: [
67
+ run("first", 1, "a"),
68
+ run("pending", 2, "b", "cancelled"),
69
+ run("/compact", 3, "c"),
70
+ run("async-answer:question", 4, "d"),
71
+ ],
72
+ turnItems: [
73
+ first!,
74
+ { ...pending!, inputIntent: "queued_turn", status: "pending" },
75
+ compact!,
76
+ answer!,
77
+ ] as OrchestrationV2ThreadProjection["turnItems"],
78
+ },
79
+ selection("c"),
80
+ ),
81
+ ).toEqual({ modelSwitch: { from: selection("a"), to: selection("c") } });
82
+ });
83
+
84
+ it("counts a wake whose handoff row shows the swap", () => {
85
+ const wake = {
86
+ ...run("wake", 2, "other"),
87
+ contextHandoffId: ContextHandoffId.make("handoff"),
88
+ };
89
+ expect(
90
+ modelSwitchSince(
91
+ { runs: [run("first", 1, "a"), wake], turnItems: shown("first") },
92
+ selection("other"),
93
+ ),
94
+ ).toEqual({});
95
+ });
96
+
97
+ it("records nothing for a first run or an unchanged selection", () => {
98
+ expect(modelSwitchSince({ runs: [], turnItems: [] }, selection("a"))).toEqual({});
99
+ // A fork's first message compares with the run it forked from.
100
+ expect(modelSwitchSince({ runs: [], turnItems: [] }, selection("a"), selection("b"))).toEqual({
101
+ modelSwitch: { from: selection("b"), to: selection("a") },
102
+ });
103
+ expect(
104
+ modelSwitchSince({ runs: [run("first", 1, "a")], turnItems: shown("first") }, selection("a")),
105
+ ).toEqual({});
106
+ });
107
+});
apps/server/src/orchestration-v2/modelSwitch.ts
new
+42
@@ -0,0 +1,42 @@
1
+import {
2
+ isCompactionCommandMessage,
3
+ type ModelSelection,
4
+ type OrchestrationV2ThreadProjection,
5
+ type OrchestrationV2TurnItem,
6
+} from "@t3tools/contracts";
7
+import { modelSelectionsEqual } from "@t3tools/shared/model";
8
+import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError";
9
+
10
+/**
11
+ * The model or effort change a new run brings, measured from the latest run the timeline shows
12
+ * through its message or its handoff row, so consecutive dividers always chain. `baseline` stands
13
+ * in when there is none, such as a fork's source run. Callers skip starts with a context handoff;
14
+ * the handoff item already shows those.
15
+ */
16
+export function modelSwitchSince(
17
+ projection: Pick<OrchestrationV2ThreadProjection, "runs" | "turnItems">,
18
+ to: ModelSelection,
19
+ baseline?: ModelSelection,
20
+): Pick<Extract<OrchestrationV2TurnItem, { type: "user_message" }>, "modelSwitch"> {
21
+ // Clients hide pending queued messages, fold async answers into their question, and replace
22
+ // `/compact` with a compaction row.
23
+ const shown = new Set(
24
+ projection.turnItems.flatMap((item) =>
25
+ item.type === "user_message" &&
26
+ !(item.inputIntent === "queued_turn" && item.status === "pending") &&
27
+ !item.messageId.startsWith("async-answer:") &&
28
+ !isCompactionCommandMessage({ role: "user", ...item })
29
+ ? [item.messageId]
30
+ : [],
31
+ ),
32
+ );
33
+ let previous: OrchestrationV2ThreadProjection["runs"][number] | undefined;
34
+ for (const run of projection.runs) {
35
+ if (run.status === "rolled_back" || run.status === "queued") continue;
36
+ // A wake shows as a notification, but its context handoff row still shows the swap.
37
+ if (!shown.has(run.userMessageId) && run.contextHandoffId === null) continue;
38
+ if (previous === undefined || runRanAfter(run, previous)) previous = run;
39
+ }
40
+ const from = previous?.modelSelection ?? baseline;
41
+ return from === undefined || modelSelectionsEqual(from, to) ? {} : { modelSwitch: { from, to } };
42
+}
apps/web/src/components/chat/TimelineUserMessageRow.tsx
+15
@@ -38,6 +38,7 @@ import {
38
} from "lucide-react";
39
import { Link as LinkIconNode } from "lucide";
40
import { Button, InlineButton } from "../ui/button";
41
+import { ModelSwitchRow } from "./V2LifecycleRow";
42
import { useAssetUrlRefresh, useAssetUrls, useAssetUrlState } from "../../assets/assetUrls";
43
import { AttachmentImage } from "../media/AttachmentImage";
44
import { MediaVideoPlayer } from "../media/MediaVideoPlayer";
@@ -246,6 +247,20 @@ function UserVideoAttachment({
247
}
248
249
export function UserMessageRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
250
+ const ctx = use(TimelineRowCtx);
251
+ const item = row.projectedItem?.item;
252
+ const modelSwitch = item?.type === "user_message" ? item.modelSwitch : undefined;
253
+ return (
254
+ <>
255
+ {modelSwitch ? (
256
+ <ModelSwitchRow environmentId={ctx.activeThreadEnvironmentId} modelSwitch={modelSwitch} />
257
+ ) : null}
258
+ <UserMessageContent row={row} />
259
+ </>
260
+ );
261
+}
262
+
263
+function UserMessageContent({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
264
const ctx = use(TimelineRowCtx);
265
return ctx.workflowOpening?.messageId === row.message.id ? (
266
<WorkflowOpeningBlock
apps/web/src/components/chat/V2LifecycleRow.tsx
+27
@@ -18,10 +18,13 @@ import {
18
resolveHandoffEndpoints,
19
type HandoffEndpoints,
20
type HandoffTimelineRun,
21
+ resolveModelSwitchChange,
22
} from "@t3tools/client-runtime/handoff";
23
import { formatSubagentDisplayTitle } from "@t3tools/client-runtime/state/subagent-display";
24
import {
25
ProviderDriverKind,
26
+ type ModelSelection,
27
+ type OrchestrationV2ModelSwitch,
28
type OrchestrationV2Notification,
29
type OrchestrationV2TurnItem,
30
type OrchestrationV2RemoteTaskChild,
@@ -594,6 +597,30 @@ function EnvironmentHandoffRow({
597
return <HandoffRow {...props} environmentId={environmentId} providers={providers} />;
598
}
599
600
+/** A same-harness model or effort change. Shows only what changed. */
601
+export function ModelSwitchRow(props: {
602
+ readonly environmentId: EnvironmentId;
603
+ readonly modelSwitch: OrchestrationV2ModelSwitch;
604
+}) {
605
+ const providers =
606
+ useAtomValue(serverEnvironment.providersValueAtom(props.environmentId)) ??
607
+ EMPTY_SERVER_PROVIDERS;
608
+ const change = resolveModelSwitchChange(props.modelSwitch, providers);
609
+ if (change === null) return null;
610
+ const describe = (selection: ModelSelection, effort: string | undefined) => {
611
+ const provider = providers.find((candidate) => candidate.instanceId === selection.instanceId);
612
+ const model = provider?.models.find((candidate) => candidate.slug === selection.model);
613
+ const modelName = model ? getTriggerDisplayModelName(model, provider?.driver) : selection.model;
614
+ return [change.modelChanged ? modelName : null, effort].filter(Boolean).join(" ");
615
+ };
616
+ const { from, to } = props.modelSwitch;
617
+ return (
618
+ <TimelineSystemDivider
619
+ label={`${describe(from, change.effort?.from)} → ${describe(to, change.effort?.to)}`}
620
+ />
621
+ );
622
+}
623
+
624
export function HandoffRow(props: {
625
readonly environmentId: EnvironmentId;
626
readonly endpoints: HandoffEndpoints;
packages/client-runtime/src/handoff.test.ts
+97
@@ -8,6 +8,7 @@ import {
8
import { describe, expect, it } from "vite-plus/test";
9
import {
10
resolveHandoffEndpoints,
11
+ resolveModelSwitchChange,
12
resolvePendingHandoff,
13
type HandoffTimelineRun,
14
} from "./handoff.ts";
@@ -173,3 +174,99 @@ describe("pending context handoff", () => {
174
).toBeNull();
175
});
176
});
177
+
178
+describe("model switch change", () => {
179
+ const selection = (model: string, options?: Record<string, string>) => ({
180
+ instanceId: from,
181
+ model,
182
+ ...(options === undefined
183
+ ? {}
184
+ : { options: Object.entries(options).map(([id, value]) => ({ id, value })) }),
185
+ });
186
+ const providers = [
187
+ {
188
+ instanceId: from,
189
+ models: ["gpt", "mini"].map((slug) => ({
190
+ slug,
191
+ capabilities: {
192
+ optionDescriptors: [
193
+ { id: "serviceTier", type: "select", options: [{ id: "fast", label: "Fast" }] },
194
+ {
195
+ id: "thought_level",
196
+ type: "select",
197
+ role: "reasoning",
198
+ options: [
199
+ { id: "medium", label: "Medium", isDefault: true },
200
+ { id: "high", label: "High" },
201
+ ],
202
+ },
203
+ ],
204
+ },
205
+ })),
206
+ },
207
+ ] as unknown as ServerProvider[];
208
+
209
+ it("shows only what changed, reading an unset effort as the default", () => {
210
+ expect(
211
+ resolveModelSwitchChange(
212
+ { from: selection("gpt"), to: selection("gpt", { thought_level: "high" }) },
213
+ providers,
214
+ ),
215
+ ).toEqual({ modelChanged: false, effort: { from: "Medium", to: "High" } });
216
+ expect(
217
+ resolveModelSwitchChange({ from: selection("gpt"), to: selection("mini") }, providers),
218
+ ).toEqual({ modelChanged: true, effort: null });
219
+ });
220
+
221
+ it("ignores changes the user cannot see", () => {
222
+ expect(
223
+ resolveModelSwitchChange(
224
+ { from: selection("gpt"), to: selection("gpt", { thought_level: "medium" }) },
225
+ providers,
226
+ ),
227
+ ).toBeNull();
228
+ expect(
229
+ resolveModelSwitchChange(
230
+ { from: selection("gpt"), to: selection("gpt", { serviceTier: "fast" }) },
231
+ providers,
232
+ ),
233
+ ).toBeNull();
234
+ // A cataloged model without an effort control ignores stale effort options.
235
+ expect(
236
+ resolveModelSwitchChange(
237
+ {
238
+ from: selection("plain", { reasoningEffort: "low" }),
239
+ to: selection("plain", { reasoningEffort: "high" }),
240
+ },
241
+ [{ instanceId: from, models: [{ slug: "plain" }] }] as unknown as ServerProvider[],
242
+ ),
243
+ ).toBeNull();
244
+ });
245
+
246
+ it("falls back to stated efforts without a catalog", () => {
247
+ expect(
248
+ resolveModelSwitchChange(
249
+ {
250
+ from: selection("gpt", { reasoningEffort: "low" }),
251
+ to: selection("gpt", { reasoningEffort: "high" }),
252
+ },
253
+ [],
254
+ ),
255
+ ).toEqual({ modelChanged: false, effort: { from: "low", to: "high" } });
256
+ expect(
257
+ resolveModelSwitchChange(
258
+ {
259
+ from: selection("pi", { thinking: "low" }),
260
+ to: selection("pi", { thinking: "high" }),
261
+ },
262
+ [],
263
+ ),
264
+ ).toEqual({ modelChanged: false, effort: { from: "low", to: "high" } });
265
+ expect(
266
+ resolveModelSwitchChange(
267
+ { from: selection("gpt"), to: selection("gpt", { reasoningEffort: "high" }) },
268
+ [],
269
+ ),
270
+ ).toBeNull();
271
+ });
272
+});
packages/client-runtime/src/handoff.ts
+56
@@ -1,12 +1,20 @@
1
import type {
2
ModelSelection,
3
+ OrchestrationV2ModelSwitch,
4
OrchestrationV2Run,
5
OrchestrationV2TurnItem,
6
ProviderInstanceId,
7
ServerProvider,
8
+ ServerProviderModel,
9
} from "@t3tools/contracts";
10
+import {
11
+ getModelSelectionStringOptionValue,
12
+ getProviderOptionCurrentValue,
13
+} from "@t3tools/shared/model";
14
15
+import { isReasoningSelect } from "./modelTraits.ts";
16
import type { ThreadStructure } from "./state/models.ts";
17
+import { REASONING_EFFORT_OPTION_IDS } from "./state/threadExecution.ts";
18
19
export type HandoffTimelineRun = Pick<
20
OrchestrationV2Run,
@@ -80,3 +88,51 @@ function latestRunModelBefore(
88
}
89
return latest?.modelSelection.model;
90
}
91
+
92
+export interface ModelSwitchChange {
93
+ readonly modelChanged: boolean;
94
+ /** Effort labels, set only when the effort changed. */
95
+ readonly effort: { readonly from: string; readonly to: string } | null;
96
+}
97
+
98
+/**
99
+ * What a recorded model switch visibly changed, or null when it changed neither the model nor the
100
+ * effort. The composer omits an untouched effort, so an unset effort reads as the model's default.
101
+ */
102
+export function resolveModelSwitchChange(
103
+ { from, to }: OrchestrationV2ModelSwitch,
104
+ providers: ReadonlyArray<ServerProvider>,
105
+): ModelSwitchChange | null {
106
+ const modelsOf = (selection: ModelSelection) =>
107
+ providers.find((provider) => provider.instanceId === selection.instanceId)?.models;
108
+ const fromEffort = resolveEffort(from, modelsOf(from));
109
+ const toEffort = resolveEffort(to, modelsOf(to));
110
+ const modelChanged = from.model !== to.model;
111
+ const effort =
112
+ fromEffort && toEffort && fromEffort.value !== toEffort.value
113
+ ? { from: fromEffort.label, to: toEffort.label }
114
+ : null;
115
+ return modelChanged || effort ? { modelChanged, effort } : null;
116
+}
117
+
118
+/** The composer's reasoning control for the model; stated values only when the catalog lacks it. */
119
+function resolveEffort(
120
+ selection: ModelSelection,
121
+ models: ReadonlyArray<ServerProviderModel> | undefined,
122
+): { readonly value: string; readonly label: string } | undefined {
123
+ const model = models?.find((candidate) => candidate.slug === selection.model);
124
+ if (model === undefined) {
125
+ // Pi states its effort as `thinking`; the catalog would otherwise mark it a reasoning control.
126
+ const value = [...REASONING_EFFORT_OPTION_IDS, "thinking"]
127
+ .map((id) => getModelSelectionStringOptionValue(selection, id))
128
+ .find((candidate) => candidate !== undefined);
129
+ return value === undefined ? undefined : { value, label: value };
130
+ }
131
+ const descriptor = model.capabilities?.optionDescriptors?.find(isReasoningSelect);
132
+ if (descriptor === undefined) return undefined;
133
+ const value =
134
+ getModelSelectionStringOptionValue(selection, descriptor.id) ??
135
+ getProviderOptionCurrentValue(descriptor, selection);
136
+ if (typeof value !== "string") return undefined;
137
+ return { value, label: descriptor.options.find((option) => option.id === value)?.label ?? value };
138
+}
packages/contracts/src/orchestrationV2.ts
+9
@@ -1480,6 +1480,13 @@ export const OrchestrationV2UserMessageInputIntent = Schema.Literals([
1480
export type OrchestrationV2UserMessageInputIntent =
1481
typeof OrchestrationV2UserMessageInputIntent.Type;
1482
1483
+/** A same-harness model or effort change that took effect with this message. */
1484
+export const OrchestrationV2ModelSwitch = Schema.Struct({
1485
+ from: ModelSelection,
1486
+ to: ModelSelection,
1487
+});
1488
+export type OrchestrationV2ModelSwitch = typeof OrchestrationV2ModelSwitch.Type;
1489
+
1490
const OrchestrationV2TurnItemBaseFields = {
1491
/** Wire-only cursor for collapsed work; persisted items keep their complete history. */
1492
deferredWork: Schema.optionalKey(
@@ -1601,6 +1608,7 @@ export const OrchestrationV2TurnItem = Schema.Union([
1608
textOmitted: DedupedBodyMarker,
1609
context: Schema.optional(OrchestrationMessageContext),
1610
attachments: Schema.Array(ChatAttachment),
1611
+ modelSwitch: Schema.optional(OrchestrationV2ModelSwitch),
1612
}),
1613
Schema.Struct({
1614
...OrchestrationV2TurnItemBaseFields,
@@ -2431,6 +2439,7 @@ export const OrchestrationV2TurnItemJson = Schema.Union([
2439
text: Schema.String,
2440
context: Schema.optional(OrchestrationMessageContext),
2441
attachments: Schema.Array(ChatAttachment),
2442
+ modelSwitch: Schema.optional(OrchestrationV2ModelSwitch),
2443
}),
2444
Schema.Struct({
2445
...OrchestrationV2TurnItemJsonBaseFields,
packages/provider-core/src/server/notification.ts
+1
@@ -217,6 +217,7 @@ export function notificationTurnItem(
217
createdBy: _createdBy,
218
creationSource: _creationSource,
219
scheduledTaskId: _scheduledTaskId,
220
+ modelSwitch: _modelSwitch,
221
...base
222
} = item;
223
return { ...base, type: "notification", ...notification };