@@ -235,6 +235,78 @@ describe("Anthropic provider", () => {
235235 expect ( result . responseModel ) . toBe ( "claude-fable-5" ) ;
236236 } ) ;
237237
238+ it ( "strips thinking from completed turns while preserving active tool-turn thinking (#94228)" , async ( ) => {
239+ // Multi-turn session with tool calls. The active tool turn (assistant
240+ // with tool_use + pending tool_result) must keep its thinking signatures
241+ // for signature continuity. The earlier completed assistant turn must
242+ // have its thinking stripped to prevent stale signature 400 errors.
243+ let capturedPayload : unknown ;
244+ const client = {
245+ messages : {
246+ create : vi . fn ( ( ) => ( {
247+ asResponse : ( ) =>
248+ Promise . resolve (
249+ createSseResponse ( [
250+ {
251+ type : "message_start" ,
252+ message : { id : "msg_1" , model : "claude-sonnet-4-6" , usage : { input_tokens : 1 , output_tokens : 0 } } ,
253+ } ,
254+ { type : "message_delta" , delta : { stop_reason : "end_turn" } , usage : { input_tokens : 1 , output_tokens : 1 } } ,
255+ { type : "message_stop" } ,
256+ ] ) ,
257+ ) ,
258+ } ) ) ,
259+ } ,
260+ } ;
261+
262+ const stream = streamAnthropic (
263+ makeAnthropicModel ( { id : "claude-sonnet-4-6" , name : "Claude Sonnet 4.6" } ) ,
264+ {
265+ messages : [
266+ { role : "user" , content : "task 1" , timestamp : 0 } ,
267+ {
268+ role : "assistant" ,
269+ provider : "anthropic" , api : "anthropic-messages" , model : "claude-sonnet-4-6" ,
270+ stopReason : "tool_use" , timestamp : 0 ,
271+ usage : { input : 0 , output : 0 , cacheRead : 0 , cacheWrite : 0 , totalTokens : 0 , cost : { input : 0 , output : 0 , cacheRead : 0 , cacheWrite : 0 , total : 0 } } ,
272+ content : [
273+ { type : "thinking" , thinking : "old reasoning" , thinkingSignature : "sig_old" } ,
274+ { type : "text" , text : "Done." } ,
275+ ] ,
276+ } ,
277+ { role : "user" , content : "task 2" , timestamp : 0 } ,
278+ {
279+ role : "assistant" ,
280+ provider : "anthropic" , api : "anthropic-messages" , model : "claude-sonnet-4-6" ,
281+ stopReason : "tool_use" , timestamp : 0 ,
282+ usage : { input : 0 , output : 0 , cacheRead : 0 , cacheWrite : 0 , totalTokens : 0 , cost : { input : 0 , output : 0 , cacheRead : 0 , cacheWrite : 0 , total : 0 } } ,
283+ content : [
284+ { type : "thinking" , thinking : "active reasoning" , thinkingSignature : "sig_active" } ,
285+ { type : "toolCall" , id : "tool_1" , name : "bash" , arguments : { } } ,
286+ ] ,
287+ } ,
288+ { role : "toolResult" , toolCallId : "tool_1" , content : "ok" , isError : false } ,
289+ ] ,
290+ } ,
291+ { apiKey : "sk-ant-provider" , client : client as never , onPayload : ( p ) => { capturedPayload = p ; } } ,
292+ ) ;
293+
294+ await stream . result ( ) ;
295+ const payload = capturedPayload as { messages : Array < { role : string ; content : unknown [ ] } > } ;
296+ const assistantMessages = payload . messages . filter ( ( m ) => m . role === "assistant" ) ;
297+ expect ( assistantMessages ) . toHaveLength ( 2 ) ;
298+
299+ // Completed turn: thinking stripped → [assistant reasoning omitted]
300+ const firstBlocks = assistantMessages [ 0 ] . content as Array < { type : string } > ;
301+ expect ( firstBlocks . find ( ( b ) => b . type === "thinking" ) ) . toBeUndefined ( ) ;
302+
303+ // Active tool turn: thinking preserved for signature continuity
304+ const secondBlocks = assistantMessages [ 1 ] . content as Array < { type : string ; thinking ?: string ; signature ?: string } > ;
305+ const activeThinking = secondBlocks . find ( ( b ) => b . type === "thinking" ) ;
306+ expect ( activeThinking ) . toBeDefined ( ) ;
307+ expect ( activeThinking ?. signature ) . toBe ( "sig_active" ) ;
308+ } ) ;
309+
238310 it . each ( [
239311 {
240312 label : "omitted" ,
0 commit comments