Add model selection to orchestration runs

- persist the selected model on run records
- surface run model selection in the debug UI
- update replay fixtures and contracts for the new field
This commit is contained in:
Julius Marminge committed 2026-05-06 14:39:42 -07:00
1 parent 9316b57f9f
commit 2ea043e73b
6 files changed
+163 -21

No files matched your search

@@ -1432,6 +1432,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
threadId: command.threadId,
ordinal,
provider: modelSelection.instanceId,
modelSelection,
providerThreadId: queueProviderThread.id,
userMessageId: command.messageId,
rootNodeId,
@@ -1910,6 +1911,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
threadId: command.threadId,
ordinal,
provider: modelSelection.instanceId,
modelSelection,
providerThreadId: providerThread.id,
userMessageId: command.messageId,
rootNodeId,
@@ -198,17 +198,6 @@ export function makeDriverLayerFromSettings<R>(input: {
return Layer.unwrap(
Effect.gen(function* () {
const settingsService = yield* ServerSettingsService;
yield* settingsService.ready.pipe(
Effect.mapError(
(cause) =>
new ProviderAdapterDriverCreateError({
driver: ProviderDriverKindSchema.make("settings"),
instanceId: ProviderInstanceId.make("settings"),
detail: "Server settings were not ready before building provider adapters.",
cause,
}),
),
);
const settings = yield* settingsService.getSettings.pipe(
Effect.mapError(
(cause) =>
@@ -118,6 +118,19 @@ describe("Claude Agent SDK replay fixtures", () => {
);
provider.assertOutput(result, transcript);
const projectionThreadId = materialized.projectionThreadIds[0];
if (projectionThreadId === undefined) {
throw new Error("Missing replay projection thread id.");
}
const projection = result.projections.get(projectionThreadId);
if (projection === undefined) {
throw new Error("Missing replay projection.");
}
const latestRun = projection.runs.at(-1);
if (latestRun === undefined) {
throw new Error("Missing replay run.");
}
assert.deepEqual(latestRun.modelSelection, provider.modelSelection);
} finally {
await rm(checkpointWorkspace, { recursive: true, force: true });
}
+143 -10
View File
@@ -1,4 +1,5 @@
import {
ProviderDriverKind,
ProviderInstanceId,
type CheckpointId,
type CheckpointScopeId,
@@ -16,14 +17,17 @@ import {
type OrchestrationV2UserInputQuestion,
type RunId,
type RuntimeMode,
type ServerProvider,
type ThreadId,
} from "@t3tools/contracts";
import { createFileRoute } from "@tanstack/react-router";
import type { CSSProperties, DragEvent, ReactNode } from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { ProviderModelPicker } from "../components/chat/ProviderModelPicker";
import { getPrimaryEnvironmentConnection } from "../environments/runtime";
import { newCommandId, newMessageId, newProjectId, newThreadId } from "../lib/utils";
import { deriveProviderInstanceEntries, sortProviderInstanceEntries } from "../providerInstances";
import { GitMergeIcon } from "lucide-react";
export const Route = createFileRoute("/debug/orchestration-v2")({
@@ -31,11 +35,112 @@ export const Route = createFileRoute("/debug/orchestration-v2")({
});
const DEFAULT_PROMPT = "Respond with the following text: fixture simple ok";
const DEBUG_CODEX_DRIVER = ProviderDriverKind.make("codex");
const DEBUG_CLAUDE_DRIVER = ProviderDriverKind.make("claudeAgent");
const DEBUG_CODEX_INSTANCE_ID = ProviderInstanceId.make("codex");
const DEBUG_CLAUDE_INSTANCE_ID = ProviderInstanceId.make("claudeAgent");
const DEFAULT_MODEL_SELECTION = {
instanceId: ProviderInstanceId.make("codex"),
instanceId: DEBUG_CODEX_INSTANCE_ID,
model: "gpt-5.4",
} satisfies ModelSelection;
const DEBUG_PROVIDER_SNAPSHOTS: ReadonlyArray<ServerProvider> = [
{
instanceId: DEBUG_CODEX_INSTANCE_ID,
driver: DEBUG_CODEX_DRIVER,
displayName: "Codex",
enabled: true,
installed: true,
version: null,
status: "ready",
auth: { status: "authenticated" },
checkedAt: "2026-01-01T00:00:00.000Z",
models: [
{
slug: "gpt-5.4",
name: "GPT-5.4",
shortName: "5.4",
isCustom: false,
capabilities: null,
},
{
slug: "gpt-5.4-mini",
name: "GPT-5.4 Mini",
shortName: "5.4 Mini",
isCustom: false,
capabilities: null,
},
{
slug: "gpt-5.3-codex",
name: "GPT-5.3 Codex",
shortName: "5.3",
isCustom: false,
capabilities: null,
},
{
slug: "gpt-5.3-codex-spark",
name: "GPT-5.3 Codex Spark",
shortName: "Spark",
isCustom: false,
capabilities: null,
},
],
slashCommands: [],
skills: [],
},
{
instanceId: DEBUG_CLAUDE_INSTANCE_ID,
driver: DEBUG_CLAUDE_DRIVER,
displayName: "Claude",
enabled: true,
installed: true,
version: null,
status: "ready",
auth: { status: "authenticated" },
checkedAt: "2026-01-01T00:00:00.000Z",
models: [
{
slug: "claude-opus-4-7",
name: "Claude Opus 4.7",
shortName: "Opus 4.7",
isCustom: false,
capabilities: null,
},
{
slug: "claude-opus-4-6",
name: "Claude Opus 4.6",
shortName: "Opus 4.6",
isCustom: false,
capabilities: null,
},
{
slug: "claude-sonnet-4-6",
name: "Claude Sonnet 4.6",
shortName: "Sonnet 4.6",
isCustom: false,
capabilities: null,
},
{
slug: "claude-haiku-4-5",
name: "Claude Haiku 4.5",
shortName: "Haiku 4.5",
isCustom: false,
capabilities: null,
},
],
slashCommands: [],
skills: [],
},
];
const DEBUG_PROVIDER_INSTANCE_ENTRIES = sortProviderInstanceEntries(
deriveProviderInstanceEntries(DEBUG_PROVIDER_SNAPSHOTS),
);
const DEBUG_MODEL_OPTIONS_BY_INSTANCE = new Map(
DEBUG_PROVIDER_SNAPSHOTS.map((provider) => [provider.instanceId, provider.models] as const),
);
type LogEntry =
| {
readonly type: "command";
@@ -233,7 +338,7 @@ function buildProjectionTimeline(
key: `run:${run.id}`,
eyebrow: "Run",
title: `Run ${run.ordinal}`,
subtitle: run.provider,
subtitle: `${run.modelSelection.instanceId} / ${run.modelSelection.model}`,
status: run.status,
timestamp: formatTimestamp(run.startedAt ?? run.requestedAt),
raw: run,
@@ -587,6 +692,7 @@ type PendingMergeBackTransfer = OrchestrationV2ThreadProjection["contextTransfer
interface DebugThreadTreeNode {
readonly threadId: ThreadId;
readonly thread: OrchestrationV2ThreadShell;
readonly modelSelection: ModelSelection;
readonly children: ReadonlyArray<DebugThreadTreeNode>;
}
@@ -753,6 +859,7 @@ function threadShellCreatedMs(thread: OrchestrationV2ThreadShell): number {
function buildThreadTree(input: {
readonly threads: ReadonlyMap<ThreadId, OrchestrationV2ThreadShell>;
readonly projectionsByThread: ReadonlyMap<ThreadId, OrchestrationV2ThreadProjection>;
}): ReadonlyArray<DebugThreadTreeNode> {
const childIds = new Map<ThreadId, Array<ThreadId>>();
const rootIds: Array<ThreadId> = [];
@@ -783,10 +890,12 @@ function buildThreadTree(input: {
if (thread === undefined) {
throw new Error(`Missing orchestration V2 shell thread ${threadId}`);
}
const latestRun = input.projectionsByThread.get(threadId)?.runs.at(-1);
const children = sortThreadIds(childIds.get(threadId) ?? []).map(buildNode);
return {
threadId,
thread,
modelSelection: latestRun?.modelSelection ?? thread.modelSelection,
children,
};
};
@@ -1126,8 +1235,8 @@ function ThreadTreeRow(props: {
const thread = props.node.thread;
const active = props.node.threadId === props.activeThreadId;
const relationship = thread.lineage.relationshipToParent ?? "source";
const instanceId = thread.modelSelection.instanceId;
const model = thread.modelSelection.model;
const instanceId = props.node.modelSelection.instanceId;
const model = props.node.modelSelection.model;
const itemCount = thread.visibleItemCount;
const createdAt = formatTimestamp(thread.createdAt);
@@ -1398,6 +1507,7 @@ function PanelHeader(props: {
function OrchestrationV2DebugRoute() {
const [prompt, setPrompt] = useState(DEFAULT_PROMPT);
const [modelSelection, setModelSelection] = useState<ModelSelection>(DEFAULT_MODEL_SELECTION);
const [threadId, setThreadId] = useState<ThreadId | null>(null);
const [projection, setProjection] = useState<OrchestrationV2ThreadProjection | null>(null);
const [projectionError, setProjectionError] = useState<string | null>(null);
@@ -1450,8 +1560,8 @@ function OrchestrationV2DebugRoute() {
[logEntries, projection, projectionByThread],
);
const threadTree = useMemo(
() => buildThreadTree({ threads: shellThreadsById }),
[shellThreadsById],
() => buildThreadTree({ threads: shellThreadsById, projectionsByThread: projectionByThread }),
[projectionByThread, shellThreadsById],
);
const activeTurn = useMemo(() => deriveActiveTurn(projection), [projection]);
const queuedRuns = useMemo(() => buildQueuedRunRows(projection), [projection]);
@@ -1582,7 +1692,7 @@ function OrchestrationV2DebugRoute() {
threadId: nextThreadId,
projectId: newProjectId(),
title: "V2 debug thread",
modelSelection: DEFAULT_MODEL_SELECTION,
modelSelection,
runtimeMode: "full-access" satisfies RuntimeMode,
interactionMode: "default",
branch: null,
@@ -1594,7 +1704,7 @@ function OrchestrationV2DebugRoute() {
appendLog({ type: "command", label: "thread.create", value: result });
await refreshProjection(nextThreadId);
return nextThreadId;
}, [api, appendLog, refreshProjection, subscribeToThread]);
}, [api, appendLog, modelSelection, refreshProjection, subscribeToThread]);
const ensureThread = useCallback(async () => {
if (threadId !== null) {
@@ -1637,7 +1747,7 @@ function OrchestrationV2DebugRoute() {
messageId: newMessageId(),
text: trimmedPrompt,
attachments: [],
modelSelection: DEFAULT_MODEL_SELECTION,
modelSelection,
dispatchMode:
intent === "steer" && targetRunId !== undefined
? { type: "steer_active", targetRunId }
@@ -1660,7 +1770,16 @@ function OrchestrationV2DebugRoute() {
setIsBusy(false);
}
},
[activeTurn?.targetRunId, api, appendLog, ensureThread, isBusy, prompt, refreshProjection],
[
activeTurn?.targetRunId,
api,
appendLog,
ensureThread,
isBusy,
modelSelection,
prompt,
refreshProjection,
],
);
const promoteQueuedRun = useCallback(
@@ -1917,6 +2036,20 @@ function OrchestrationV2DebugRoute() {
<HiddenPanelPills hiddenPanels={hiddenPanels} onRestore={restorePanel} />
</div>
<div className="flex flex-wrap items-center gap-2">
<ProviderModelPicker
activeInstanceId={modelSelection.instanceId}
model={modelSelection.model}
lockedProvider={null}
instanceEntries={DEBUG_PROVIDER_INSTANCE_ENTRIES}
modelOptionsByInstance={DEBUG_MODEL_OPTIONS_BY_INSTANCE}
compact
disabled={isBusy}
triggerVariant="outline"
triggerClassName="h-9 max-w-64 bg-background"
onInstanceModelChange={(instanceId, model) => {
setModelSelection({ instanceId, model });
}}
/>
<button
type="button"
disabled={isBusy}
@@ -105,6 +105,10 @@ describe("orchestration V2 contracts", () => {
threadId: "thread-1",
ordinal: 1,
provider: "codex",
modelSelection: {
instanceId: "codex",
model: "gpt-5.4",
},
providerThreadId: "provider-thread-1",
userMessageId: "message-1",
rootNodeId: null,
@@ -308,6 +308,7 @@ export const OrchestrationV2Run = Schema.Struct({
threadId: ThreadId,
ordinal: PositiveInt,
provider: ProviderKind,
modelSelection: ModelSelection,
providerThreadId: Schema.NullOr(ProviderThreadId),
userMessageId: MessageId,
rootNodeId: Schema.NullOr(NodeId),