fix(server): drop stale text generation options when resetting text-gen model selection (#2076)
This commit is contained in:
1 parent
19d47408a5
commit
7a08fcf2e8
5 files changed
+141
-5
No files matched your search
@@ -142,6 +142,35 @@ it.layer(NodeServices.layer)("server settings", (it) => {
|
||||
}).pipe(Effect.provide(makeServerSettingsLayer())),
|
||||
);
|
||||
|
||||
it.effect("drops stale text generation options when resetting model selection", () =>
|
||||
Effect.gen(function* () {
|
||||
const serverSettings = yield* ServerSettingsService;
|
||||
|
||||
yield* serverSettings.updateSettings({
|
||||
textGenerationModelSelection: {
|
||||
provider: "codex",
|
||||
model: DEFAULT_SERVER_SETTINGS.textGenerationModelSelection.model,
|
||||
options: {
|
||||
reasoningEffort: "high",
|
||||
fastMode: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const next = yield* serverSettings.updateSettings({
|
||||
textGenerationModelSelection: {
|
||||
provider: DEFAULT_SERVER_SETTINGS.textGenerationModelSelection.provider,
|
||||
model: DEFAULT_SERVER_SETTINGS.textGenerationModelSelection.model,
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepEqual(next.textGenerationModelSelection, {
|
||||
provider: DEFAULT_SERVER_SETTINGS.textGenerationModelSelection.provider,
|
||||
model: DEFAULT_SERVER_SETTINGS.textGenerationModelSelection.model,
|
||||
});
|
||||
}).pipe(Effect.provide(makeServerSettingsLayer())),
|
||||
);
|
||||
|
||||
it.effect("trims provider path settings when updates are applied", () =>
|
||||
Effect.gen(function* () {
|
||||
const serverSettings = yield* ServerSettingsService;
|
||||
|
||||
@@ -42,6 +42,7 @@ import * as Semaphore from "effect/Semaphore";
|
||||
import { ServerConfig } from "./config";
|
||||
import { type DeepPartial, deepMerge } from "@t3tools/shared/Struct";
|
||||
import { fromLenientJson } from "@t3tools/shared/schemaJson";
|
||||
import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
|
||||
|
||||
export interface ServerSettingsShape {
|
||||
/** Start the settings runtime and attach file watching. */
|
||||
@@ -80,7 +81,20 @@ export class ServerSettingsService extends Context.Service<
|
||||
getSettings: Ref.get(currentSettingsRef),
|
||||
updateSettings: (patch) =>
|
||||
Ref.get(currentSettingsRef).pipe(
|
||||
Effect.map((currentSettings) => deepMerge(currentSettings, patch)),
|
||||
Effect.flatMap((currentSettings) =>
|
||||
Schema.decodeEffect(ServerSettings)(
|
||||
applyServerSettingsPatch(currentSettings, patch),
|
||||
).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new ServerSettingsError({
|
||||
settingsPath: "<memory>",
|
||||
detail: `failed to normalize server settings: ${SchemaIssue.makeFormatterDefault()(cause.issue)}`,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
Effect.tap((nextSettings) => Ref.set(currentSettingsRef, nextSettings)),
|
||||
),
|
||||
streamChanges: Stream.empty,
|
||||
@@ -314,7 +328,9 @@ const makeServerSettings = Effect.gen(function* () {
|
||||
writeSemaphore.withPermits(1)(
|
||||
Effect.gen(function* () {
|
||||
const current = yield* getSettingsFromCache;
|
||||
const next = yield* Schema.decodeEffect(ServerSettings)(deepMerge(current, patch)).pipe(
|
||||
const next = yield* Schema.decodeEffect(ServerSettings)(
|
||||
applyServerSettingsPatch(current, patch),
|
||||
).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new ServerSettingsError({
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
} from "@t3tools/contracts/settings";
|
||||
import { ensureLocalApi } from "~/localApi";
|
||||
import { Struct } from "effect";
|
||||
import { deepMerge } from "@t3tools/shared/Struct";
|
||||
import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
|
||||
import { applySettingsUpdated, getServerConfig, useServerSettings } from "~/rpc/serverState";
|
||||
|
||||
const CLIENT_SETTINGS_PERSISTENCE_ERROR_SCOPE = "[CLIENT_SETTINGS]";
|
||||
@@ -154,7 +154,7 @@ export function useUpdateSettings() {
|
||||
if (Object.keys(serverPatch).length > 0) {
|
||||
const currentServerConfig = getServerConfig();
|
||||
if (currentServerConfig) {
|
||||
applySettingsUpdated(deepMerge(currentServerConfig.settings, serverPatch));
|
||||
applySettingsUpdated(applyServerSettingsPatch(currentServerConfig.settings, serverPatch));
|
||||
}
|
||||
// Fire-and-forget RPC — push will reconcile on success
|
||||
void ensureLocalApi().server.updateSettings(serverPatch);
|
||||
|
||||
Reference in new issue
Block a user