From 24bf4d488acabad808b5374fc7fa26893f4c5e42 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Tue, 27 Oct 2026 11:45:08 -0500 Subject: [PATCH] fix(core): keep prompt cache settings out of model variants (#59500) --- .../client/src/promise/generated/types.ts | 56 +++++++++++-------- packages/core/src/model-resolver.ts | 6 +- packages/protocol/openapi.json | 45 ++++++++++++++- packages/schema/src/config/provider.ts | 9 ++- packages/schema/src/model.ts | 7 +++ 5 files changed, 95 insertions(+), 28 deletions(-) diff --git a/packages/client/src/promise/generated/types.ts b/packages/client/src/promise/generated/types.ts index 9d4db667f96..f5db7ce7e53 100644 --- a/packages/client/src/promise/generated/types.ts +++ b/packages/client/src/promise/generated/types.ts @@ -369,6 +369,14 @@ export type ModelRef = { id: string; providerID: ProviderID; variant?: string } export type ProviderCache = { ttl?: ProviderCacheTTL } +export type ModelVariantSettings = { compaction?: ProviderCompaction; encoding?: ProviderEncoding } & { + [x: string]: any +} + +export type ConfigModelVariantSettings = { compaction?: ProviderCompaction; encoding?: ProviderEncoding } & { + [x: string]: JsonValue | null +} + export type PermissionRule = { action: string; resource: string; effect: PermissionEffect } export type PluginInfo = { id?: PluginID; source: PluginSource; features: PluginFeatures; state: PluginState } @@ -982,6 +990,13 @@ export type ConfigModelSettings = { encoding?: ProviderEncoding } & { [x: string]: JsonValue | null } +export type ModelVariant = { + id: string + settings?: ModelVariantSettings + headers?: { [x: string]: string } + body?: { [x: string]: any } +} + export type PermissionRuleset = Array export type UsageLimitsBudget = { @@ -2163,11 +2178,26 @@ export type ProviderInfo = { body?: { [x: string]: any } } -export type ModelVariant = { +export type ModelInfo = { id: string + modelID: string + providerID: ProviderID + canonical?: ProviderID + type?: ModelType + family?: string + name: string + compatibility?: ModelCompatibility + package?: string settings?: ModelSettings headers?: { [x: string]: string } body?: { [x: string]: any } + capabilities: ModelCapabilities + variants: Array + time: { released: number } + cost: Array + status: "alpha" | "beta" | "deprecated" | "active" + enabled: boolean + limit: { context: number; input?: number; output: number } } export type SessionInfo = { @@ -2367,7 +2397,7 @@ export type ConfigEntry = capabilities?: ConfigModelCapabilities variants?: Array<{ id: string - settings?: ConfigModelSettings + settings?: ConfigModelVariantSettings headers?: { [x: string]: string } body?: { [x: string]: JsonValue } }> @@ -2491,28 +2521,6 @@ export type AgentInfo = { permissions: PermissionRuleset } -export type ModelInfo = { - id: string - modelID: string - providerID: ProviderID - canonical?: ProviderID - type?: ModelType - family?: string - name: string - compatibility?: ModelCompatibility - package?: string - settings?: ModelSettings - headers?: { [x: string]: string } - body?: { [x: string]: any } - capabilities: ModelCapabilities - variants: Array - time: { released: number } - cost: Array - status: "alpha" | "beta" | "deprecated" | "active" - enabled: boolean - limit: { context: number; input?: number; output: number } -} - export type SessionsResponse = { data: Array cursor: { previous?: SessionsCursor | null; next?: SessionsCursor | null } diff --git a/packages/core/src/model-resolver.ts b/packages/core/src/model-resolver.ts index 1bf02798fdf..a2b32c0dc21 100644 --- a/packages/core/src/model-resolver.ts +++ b/packages/core/src/model-resolver.ts @@ -175,7 +175,11 @@ export const withVariant = ( variant ? { ...model, - settings: Provider.mergeOverlay(model.settings, Provider.modelSettings(variant.settings)), + // Config accepts unknown variant keys, so drop `cache` here too; a variant can't change the prompt cache. + settings: Provider.mergeOverlay( + model.settings, + Provider.modelSettings(variant.settings && Struct.omit(variant.settings, ["cache"])), + ), headers: Provider.mergeHeaders(model.headers, variant.headers), body: Provider.mergeOverlay(model.body, variant.body), } diff --git a/packages/protocol/openapi.json b/packages/protocol/openapi.json index 3992529b5d6..1789c459277 100644 --- a/packages/protocol/openapi.json +++ b/packages/protocol/openapi.json @@ -16000,6 +16000,30 @@ } ] }, + "Config.Model.VariantSettings": { + "type": "object", + "properties": { + "compaction": { + "$ref": "#/components/schemas/Provider.Compaction" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" + } + }, + "allOf": [ + { + "type": "object", + "additionalProperties": { + "anyOf": [ + {}, + { + "type": "null" + } + ] + } + } + ] + }, "Config.ModelEncoded": { "type": "object", "properties": { @@ -16050,7 +16074,7 @@ "type": "string" }, "settings": { - "$ref": "#/components/schemas/Config.Model.Settings" + "$ref": "#/components/schemas/Config.Model.VariantSettings" }, "headers": { "type": "object", @@ -19205,7 +19229,7 @@ "type": "string" }, "settings": { - "$ref": "#/components/schemas/Model.Settings" + "$ref": "#/components/schemas/Model.VariantSettings" }, "headers": { "type": "object", @@ -19220,6 +19244,23 @@ "required": ["id"], "additionalProperties": false }, + "Model.VariantSettings": { + "type": "object", + "properties": { + "compaction": { + "$ref": "#/components/schemas/Provider.Compaction" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" + } + }, + "allOf": [ + { + "type": "object", + "additionalProperties": {} + } + ] + }, "ModelNotFoundErrorEncoded": { "type": "object", "properties": { diff --git a/packages/schema/src/config/provider.ts b/packages/schema/src/config/provider.ts index 11befcabb86..e0c1f8d4fdb 100644 --- a/packages/schema/src/config/provider.ts +++ b/packages/schema/src/config/provider.ts @@ -1,6 +1,6 @@ export * as ConfigProvider from "./provider.js" -import { Schema } from "effect" +import { Schema, Struct } from "effect" import { Money } from "../money.js" import { Capabilities, Compatibility, Family, ID, Model, Type, VariantID } from "../model.js" import { ProviderCompatibility } from "../model-compatibility.js" @@ -96,6 +96,13 @@ class ModelConfig extends Schema.Class("Config.Model")({ variants: Schema.Struct({ id: VariantID, ...ModelOverlays, + // The prompt cache belongs to the model, so a variant can't change it. + settings: Schema.StructWithRest( + Schema.Struct(Struct.omit(ModelSettings.schema.fields, ["cache"])), + ModelSettings.records, + ) + .annotate({ identifier: "Config.Model.VariantSettings" }) + .pipe(optional), }).pipe(Schema.Array, optional), cost: Schema.Union([Cost, Cost.pipe(Schema.Array)]).pipe(optional), disabled: Schema.Boolean.pipe(optional), diff --git a/packages/schema/src/model.ts b/packages/schema/src/model.ts index 03873c91eac..8d198338b1f 100644 --- a/packages/schema/src/model.ts +++ b/packages/schema/src/model.ts @@ -62,6 +62,12 @@ export const Settings = Schema.StructWithRest( ).annotate({ identifier: "Model.Settings" }) export type Settings = typeof Settings.Type +// Variants switch request settings. The prompt cache belongs to the model, so a variant can't change it. +const VariantSettings = Schema.StructWithRest( + Schema.Struct(Struct.omit(Settings.schema.fields, ["cache"])), + Settings.records, +).annotate({ identifier: "Model.VariantSettings" }) + export const Overlays = { settings: Settings.pipe(optional), headers: Schema.Record(Schema.String, Schema.String).pipe(optional), @@ -101,6 +107,7 @@ export interface Variant extends Schema.Schema.Type {} export const Variant = Schema.Struct({ id: VariantID, ...Overlays, + settings: VariantSettings.pipe(optional), }).annotate({ identifier: "Model.Variant" }) export interface Info extends Schema.Schema.Type {}