fix: generate thread titles with the selected model across connections (#10526)
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
9d345fa957
commit
bc4b006662
7 files changed
+188
-7
No files matched your search
@@ -669,6 +669,8 @@ function AutoSettleSettingsRows() {
|
||||
patch: filterSharedServerPatch(
|
||||
patch,
|
||||
target?.serverConfig?.environment.capabilities,
|
||||
target?.serverConfig?.settings,
|
||||
referenceSettings,
|
||||
),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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);',
|
||||
|
||||
@@ -214,6 +214,8 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
|
||||
"",
|
||||
"--disable-slash-commands",
|
||||
"--strict-mcp-config",
|
||||
"--permission-mode",
|
||||
"dontAsk",
|
||||
],
|
||||
{ env: claudeEnvironment },
|
||||
);
|
||||
|
||||
@@ -2718,7 +2718,7 @@ export function GeneralSettingsPanel() {
|
||||
<SettingsRow
|
||||
serverScoped
|
||||
{...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 ? (
|
||||
<SettingResetButton
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 }];
|
||||
|
||||
Reference in new issue
Block a user