Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
ca3f497b
Commit
ca3f497b
authored
Mar 08, 2026
by
Elysia
Browse files
fix issue #851
parent
03bf3485
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/gateway_request.go
View file @
ca3f497b
...
...
@@ -396,6 +396,10 @@ func FilterThinkingBlocksForRetry(body []byte) []byte {
}
else
{
return
body
}
// Removing "thinking" makes any context_management strategy that requires it invalid
// (e.g. clear_thinking_20251015). Strip those entries so the retry request does not
// receive a 400 "strategy requires thinking to be enabled or adaptive".
out
=
removeThinkingDependentContextStrategies
(
out
)
}
if
modified
{
msgsBytes
,
err
:=
json
.
Marshal
(
messages
)
...
...
@@ -410,6 +414,49 @@ func FilterThinkingBlocksForRetry(body []byte) []byte {
return
out
}
// removeThinkingDependentContextStrategies 从 context_management.edits 中移除
// 需要 thinking 启用的策略(如 clear_thinking_20251015)。
// 当顶层 "thinking" 字段被禁用时必须调用,否则上游会返回
// "strategy requires thinking to be enabled or adaptive"。
func
removeThinkingDependentContextStrategies
(
body
[]
byte
)
[]
byte
{
jsonStr
:=
*
(
*
string
)(
unsafe
.
Pointer
(
&
body
))
editsRes
:=
gjson
.
Get
(
jsonStr
,
"context_management.edits"
)
if
!
editsRes
.
Exists
()
||
!
editsRes
.
IsArray
()
{
return
body
}
var
filtered
[]
json
.
RawMessage
hasRemoved
:=
false
editsRes
.
ForEach
(
func
(
_
,
v
gjson
.
Result
)
bool
{
if
v
.
Get
(
"type"
)
.
String
()
==
"clear_thinking_20251015"
{
hasRemoved
=
true
return
true
}
filtered
=
append
(
filtered
,
json
.
RawMessage
(
v
.
Raw
))
return
true
})
if
!
hasRemoved
{
return
body
}
if
len
(
filtered
)
==
0
{
if
b
,
err
:=
sjson
.
DeleteBytes
(
body
,
"context_management.edits"
);
err
==
nil
{
return
b
}
return
body
}
filteredBytes
,
err
:=
json
.
Marshal
(
filtered
)
if
err
!=
nil
{
return
body
}
if
b
,
err
:=
sjson
.
SetRawBytes
(
body
,
"context_management.edits"
,
filteredBytes
);
err
==
nil
{
return
b
}
return
body
}
// FilterSignatureSensitiveBlocksForRetry is a stronger retry filter for cases where upstream errors indicate
// signature/thought_signature validation issues involving tool blocks.
//
...
...
@@ -445,6 +492,24 @@ func FilterSignatureSensitiveBlocksForRetry(body []byte) []byte {
if
_
,
exists
:=
req
[
"thinking"
];
exists
{
delete
(
req
,
"thinking"
)
modified
=
true
// Remove context_management strategies that require thinking to be enabled
// (e.g. clear_thinking_20251015), otherwise upstream returns 400.
if
cm
,
ok
:=
req
[
"context_management"
]
.
(
map
[
string
]
any
);
ok
{
if
edits
,
ok
:=
cm
[
"edits"
]
.
([]
any
);
ok
{
filtered
:=
make
([]
any
,
0
,
len
(
edits
))
for
_
,
edit
:=
range
edits
{
if
editMap
,
ok
:=
edit
.
(
map
[
string
]
any
);
ok
{
if
editMap
[
"type"
]
==
"clear_thinking_20251015"
{
continue
}
}
filtered
=
append
(
filtered
,
edit
)
}
if
len
(
filtered
)
!=
len
(
edits
)
{
cm
[
"edits"
]
=
filtered
}
}
}
}
messages
,
ok
:=
req
[
"messages"
]
.
([]
any
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment