Repository navigation
feat: add setting for provider/model-specific parameters #6649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
5712364
44d501a
9cd18bf
4bc8cde
8c66807
e135594
bca5485
f5ba160
da4ca30
0f319ac
00ac985
3f42b1f
f19e2ff
d776002
aa1c9e3
1324dc5
e01ed7f
964ac81
2a97832
7f9aa3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,16 @@ import { | |||||||||||||||||
| normalizeAnthropicHeaderVariants, | ||||||||||||||||||
| } from "../config/anthropicHeaders.ts"; | ||||||||||||||||||
| import { applyContextEditingToBody } from "../config/contextEditing.ts"; | ||||||||||||||||||
| import { findOffendingField, stripGroqUnsupportedFields } from "../config/providerFieldStrips.ts"; | ||||||||||||||||||
| import { | ||||||||||||||||||
| findOffendingField, | ||||||||||||||||||
| detectUnsupportedParam, | ||||||||||||||||||
| stripGroqUnsupportedFields, | ||||||||||||||||||
| } from "../config/providerFieldStrips.ts"; | ||||||||||||||||||
| import { | ||||||||||||||||||
| getParamFilterConfig, | ||||||||||||||||||
| addParamToBlocklist, | ||||||||||||||||||
| isAutoLearnGloballyEnabled, | ||||||||||||||||||
| } from "@/lib/db/paramFilters"; | ||||||||||||||||||
| import { applyFingerprint, isCliCompatEnabled } from "../config/cliFingerprints.ts"; | ||||||||||||||||||
| import { supportsClaudeMaxEffort, supportsXHighEffort } from "../config/providerModels.ts"; | ||||||||||||||||||
| import { getThinkingBudgetConfig, ThinkingMode } from "../services/thinkingBudget.ts"; | ||||||||||||||||||
|
|
@@ -1261,6 +1270,39 @@ export class BaseExecutor { | |||||||||||||||||
| `Upstream 400 rejected ${offending} on ${url} — retrying without it` | ||||||||||||||||||
| ); | ||||||||||||||||||
| response = await fetchWithStartTimeout(url, { ...fetchOptions, body: retryBody }); | ||||||||||||||||||
| } else { | ||||||||||||||||||
| // Auto-learn: detect "Unsupported parameter" errors and persist to DB | ||||||||||||||||||
| // when the provider config has autoLearn enabled (#6625). | ||||||||||||||||||
| const autoLearned = detectUnsupportedParam(errText); | ||||||||||||||||||
| if ( | ||||||||||||||||||
| autoLearned && | ||||||||||||||||||
| !strippedFields.has(autoLearned) && | ||||||||||||||||||
| (transformedBody as Record<string, unknown>)[autoLearned] !== undefined | ||||||||||||||||||
| ) { | ||||||||||||||||||
| try { | ||||||||||||||||||
| const config = getParamFilterConfig(this.provider); | ||||||||||||||||||
| const shouldAutoLearn = isAutoLearnGloballyEnabled() || config?.autoLearn === true; | ||||||||||||||||||
| if (shouldAutoLearn) { | ||||||||||||||||||
| strippedFields.add(autoLearned); | ||||||||||||||||||
| addParamToBlocklist(this.provider, autoLearned); | ||||||||||||||||||
| delete (transformedBody as Record<string, unknown>)[autoLearned]; | ||||||||||||||||||
| let retryBody = JSON.stringify(transformedBody); | ||||||||||||||||||
| if (isClaudeCodeCompatible(this.provider) || this.provider === "claude") { | ||||||||||||||||||
| retryBody = await signRequestBody(retryBody); | ||||||||||||||||||
| } | ||||||||||||||||||
| log?.info?.( | ||||||||||||||||||
| "AUTO_LEARN", | ||||||||||||||||||
| `Auto-learned "${autoLearned}" for provider ${this.provider} from 400 on ${url} — retrying` | ||||||||||||||||||
| ); | ||||||||||||||||||
|
Comment on lines
+1293
to
+1296
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the log message to include the model name so that operators can easily see which specific model triggered the auto-learning behavior.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 0f319ac. Log message now includes model: |
||||||||||||||||||
| response = await fetchWithStartTimeout(url, { ...fetchOptions, body: retryBody }); | ||||||||||||||||||
| } | ||||||||||||||||||
| } catch (learnError) { | ||||||||||||||||||
| log?.warn?.( | ||||||||||||||||||
| "AUTO_LEARN", | ||||||||||||||||||
| `Failed to persist auto-learned param "${autoLearned}" for ${this.provider}: ${String(learnError)}` | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ | |
| // introduces new keys and never throws on null/undefined bodies — call sites | ||
| // can chain it without extra guards. | ||
|
|
||
| import { getParamFilterConfig } from "@/lib/db/paramFilters"; | ||
|
|
||
| type StripRule = { | ||
| provider?: string; | ||
| match: RegExp | ((model: string) => boolean); | ||
|
|
@@ -56,15 +58,77 @@ export function stripUnsupportedParams<T>( | |
| ): T { | ||
| if (!model || !body || typeof body !== "object") return body; | ||
| const rec = body as unknown as Record<string, unknown>; | ||
| // Snapshot the original body before any mutations so the allowlist can | ||
| // restore params that were stripped by hardcoded or config-driven denylist. | ||
| const snapshot = { ...rec }; | ||
|
|
||
| // Phase 1: Hardcoded rules (unchanged) | ||
| for (const rule of STRIP_RULES) { | ||
| if (rule.provider && rule.provider !== provider) continue; | ||
| if (!matches(rule, model)) continue; | ||
| for (const key of rule.drop) { | ||
| if (rec[key] !== undefined) delete rec[key]; | ||
| } | ||
| } | ||
|
|
||
| // Phase 2: Config-driven rules from DB | ||
| applyConfigFilters(provider, model, rec, snapshot); | ||
|
|
||
| return body; | ||
| } | ||
|
|
||
| /** | ||
| * Apply config-driven denylist + allowlist rules from the DB-backed | ||
| * ProviderParamFilter store. Order of operations: | ||
| * 1. Provider-level denylist | ||
| * 2. Model-level denylist | ||
| * 3. Provider-level allowlist (restores from snapshot) | ||
| * 4. Model-level allowlist (restores from snapshot) | ||
| * | ||
| * The allowlist only restores keys that were present in the original request | ||
| * (the snapshot). It never introduces new params the client didn't send. | ||
| */ | ||
| export function applyConfigFilters( | ||
| provider: string | null | undefined, | ||
| model: string | null | undefined, | ||
| body: Record<string, unknown>, | ||
| snapshot: Record<string, unknown> | ||
| ): void { | ||
| if (!provider || !body) return; | ||
| const config = getParamFilterConfig(provider); | ||
| if (!config) return; | ||
|
|
||
| // 1. Provider-level denylist | ||
| for (const key of config.block) { | ||
| delete body[key]; | ||
| } | ||
|
|
||
| // 2. Model-level denylist | ||
| const modelCfg = config.models?.[model ?? ""]; | ||
| if (modelCfg?.block) { | ||
| for (const key of modelCfg.block) { | ||
| delete body[key]; | ||
| } | ||
| } | ||
|
|
||
| // 3. Provider-level allowlist — restore from snapshot if key existed in original | ||
| if (config.allow.length > 0) { | ||
| for (const key of config.allow) { | ||
| if (key in snapshot) { | ||
| body[key] = snapshot[key]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // 4. Model-level allowlist | ||
| if (modelCfg?.allow) { | ||
| for (const key of modelCfg.allow) { | ||
| if (key in snapshot) { | ||
| body[key] = snapshot[key]; | ||
| } | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current order of operations applies all denylists first, followed by all allowlists:
This creates a bug where a provider-level allowlist (step 3) will restore a parameter that was explicitly blocked by a more specific model-level denylist (step 2). Model-level configurations are more specific and should always take precedence over provider-level configurations. The correct hierarchical order of operations should be:
This ensures that model-level denylists can successfully override provider-level allowlists. // 1. Provider-level denylist
for (const key of config.block) {
delete body[key];
}
// 2. Provider-level allowlist — restore from snapshot if key existed in original
if (config.allow.length > 0) {
for (const key of config.allow) {
if (key in snapshot) {
body[key] = snapshot[key];
}
}
}
// 3. Model-level denylist
const modelCfg = config.models?.[model ?? ""];
if (modelCfg?.block) {
for (const key of modelCfg.block) {
delete body[key];
}
}
// 4. Model-level allowlist
if (modelCfg?.allow) {
for (const key of modelCfg.allow) {
if (key in snapshot) {
body[key] = snapshot[key];
}
}
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 0f319ac. Reordered applyConfigFilters so model-level operations run AFTER provider-level operations:
Added regression test verifying model denylist beats provider allowlist. |
||
| } | ||
|
|
||
| // Exported for unit tests only — do not import from production code. | ||
| export const __STRIP_RULES_FOR_TEST: ReadonlyArray<StripRule> = STRIP_RULES; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When auto-learning an unsupported parameter, it is currently added to the provider-level blocklist globally.
For multi-model providers (such as NVIDIA NIM, Groq, or OpenRouter), different models have completely different parameter support. Auto-learning a parameter at the provider level because one model rejected it will incorrectly strip that parameter from other models under the same provider that actually support it.
Since
addParamToBlocklistsupports amodelparameter, andmodelis available in the execution context, we should scope the auto-learned parameter to the specific model.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0f319ac. Changed
addParamToBlocklist(this.provider, autoLearned)toaddParamToBlocklist(this.provider, autoLearned, model)so auto-learn scopes to the specific model that triggered the 400, preventing provider-level pollution.