Skip to content

Commit c6bac61

Browse files
committed
fix(relaykit): make the thinking suffix adapter toggle cover effort suffixes
With the Claude or Gemini thinking suffix adapter switched off, the parser still stripped effort tails such as -high from claude-* and gemini-* model names and injected thinking parameters upstream; only the -thinking family honoured the toggle. Gate every alias on the same flag so a disabled adapter sends the model name verbatim, rename the parameter to allowSuffixAlias, correct the ThinkingAdapterEnabled doc comments, and spell out the covered suffixes and the off behaviour in both settings cards.
1 parent 9560191 commit c6bac61

13 files changed

Lines changed: 105 additions & 57 deletions

File tree

‎relay/helper/reasoning_suffix_test.go‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,27 @@ func TestApplyReasoningModelSuffixGeminiNoThinkingWhenAdapterEnabled(t *testing.
161161
assert.Equal(t, "none", info.ReasoningConversion.Effort)
162162
}
163163

164+
func TestApplyReasoningModelSuffixClaudeEffortTailKeptWhenAdapterDisabled(t *testing.T) {
165+
settings := model_setting.GetClaudeSettings()
166+
original := settings.ThinkingAdapterEnabled
167+
t.Cleanup(func() { settings.ThinkingAdapterEnabled = original })
168+
settings.ThinkingAdapterEnabled = false
169+
170+
req := &dto.ClaudeRequest{Model: "claude-opus-5-5-high"}
171+
info := &relaycommon.RelayInfo{
172+
OriginModelName: "claude-opus-5-5-high",
173+
Request: req,
174+
ChannelMeta: &relaycommon.ChannelMeta{
175+
UpstreamModelName: "claude-opus-5-5-high",
176+
},
177+
}
178+
179+
mustApplyReasoningModelSuffix(t, info, req)
180+
assert.Equal(t, "claude-opus-5-5-high", info.UpstreamModelName)
181+
assert.Equal(t, "claude-opus-5-5-high", req.Model)
182+
assert.Nil(t, info.ReasoningConversion)
183+
}
184+
164185
func TestApplyReasoningModelSuffixPreservesEffortTailModelID(t *testing.T) {
165186
info := &relaycommon.RelayInfo{
166187
OriginModelName: "qwen-max",

‎relaykit/relayconvert/convmeta/options.go‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ type Options struct {
3434
}
3535

3636
type ClaudeOptions struct {
37-
// ThinkingAdapterEnabled controls whether suffix-derived reasoning intent
38-
// is rendered onto Claude thinking / output_config. Suffix parsing itself
39-
// is the host entry layer's job (standalone users call Parse* themselves).
37+
// ThinkingAdapterEnabled is the host thinking-suffix adapter toggle. The
38+
// host passes it to reasoning.ParseClaudeModelSuffix, so -thinking,
39+
// -nothinking, -thinking-<budget>, and effort tails such as -high on
40+
// claude-* names become reasoning intent only while it is on; when off the
41+
// model name is sent verbatim. Explicit @ modifiers are unaffected. Suffix
42+
// parsing itself is the host entry layer's job (standalone users call
43+
// Parse* themselves).
4044
ThinkingAdapterEnabled bool
4145
// ThinkingAdapterBudgetTokensPercentage sizes thinking budget_tokens as a
4246
// fraction of max_tokens when the adapter fires.
@@ -57,9 +61,12 @@ type ClaudeOptions struct {
5761
}
5862

5963
type GeminiOptions struct {
60-
// ThinkingAdapterEnabled controls whether suffix-derived reasoning intent
61-
// is rendered onto Gemini thinkingConfig. Suffix parsing itself is the
62-
// host entry layer's job (standalone users call Parse* themselves).
64+
// ThinkingAdapterEnabled is the host thinking-suffix adapter toggle. The
65+
// host and gemini_chat request conversion pass it to
66+
// reasoning.ParseGeminiModelSuffix, so -thinking, -nothinking,
67+
// -thinking-<budget>, and effort tails such as -high on gemini-* names
68+
// become reasoning intent only while it is on; when off the model name is
69+
// sent verbatim. Explicit @ modifiers are unaffected.
6370
ThinkingAdapterEnabled bool
6471
// ThinkingAdapterBudgetTokensPercentage sizes thinkingBudget as a fraction
6572
// of maxOutputTokens when the adapter fires.

‎relaykit/relayconvert/reasoning/suffix.go‎

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,16 @@ func ParseOpenAIReasoningEffortFromModelSuffix(modelName string, preserveEffortT
136136
return effort, baseModel
137137
}
138138

139-
func ParseClaudeModelSuffix(modelName string, allowThinkingAlias bool) (string, Intent, bool, error) {
139+
// ParseClaudeModelSuffix folds the naked claude-* aliases (-thinking,
140+
// -nothinking, -thinking-<budget>, and effort tails such as -high) into an
141+
// Intent. allowSuffixAlias is the host thinking-adapter toggle; when false the
142+
// name is returned verbatim and no intent is produced.
143+
func ParseClaudeModelSuffix(modelName string, allowSuffixAlias bool) (string, Intent, bool, error) {
140144
prefix, bare := splitModelNamespace(modelName)
141145
if !strings.HasPrefix(bare, "claude-") {
142146
return modelName, Intent{}, false, nil
143147
}
144-
base, intent, found, err := parseProviderModelSuffix(bare, "claude-", allowThinkingAlias, true)
148+
base, intent, found, err := parseProviderModelSuffix(bare, "claude-", allowSuffixAlias, true)
145149
if err != nil || !found || !legacyClaudeModelPattern.MatchString(base) {
146150
return modelName, Intent{}, false, err
147151
}
@@ -171,12 +175,14 @@ func isKnownClaudeModel(modelName string) bool {
171175
return false
172176
}
173177

174-
func ParseGeminiModelSuffix(modelName string, allowThinkingAlias bool) (string, Intent, bool, error) {
178+
// ParseGeminiModelSuffix is the gemini-* counterpart of ParseClaudeModelSuffix
179+
// and honours allowSuffixAlias the same way.
180+
func ParseGeminiModelSuffix(modelName string, allowSuffixAlias bool) (string, Intent, bool, error) {
175181
prefix, bare := splitModelNamespace(modelName)
176182
if !strings.HasPrefix(bare, "gemini-") {
177183
return modelName, Intent{}, false, nil
178184
}
179-
base, intent, found, err := parseProviderModelSuffix(bare, "gemini-", allowThinkingAlias, true)
185+
base, intent, found, err := parseProviderModelSuffix(bare, "gemini-", allowSuffixAlias, true)
180186
if err != nil || !found || !legacyGeminiModelPattern.MatchString(base) {
181187
return modelName, Intent{}, false, err
182188
}
@@ -186,13 +192,13 @@ func ParseGeminiModelSuffix(modelName string, allowThinkingAlias bool) (string,
186192
// ParseKnownProviderModelSuffix extracts a canonical intent only when the
187193
// origin identifies a provider family whose suffix vocabulary is defined by
188194
// relaykit. Unknown OpenAI-compatible model names are deliberately untouched.
189-
func ParseKnownProviderModelSuffix(modelName string, allowThinkingAlias bool) (string, Intent, bool, error) {
195+
func ParseKnownProviderModelSuffix(modelName string, allowSuffixAlias bool) (string, Intent, bool, error) {
190196
bare := lastModelPathSegment(modelName)
191197
if strings.HasPrefix(bare, "claude-") {
192-
return ParseClaudeModelSuffix(modelName, allowThinkingAlias)
198+
return ParseClaudeModelSuffix(modelName, allowSuffixAlias)
193199
}
194200
if strings.HasPrefix(bare, "gemini-") {
195-
return ParseGeminiModelSuffix(modelName, allowThinkingAlias)
201+
return ParseGeminiModelSuffix(modelName, allowSuffixAlias)
196202
}
197203
return modelName, Intent{}, false, nil
198204
}
@@ -214,37 +220,39 @@ func TrimGeminiThinkingSuffix(modelName string) (string, bool) {
214220
return baseModel, ok && err == nil
215221
}
216222

217-
func parseProviderModelSuffix(modelName string, requiredPrefix string, allowThinkingAlias bool, includeThoughts bool) (string, Intent, bool, error) {
218-
if allowThinkingAlias {
219-
if marker := strings.LastIndex(modelName, "-thinking-"); marker >= 0 {
220-
baseModel := modelName[:marker]
221-
if !strings.HasPrefix(baseModel, requiredPrefix) {
222-
return modelName, Intent{}, false, nil
223-
}
224-
budget, err := strconv.Atoi(modelName[marker+len("-thinking-"):])
225-
if err != nil {
226-
return modelName, Intent{}, false, fmt.Errorf("invalid thinking budget suffix on model %q: %w", modelName, err)
227-
}
228-
intent := Intent{BudgetTokens: &budget, Source: SourceSuffix, BudgetSource: SourceSuffix}
229-
if includeThoughts {
230-
value := true
231-
intent.IncludeThoughts = &value
232-
}
233-
return baseModel, intent, true, nil
223+
// parseProviderModelSuffix recognises a provider family's naked model-name
224+
// aliases. allowSuffixAlias gates all of them, including effort tails, so a
225+
// disabled thinking adapter leaves the model name untouched.
226+
func parseProviderModelSuffix(modelName string, requiredPrefix string, allowSuffixAlias bool, includeThoughts bool) (string, Intent, bool, error) {
227+
if !allowSuffixAlias {
228+
return modelName, Intent{}, false, nil
229+
}
230+
if marker := strings.LastIndex(modelName, "-thinking-"); marker >= 0 {
231+
baseModel := modelName[:marker]
232+
if !strings.HasPrefix(baseModel, requiredPrefix) {
233+
return modelName, Intent{}, false, nil
234+
}
235+
budget, err := strconv.Atoi(modelName[marker+len("-thinking-"):])
236+
if err != nil {
237+
return modelName, Intent{}, false, fmt.Errorf("invalid thinking budget suffix on model %q: %w", modelName, err)
234238
}
235-
if before, ok := strings.CutSuffix(modelName, "-nothinking"); ok {
236-
baseModel := before
237-
return baseModel, Intent{Mode: ModeDisabled, Effort: EffortNone, Source: SourceSuffix}, true, nil
239+
intent := Intent{BudgetTokens: &budget, Source: SourceSuffix, BudgetSource: SourceSuffix}
240+
if includeThoughts {
241+
value := true
242+
intent.IncludeThoughts = &value
238243
}
239-
if before, ok := strings.CutSuffix(modelName, "-thinking"); ok {
240-
baseModel := before
241-
intent := Intent{Mode: ModeEnabled, Source: SourceSuffix}
242-
if includeThoughts {
243-
value := true
244-
intent.IncludeThoughts = &value
245-
}
246-
return baseModel, intent, true, nil
244+
return baseModel, intent, true, nil
245+
}
246+
if baseModel, ok := strings.CutSuffix(modelName, "-nothinking"); ok {
247+
return baseModel, Intent{Mode: ModeDisabled, Effort: EffortNone, Source: SourceSuffix}, true, nil
248+
}
249+
if baseModel, ok := strings.CutSuffix(modelName, "-thinking"); ok {
250+
intent := Intent{Mode: ModeEnabled, Source: SourceSuffix}
251+
if includeThoughts {
252+
value := true
253+
intent.IncludeThoughts = &value
247254
}
255+
return baseModel, intent, true, nil
248256
}
249257

250258
suffixes := []string{"-max", "-xhigh", "-high", "-medium", "-low", "-minimal", "-none"}

‎relaykit/relayconvert/reasoning/suffix_test.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ func TestParseKnownProviderModelSuffix(t *testing.T) {
6969
wantMode: ModeEnabled,
7070
wantEffort: EffortHigh,
7171
},
72+
{
73+
name: "claude effort tail kept when adapter is off",
74+
model: "claude-opus-5-5-high",
75+
wantBase: "claude-opus-5-5-high",
76+
wantFound: false,
77+
},
78+
{
79+
name: "gemini effort tail kept when adapter is off",
80+
model: "gemini-2.5-flash-high",
81+
wantBase: "gemini-2.5-flash-high",
82+
wantFound: false,
83+
},
7284
{
7385
name: "gemini thinking alias",
7486
model: "gemini-2.5-flash-thinking",

‎web/src/features/system-settings/models/claude-settings-card.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export function ClaudeSettingsCard({ defaultValues }: ClaudeSettingsCardProps) {
254254
<FormLabel>{t('Thinking Suffix Adapter')}</FormLabel>
255255
<FormDescription>
256256
{t(
257-
'Adapt `-thinking` suffix requests to Anthropic native thinking behavior while keeping billing predictable.'
257+
'Adapt `-thinking`, `-nothinking`, and effort suffixes such as `-high` to Anthropic native thinking behavior while keeping billing predictable. When off, model names are sent upstream unchanged.'
258258
)}
259259
</FormDescription>
260260
</SettingsSwitchContent>

‎web/src/features/system-settings/models/gemini-settings-card.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export function GeminiSettingsCard({ defaultValues }: GeminiSettingsCardProps) {
339339
{t('Supports `-thinking`, `-thinking-')}
340340
{'{{budget}}'}
341341
{t(
342-
'`, and `-nothinking` suffixes while routing to the correct Gemini variant.'
342+
'`, `-nothinking`, and effort suffixes such as `-high` while routing to the correct Gemini variant. When off, model names are sent upstream unchanged.'
343343
)}
344344
</FormDescription>
345345
</SettingsSwitchContent>

‎web/src/i18n/locales/en.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"#1 by usage": "#1 by usage",
117117
"#1 Model": "#1 Model",
118118
"% off": "% off",
119-
"`, and `-nothinking` suffixes while routing to the correct Gemini variant.": "`, and `-nothinking` suffixes while routing to the correct Gemini variant.",
119+
"`, `-nothinking`, and effort suffixes such as `-high` while routing to the correct Gemini variant. When off, model names are sent upstream unchanged.": "`, `-nothinking`, and effort suffixes such as `-high` while routing to the correct Gemini variant. When off, model names are sent upstream unchanged.",
120120
"© 2025 Your Company. All rights reserved.": "© 2025 Your Company. All rights reserved.",
121121
"+{{count}} more": "+{{count}} more",
122122
"| Based on": "| Based on",
@@ -243,7 +243,7 @@
243243
"Actual Amount": "Actual Amount",
244244
"Actual Model": "Actual Model",
245245
"Actual Model:": "Actual Model:",
246-
"Adapt `-thinking` suffix requests to Anthropic native thinking behavior while keeping billing predictable.": "Adapt `-thinking` suffix requests to Anthropic native thinking behavior while keeping billing predictable.",
246+
"Adapt `-thinking`, `-nothinking`, and effort suffixes such as `-high` to Anthropic native thinking behavior while keeping billing predictable. When off, model names are sent upstream unchanged.": "Adapt `-thinking`, `-nothinking`, and effort suffixes such as `-high` to Anthropic native thinking behavior while keeping billing predictable. When off, model names are sent upstream unchanged.",
247247
"Add": "Add",
248248
"Add \"{{value}}\"": "Add \"{{value}}\"",
249249
"Add {{added}} models and remove {{removed}} models": "Add {{added}} models and remove {{removed}} models",

‎web/src/i18n/locales/fr.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"#1 by usage": "N° 1 d'utilisation",
117117
"#1 Model": "#1 Modèle",
118118
"% off": "% de réduction",
119-
"`, and `-nothinking` suffixes while routing to the correct Gemini variant.": "`, et les suffixes `-nothinking` lors du routage vers la variante Gemini correcte.",
119+
"`, `-nothinking`, and effort suffixes such as `-high` while routing to the correct Gemini variant. When off, model names are sent upstream unchanged.": "`, `-nothinking` et les suffixes d’effort tels que `-high` lors du routage vers la variante Gemini correcte. Désactivé, les noms de modèle sont envoyés en amont tels quels.",
120120
"© 2025 Your Company. All rights reserved.": "© 2025 Votre entreprise. Tous droits réservés.",
121121
"+{{count}} more": "+{{count}} de plus",
122122
"| Based on": "| Basé sur",
@@ -243,7 +243,7 @@
243243
"Actual Amount": "Montant réel",
244244
"Actual Model": "Modèle réel",
245245
"Actual Model:": "Modèle réel :",
246-
"Adapt `-thinking` suffix requests to Anthropic native thinking behavior while keeping billing predictable.": "Adapter les requêtes avec le suffixe `-thinking` au comportement de pensée natif d’Anthropic tout en gardant une facturation prévisible.",
246+
"Adapt `-thinking`, `-nothinking`, and effort suffixes such as `-high` to Anthropic native thinking behavior while keeping billing predictable. When off, model names are sent upstream unchanged.": "Adapter les requêtes avec les suffixes `-thinking`, `-nothinking` et les suffixes d’effort tels que `-high` au comportement de pensée natif d’Anthropic tout en gardant une facturation prévisible. Désactivé, les noms de modèle sont envoyés en amont tels quels.",
247247
"Add": "Ajouter",
248248
"Add \"{{value}}\"": "Ajouter \"{{value}}\"",
249249
"Add {{added}} models and remove {{removed}} models": "Ajouter {{added}} modèles et en retirer {{removed}}",

‎web/src/i18n/locales/ja.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"#1 by usage": "利用量1位",
117117
"#1 Model": "#1 モデル",
118118
"% off": "% OFF",
119-
"`, and `-nothinking` suffixes while routing to the correct Gemini variant.": "`, および `-nothinking` サフィックスを、正しい Gemini バリアントにルーティングする際に使用します。",
119+
"`, `-nothinking`, and effort suffixes such as `-high` while routing to the correct Gemini variant. When off, model names are sent upstream unchanged.": "`、`-nothinking`、および `-high` などの推論強度サフィックスを、正しい Gemini バリアントにルーティングする際に使用します。オフの場合、モデル名はそのまま上流に送信されます。",
120120
"© 2025 Your Company. All rights reserved.": "© 2025 Your Company. 全著作権所有。",
121121
"+{{count}} more": "他 {{count}} 件",
122122
"| Based on": "| に基づく",
@@ -243,7 +243,7 @@
243243
"Actual Amount": "実際の金額",
244244
"Actual Model": "実際のモデル",
245245
"Actual Model:": "実際のモデル:",
246-
"Adapt `-thinking` suffix requests to Anthropic native thinking behavior while keeping billing predictable.": "`-thinking` サフィックス付きリクエストを Anthropic ネイティブの思考動作に適配し、課金を予測可能に保ちます。",
246+
"Adapt `-thinking`, `-nothinking`, and effort suffixes such as `-high` to Anthropic native thinking behavior while keeping billing predictable. When off, model names are sent upstream unchanged.": "`-thinking`、`-nothinking`、および `-high` などの推論強度サフィックス付きリクエストを Anthropic ネイティブの思考動作に適配し、課金を予測可能に保ちます。オフの場合、モデル名はそのまま上流に送信されます。",
247247
"Add": "追加",
248248
"Add \"{{value}}\"": "\"{{value}}\" を追加",
249249
"Add {{added}} models and remove {{removed}} models": "{{added}} 個のモデルを追加、{{removed}} 個を削除",

‎web/src/i18n/locales/ru.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"#1 by usage": "№1 по использованию",
117117
"#1 Model": "#1 Модель",
118118
"% off": "скидка",
119-
"`, and `-nothinking` suffixes while routing to the correct Gemini variant.": "суффиксы `, и `-nothinking` при маршрутизации к правильному варианту Gemini.",
119+
"`, `-nothinking`, and effort suffixes such as `-high` while routing to the correct Gemini variant. When off, model names are sent upstream unchanged.": "суффиксы `, `-nothinking` и суффиксы усилия, такие как `-high`, при маршрутизации к правильному варианту Gemini. При отключении имена моделей отправляются вверх по потоку без изменений.",
120120
"© 2025 Your Company. All rights reserved.": "© 2025 Ваша Компания. Все права защищены.",
121121
"+{{count}} more": "ещё {{count}}",
122122
"| Based on": "| На основе",
@@ -243,7 +243,7 @@
243243
"Actual Amount": "Фактическая сумма",
244244
"Actual Model": "Фактическая модель",
245245
"Actual Model:": "Фактическая модель:",
246-
"Adapt `-thinking` suffix requests to Anthropic native thinking behavior while keeping billing predictable.": "Адаптировать запросы с суффиксом `-thinking` к собственному режиму размышления Anthropic, сохраняя предсказуемость биллинга.",
246+
"Adapt `-thinking`, `-nothinking`, and effort suffixes such as `-high` to Anthropic native thinking behavior while keeping billing predictable. When off, model names are sent upstream unchanged.": "Адаптировать запросы с суффиксами `-thinking`, `-nothinking` и суффиксами усилия, такими как `-high`, к собственному режиму размышления Anthropic, сохраняя предсказуемость биллинга. При отключении имена моделей отправляются вверх по потоку без изменений.",
247247
"Add": "Добавить",
248248
"Add \"{{value}}\"": "Добавить \"{{value}}\"",
249249
"Add {{added}} models and remove {{removed}} models": "Добавить моделей: {{added}}, удалить: {{removed}}",

0 commit comments

Comments
 (0)