TypeScript
fix: generate thread titles with the selected model across connections (#10526)
Bilal Bakrbc4b00666272
diff --git a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsRouteScreen.tsxindex 3bd25a20c8d..57e6ab30a1d 100644--- a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx+++ b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx@@ -669,6 +669,8 @@ function AutoSettleSettingsRows() {patch: filterSharedServerPatch(patch,target?.serverConfig?.environment.capabilities,+ target?.serverConfig?.settings,+ referenceSettings,),},});diff --git a/apps/server/src/textGeneration/ClaudeTextGeneration.test.ts b/apps/server/src/textGeneration/ClaudeTextGeneration.test.tsindex fc9c9691d44..8fe5152d345 100644--- a/apps/server/src/textGeneration/ClaudeTextGeneration.test.ts+++ b/apps/server/src/textGeneration/ClaudeTextGeneration.test.ts@@ -50,6 +50,10 @@ function makeFakeClaudeBinary(dir: string) {" process.exit(code);","}","",+ 'const permissionIndex = argv.indexOf("--permission-mode");',+ 'if (permissionIndex === -1 || argv[permissionIndex + 1] !== "dontAsk") {',+ ' fail("text generation must deny permission prompts", 12);',+ "}",'const toolsIndex = argv.indexOf("--tools");','if (toolsIndex === -1 || argv[toolsIndex + 1] !== "") {',' fail("text generation must receive an explicit empty tool set", 6);',diff --git a/apps/server/src/textGeneration/ClaudeTextGeneration.ts b/apps/server/src/textGeneration/ClaudeTextGeneration.tsindex 2151495d915..76d5b256b3d 100644--- a/apps/server/src/textGeneration/ClaudeTextGeneration.ts+++ b/apps/server/src/textGeneration/ClaudeTextGeneration.ts@@ -214,6 +214,8 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu"","--disable-slash-commands","--strict-mcp-config",+ "--permission-mode",+ "dontAsk",],{ env: claudeEnvironment },);diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsxindex bac8f293732..f51c14c4f39 100644--- a/apps/web/src/components/settings/SettingsPanels.tsx+++ b/apps/web/src/components/settings/SettingsPanels.tsx@@ -2718,7 +2718,7 @@ export function GeneralSettingsPanel() {<SettingsRowserverScoped{...searchableSetting("text-generation-model")}- description="Used for thread titles and other generated text. Source control can override it."+ description="Used for thread titles and other generated text on connected devices with this provider. Source control can override it."resetAction={isTextGenerationModelDirty ? (<SettingResetButtondiff --git a/apps/web/src/hooks/useSettings.ts b/apps/web/src/hooks/useSettings.tsindex 423059aba26..2df74d6a5da 100644--- a/apps/web/src/hooks/useSettings.ts+++ b/apps/web/src/hooks/useSettings.ts@@ -450,6 +450,9 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {}}if (Object.keys(sharedPatch).length > 0) {+ const sourceSettings = environments.find(+ (target) => target.environmentId === environmentId,+ )?.serverConfig?.settings;const targets = new Set(environments.filter(supportsSharedSettingsSync).map((target) => target.environmentId),);@@ -462,6 +465,9 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {const targetPatch = filterSharedServerPatch(sharedPatch,target?.serverConfig?.environment.capabilities,+ target?.serverConfig?.settings,+ sourceSettings,+ targetId === environmentId,);if (Object.keys(targetPatch).length === 0) continue;wroteToTarget = true;@@ -540,7 +546,12 @@ export function useSharedSettingsSync() {void persistServerSettings({environmentId: mismatch.environmentId,input: {- patch: filterSharedServerPatch(patch, target?.serverConfig?.environment.capabilities),+ patch: filterSharedServerPatch(+ patch,+ target?.serverConfig?.environment.capabilities,+ target?.serverConfig?.settings,+ primarySettings,+ ),},});}diff --git a/packages/client-runtime/src/state/sharedSettings.test.ts b/packages/client-runtime/src/state/sharedSettings.test.tsindex 712138aab4c..fc5ffe62ebc 100644--- a/packages/client-runtime/src/state/sharedSettings.test.ts+++ b/packages/client-runtime/src/state/sharedSettings.test.ts@@ -1,4 +1,9 @@-import { DEFAULT_SERVER_SETTINGS, EnvironmentId } from "@t3tools/contracts";+import {+ DEFAULT_SERVER_SETTINGS,+ EnvironmentId,+ ProviderDriverKind,+ ProviderInstanceId,+} from "@t3tools/contracts";import { describe, expect, it } from "@effect/vitest";import {@@ -38,6 +43,47 @@ describe("supportsSharedSettingsSync", () => {});describe("splitSharedServerPatch", () => {+ it.each([+ {+ instanceId: ProviderInstanceId.make("codex"),+ model: "gpt-5.6-sol",+ options: [{ id: "reasoningEffort", value: "low" }],+ },+ {+ instanceId: ProviderInstanceId.make("claudeAgent"),+ model: "claude-sonnet-4-6",+ options: [{ id: "effort", value: "high" }],+ },+ DEFAULT_SERVER_SETTINGS.textGenerationModelSelection,+ ])("shares the text generation model and options, including reset (%j)", (selection) => {+ const patch = { textGenerationModelSelection: selection };+ expect(splitSharedServerPatch(patch)).toEqual({ sharedPatch: patch, localPatch: {} });+ expect(pickSharedServerSettings({ ...DEFAULT_SERVER_SETTINGS, ...patch })).toMatchObject(patch);+ const environment = {+ environmentId: boxId,+ label: "Remote Box",+ syncEligible: true,+ settings: {+ ...DEFAULT_SERVER_SETTINGS,+ textGenerationModelSelection: { ...selection, model: "different-model" },+ },+ };+ const input = {+ primaryEnvironmentId: primaryId,+ primarySettings: { ...DEFAULT_SERVER_SETTINGS, ...patch },+ environments: [environment],+ };+ expect(findSharedSettingsMismatches(input)).toEqual([+ { environmentId: boxId, label: "Remote Box" },+ ]);+ expect(+ findSharedSettingsMismatches({+ ...input,+ environments: [{ ...environment, settings: input.primarySettings }],+ }),+ ).toEqual([]);+ });+it("routes preference keys to the shared patch and machine keys to the local patch", () => {const { sharedPatch, localPatch } = splitSharedServerPatch({sidebarAutoSettleAfterDays: 7,@@ -70,11 +116,92 @@ describe("pickSharedServerSettings", () => {"sidebarAutoSettleAfterDays","sidebarAutoSettleOnMerge","sourceControlWritingStyle",+ "textGenerationModelSelection",]);});});describe("filterSharedServerPatch", () => {+ it.each([true, false])(+ "resets a disabled default provider only on the originating environment (%s)",+ (targetIsSource) => {+ const settings = {+ ...DEFAULT_SERVER_SETTINGS,+ providerInstances: {+ codex: { driver: ProviderDriverKind.make("codex"), enabled: false, config: {} },+ claudeAgent: {+ driver: ProviderDriverKind.make("claudeAgent"),+ enabled: true,+ config: {},+ },+ },+ textGenerationModelSelection: {+ instanceId: ProviderInstanceId.make("claudeAgent"),+ model: "claude-opus-4-6",+ },+ };+ const patch = {+ textGenerationModelSelection: DEFAULT_SERVER_SETTINGS.textGenerationModelSelection,+ continueThreadsAfterServerUpdate: true,+ sidebarAutoSettleAfterDays: 7,+ };+ expect(filterSharedServerPatch(patch, undefined, settings, settings, targetIsSource)).toEqual(+ {+ ...(targetIsSource+ ? { textGenerationModelSelection: DEFAULT_SERVER_SETTINGS.textGenerationModelSelection }+ : {}),+ sidebarAutoSettleAfterDays: 7,+ },+ );+ },+ );++ it.each(["missing", "disabled", "different-driver", "enabled"] as const)(+ "shares a custom model only when its target provider is enabled (%s)",+ (availability) => {+ const instanceId = ProviderInstanceId.make("codex_personal");+ const selection = {+ instanceId,+ model: "gpt-5.6-luna",+ options: [{ id: "reasoningEffort", value: "low" }],+ };+ const instance = {+ driver: ProviderDriverKind.make(+ availability === "different-driver" ? "claudeAgent" : "codex",+ ),+ enabled: availability !== "disabled",+ config: {},+ };+ const settings = {+ ...DEFAULT_SERVER_SETTINGS,+ providerInstances: availability === "missing" ? {} : { [instanceId]: instance },+ };+ const patch = { sidebarAutoSettleAfterDays: 7, textGenerationModelSelection: selection };+ const sourceSettings = {+ ...settings,+ providerInstances: {+ [instanceId]: { ...instance, driver: ProviderDriverKind.make("codex"), enabled: true },+ },+ };+ expect(filterSharedServerPatch(patch, restartCapabilities, settings, sourceSettings)).toEqual(+ availability === "enabled" ? patch : { sidebarAutoSettleAfterDays: 7 },+ );+ const primarySettings = {+ ...sourceSettings,+ textGenerationModelSelection: selection,+ };+ expect(+ findSharedSettingsMismatches({+ primaryEnvironmentId: primaryId,+ primarySettings,+ environments: [+ { environmentId: boxId, label: "Remote Box", syncEligible: true, settings },+ ],+ }),+ ).toEqual(availability === "enabled" ? [{ environmentId: boxId, label: "Remote Box" }] : []);+ },+ );+it.each([true, false])("preserves supported restart preference %s", (enabled) => {const patch = { continueThreadsAfterServerUpdate: enabled, sidebarAutoSettleAfterDays: 7 };expect(filterSharedServerPatch(patch, restartCapabilities)).toEqual(patch);diff --git a/packages/client-runtime/src/state/sharedSettings.ts b/packages/client-runtime/src/state/sharedSettings.tsindex 0fd691a64bc..9845764d5e0 100644--- a/packages/client-runtime/src/state/sharedSettings.ts+++ b/packages/client-runtime/src/state/sharedSettings.ts@@ -14,6 +14,7 @@ import type {ServerSettings,ServerSettingsPatch,} from "@t3tools/contracts";+import { isModelSelectionProviderEnabled } from "@t3tools/shared/serverSettings";import * as Equal from "effect/Equal";import * as Struct from "effect/Struct";@@ -26,6 +27,7 @@ const SHARED_SERVER_SETTING_KEYS = ["sidebarAutoSettleOnMerge","newWorktreesStartFromOrigin","sourceControlWritingStyle",+ "textGenerationModelSelection",] as const satisfies ReadonlyArray<keyof ServerSettings & keyof ServerSettingsPatch>;export type SharedServerSettingKey = (typeof SHARED_SERVER_SETTING_KEYS)[number];@@ -52,11 +54,31 @@ export function splitSharedServerPatch(patch: ServerSettingsPatch): {};}-/** Omit restart recovery on servers that cannot persist its preference. */+/** Filter unsupported preferences; direct model writes retain the server's fallback behavior. */export function filterSharedServerPatch(patch: ServerSettingsPatch,capabilities: Pick<ExecutionEnvironmentCapabilities, "threadRestartContinuation"> | undefined,+ settings?: ServerSettings,+ sourceSettings = settings,+ targetIsSource = false,): ServerSettingsPatch {+ const instanceId =+ patch.textGenerationModelSelection?.instanceId ??+ sourceSettings?.textGenerationModelSelection.instanceId;+ if (+ !targetIsSource &&+ patch.textGenerationModelSelection &&+ (!settings ||+ (instanceId !== undefined &&+ (sourceSettings?.providerInstances[instanceId]?.driver ?? instanceId) !==+ (settings.providerInstances[instanceId]?.driver ?? instanceId)) ||+ !isModelSelectionProviderEnabled(settings, {+ ...settings.textGenerationModelSelection,+ ...patch.textGenerationModelSelection,+ }))+ ) {+ patch = Struct.omit(patch, ["textGenerationModelSelection"]);+ }return capabilities?.threadRestartContinuation === true? patch: Struct.omit(patch, ["continueThreadsAfterServerUpdate"]);@@ -67,7 +89,11 @@ export function pickSharedServerSettings(settings: ServerSettings,capabilities?: Pick<ExecutionEnvironmentCapabilities, "threadRestartContinuation">,): ServerSettingsPatch {- return filterSharedServerPatch(Struct.pick(settings, SHARED_SERVER_SETTING_KEYS), capabilities);+ return filterSharedServerPatch(+ Struct.pick(settings, SHARED_SERVER_SETTING_KEYS),+ capabilities,+ settings,+ );}/**@@ -129,11 +155,20 @@ export function findSharedSettingsMismatches(input: {) {return [];}- const expected = filterSharedServerPatch(primarySettings, environment.capabilities);- const actual = filterSharedServerPatch(+ const expected = filterSharedServerPatch(+ primarySettings,+ environment.capabilities,+ environment.settings,+ input.primarySettings ?? undefined,+ );+ let actual = filterSharedServerPatch(pickSharedServerSettings(environment.settings, environment.capabilities),input.primaryCapabilities,+ environment.settings,);+ if (!expected.textGenerationModelSelection) {+ actual = Struct.omit(actual, ["textGenerationModelSelection"]);+ }return Equal.equals(actual, expected)? []: [{ environmentId: environment.environmentId, label: environment.label }];