Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions relay/common/override.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var paramOverrideSensitivePathPrefixes = []string{
"model",
"original_model",
"upstream_model",
"reasoning",
"reasoning_effort",
"service_tier",
"inference_geo",
"speed",
Expand Down Expand Up @@ -191,6 +193,7 @@ func ApplyParamOverrideWithRelayInfo(jsonData []byte, info *RelayInfo) ([]byte,
if err != nil {
return nil, err
}
syncReasoningEffort(info, result)
syncRuntimeHeaderOverrideFromContext(info, overrideCtx)
if info != nil {
if recorder != nil {
Expand All @@ -202,6 +205,29 @@ func ApplyParamOverrideWithRelayInfo(jsonData []byte, info *RelayInfo) ([]byte,
return result, nil
}

// syncReasoningEffort keeps request metadata aligned with the final outbound
// body after parameter overrides have been applied. Adapters populate this
// field before overrides run, so reading the final JSON prevents logs from
// reporting the pre-override effort.
func syncReasoningEffort(info *RelayInfo, jsonData []byte) {
if info == nil {
return
}

for _, path := range []string{"reasoning.effort", "reasoning_effort"} {
value := gjson.GetBytes(jsonData, path)
if !value.Exists() {
continue
}
if value.Type == gjson.String {
info.ReasoningEffort = value.String()
} else {
info.ReasoningEffort = ""
}
return
}
Comment on lines +208 to +227

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Clear metadata when the final body has no reasoning field.

Line 219 skips absent paths and Line 228 returns without changing info.ReasoningEffort. If an override removes reasoning.effort or reasoning_effort, logs retain the pre-override value.

Clear info.ReasoningEffort before this loop. Then set it only when the final body contains a string value.

Proposed fix
 func syncReasoningEffort(info *RelayInfo, jsonData []byte) {
 	if info == nil {
 		return
 	}
+	info.ReasoningEffort = ""

 	for _, path := range []string{"reasoning.effort", "reasoning_effort"} {

Based on PR objectives, metadata must align with the final outbound request body.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// syncReasoningEffort keeps request metadata aligned with the final outbound
// body after parameter overrides have been applied. Adapters populate this
// field before overrides run, so reading the final JSON prevents logs from
// reporting the pre-override effort.
func syncReasoningEffort(info *RelayInfo, jsonData []byte) {
if info == nil {
return
}
for _, path := range []string{"reasoning.effort", "reasoning_effort"} {
value := gjson.GetBytes(jsonData, path)
if !value.Exists() {
continue
}
if value.Type == gjson.String {
info.ReasoningEffort = value.String()
} else {
info.ReasoningEffort = ""
}
return
}
// syncReasoningEffort keeps request metadata aligned with the final outbound
// body after parameter overrides have been applied. Adapters populate this
// field before overrides run, so reading the final JSON prevents logs from
// reporting the pre-override effort.
func syncReasoningEffort(info *RelayInfo, jsonData []byte) {
if info == nil {
return
}
info.ReasoningEffort = ""
for _, path := range []string{"reasoning.effort", "reasoning_effort"} {
value := gjson.GetBytes(jsonData, path)
if !value.Exists() {
continue
}
if value.Type == gjson.String {
info.ReasoningEffort = value.String()
} else {
info.ReasoningEffort = ""
}
return
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@relay/common/override.go` around lines 208 - 228, Update syncReasoningEffort
to clear info.ReasoningEffort before iterating over the reasoning paths.
Preserve the existing loop, but only assign the field when the final JSON
contains a string value, leaving it empty when both paths are absent or
non-string.

}

func shouldEnableParamOverrideAudit(paramOverride map[string]interface{}) bool {
if common.DebugEnabled {
return true
Expand Down
73 changes: 73 additions & 0 deletions relay/common/override_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2153,6 +2153,79 @@ func TestApplyParamOverrideWithRelayInfoRecordsOperationAuditInDebugMode(t *test
}
}

func TestApplyParamOverrideWithRelayInfoSyncsResponsesReasoningEffort(t *testing.T) {
originalDebugEnabled := common2.DebugEnabled
common2.DebugEnabled = false
t.Cleanup(func() {
common2.DebugEnabled = originalDebugEnabled
})

info := &RelayInfo{
ReasoningEffort: "high",
ChannelMeta: &ChannelMeta{
ParamOverride: map[string]interface{}{
"operations": []interface{}{
map[string]interface{}{
"mode": "set",
"path": "reasoning.effort",
"value": "max",
},
},
},
},
}

out, err := ApplyParamOverrideWithRelayInfo([]byte(`{
"model":"gpt-5.6-sol",
"reasoning":{"effort":"high"}
}`), info)
if err != nil {
t.Fatalf("ApplyParamOverrideWithRelayInfo returned error: %v", err)
}
assertJSONEqual(t, `{
"model":"gpt-5.6-sol",
"reasoning":{"effort":"max"}
}`, string(out))
if info.ReasoningEffort != "max" {
t.Fatalf("expected final reasoning effort max, got %q", info.ReasoningEffort)
}
if !reflect.DeepEqual(info.ParamOverrideAudit, []string{"set reasoning.effort = max"}) {
t.Fatalf("unexpected param override audit, got %#v", info.ParamOverrideAudit)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}

func TestApplyParamOverrideWithRelayInfoSyncsChatReasoningEffort(t *testing.T) {
info := &RelayInfo{
ReasoningEffort: "high",
ChannelMeta: &ChannelMeta{
ParamOverride: map[string]interface{}{
"operations": []interface{}{
map[string]interface{}{
"mode": "set",
"path": "reasoning_effort",
"value": "xhigh",
},
},
},
},
}
Comment on lines +2219 to +2239

out, err := ApplyParamOverrideWithRelayInfo([]byte(`{
"model":"gpt-5.6-sol",
"reasoning_effort":"high"
}`), info)
if err != nil {
t.Fatalf("ApplyParamOverrideWithRelayInfo returned error: %v", err)
}
assertJSONEqual(t, `{
"model":"gpt-5.6-sol",
"reasoning_effort":"xhigh"
}`, string(out))
if info.ReasoningEffort != "xhigh" {
t.Fatalf("expected final reasoning effort xhigh, got %q", info.ReasoningEffort)
}
}

func TestApplyParamOverrideWithRelayInfoRecordsOnlyKeyOperationsWhenDebugDisabled(t *testing.T) {
originalDebugEnabled := common2.DebugEnabled
common2.DebugEnabled = false
Expand Down