Fix Claude model fallback in web store sync

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-02-27 21:35:57 -08:00
1 parent b6f93eaf5b
commit 67eef99b43
2 files changed
+116 -2

No files matched your search

+87 -1
View File
@@ -1,4 +1,4 @@
import { ProjectId, ThreadId, TurnId } from "@t3tools/contracts";
import { ProjectId, ThreadId, TurnId, type OrchestrationReadModel } from "@t3tools/contracts";
import { describe, expect, it } from "vitest";
import { reducer, type AppState } from "./store";
@@ -54,6 +54,46 @@ function makeState(thread: Thread): AppState {
};
}
function makeReadModelThread(overrides: Partial<OrchestrationReadModel["threads"][number]>) {
return {
id: ThreadId.makeUnsafe("thread-1"),
projectId: ProjectId.makeUnsafe("project-1"),
title: "Thread",
model: "gpt-5.3-codex",
branch: null,
worktreePath: null,
latestTurn: null,
createdAt: "2026-02-27T00:00:00.000Z",
updatedAt: "2026-02-27T00:00:00.000Z",
deletedAt: null,
messages: [],
activities: [],
checkpoints: [],
session: null,
...overrides,
} satisfies OrchestrationReadModel["threads"][number];
}
function makeReadModel(thread: OrchestrationReadModel["threads"][number]): OrchestrationReadModel {
return {
snapshotSequence: 1,
updatedAt: "2026-02-27T00:00:00.000Z",
projects: [
{
id: ProjectId.makeUnsafe("project-1"),
title: "Project",
workspaceRoot: "/tmp/project",
defaultModel: "gpt-5.3-codex",
createdAt: "2026-02-27T00:00:00.000Z",
updatedAt: "2026-02-27T00:00:00.000Z",
deletedAt: null,
scripts: [],
},
],
threads: [thread],
};
}
describe("store reducer", () => {
it("marks a completed thread as unread by moving lastVisitedAt before completion", () => {
const latestTurnCompletedAt = "2026-02-25T12:30:00.000Z";
@@ -159,3 +199,49 @@ describe("store terminal activity reducer", () => {
expect(next.threads[0]?.runningTerminalIds).toEqual([]);
});
});
describe("store read model sync", () => {
it("preserves claude model slugs without an active session", () => {
const initialState = makeState(makeThread());
const readModel = makeReadModel(
makeReadModelThread({
model: "claude-opus-4-6",
}),
);
const next = reducer(initialState, {
type: "SYNC_SERVER_READ_MODEL",
readModel,
});
expect(next.threads[0]?.model).toBe("claude-opus-4-6");
});
it("resolves claude aliases when session provider is claudeCode", () => {
const initialState = makeState(makeThread());
const readModel = makeReadModel(
makeReadModelThread({
model: "sonnet",
session: {
threadId: ThreadId.makeUnsafe("thread-1"),
status: "ready",
providerName: "claudeCode",
providerSessionId: null,
providerThreadId: null,
approvalPolicy: "on-request",
sandboxMode: "workspace-write",
activeTurnId: null,
lastError: null,
updatedAt: "2026-02-27T00:00:00.000Z",
},
}),
);
const next = reducer(initialState, {
type: "SYNC_SERVER_READ_MODEL",
readModel,
});
expect(next.threads[0]?.model).toBe("claude-sonnet-4-6");
});
});
+29 -1
View File
@@ -10,11 +10,14 @@ import {
import {
DEFAULT_MODEL,
getModelOptions,
normalizeModelSlug,
ProviderSessionId,
ThreadId,
type OrchestrationReadModel,
type OrchestrationSessionStatus,
resolveModelSlug,
resolveModelSlugForProvider,
} from "@t3tools/contracts";
import {
DEFAULT_THREAD_TERMINAL_HEIGHT,
@@ -192,6 +195,27 @@ function toLegacyProvider(providerName: string | null): "codex" | "claudeCode" {
return providerName === "claudeCode" ? "claudeCode" : "codex";
}
const CODEX_MODEL_SLUGS = new Set(getModelOptions("codex").map((option) => option.slug));
const CLAUDE_MODEL_SLUGS = new Set(getModelOptions("claudeCode").map((option) => option.slug));
function inferProviderForThreadModel(input: {
readonly model: string;
readonly sessionProviderName: string | null;
}): "codex" | "claudeCode" {
if (input.sessionProviderName === "codex" || input.sessionProviderName === "claudeCode") {
return input.sessionProviderName;
}
const normalizedClaude = normalizeModelSlug(input.model, "claudeCode");
if (normalizedClaude && CLAUDE_MODEL_SLUGS.has(normalizedClaude)) {
return "claudeCode";
}
const normalizedCodex = normalizeModelSlug(input.model, "codex");
if (normalizedCodex && CODEX_MODEL_SLUGS.has(normalizedCodex)) {
return "codex";
}
return input.model.trim().startsWith("claude-") ? "claudeCode" : "codex";
}
function resolveWsHttpOrigin(): string {
if (typeof window === "undefined") {
return "";
@@ -451,13 +475,17 @@ export function reducer(state: AppState, action: Action): AppState {
.filter((thread) => thread.deletedAt === null)
.map((thread) => {
const existing = existingThreadById.get(thread.id);
const modelProvider = inferProviderForThreadModel({
model: thread.model,
sessionProviderName: thread.session?.providerName ?? null,
});
return normalizeThreadTerminals({
id: thread.id,
codexThreadId: thread.session?.providerThreadId ?? null,
projectId: thread.projectId,
title: thread.title,
model: resolveModelSlug(thread.model),
model: resolveModelSlugForProvider(modelProvider, thread.model),
terminalOpen: existing?.terminalOpen ?? false,
terminalHeight: existing?.terminalHeight ?? DEFAULT_THREAD_TERMINAL_HEIGHT,
terminalIds: existing?.terminalIds ?? [DEFAULT_THREAD_TERMINAL_ID],