@@ -1259,61 +1259,68 @@ describe("shouldRecoverAnthropicThinkingError — broadened candidate set", () =
12591259 // the actionable Anthropic detail is stored on .errorBody as a JSON
12601260 // string. Without the broadened candidate set, the recovery detector
12611261 // returns false and the session gets bricked.
1262- const err = new Error (
1263- "LLM request failed: provider rejected the request schema or tool payload." ,
1264- ) ;
1265- err . errorBody = JSON . stringify ( {
1266- error : {
1267- message : "messages.12.content.3: Invalid `signature` in `thinking` block" ,
1268- type : "invalid_request_error" ,
1262+ const err = Object . assign (
1263+ new Error ( "LLM request failed: provider rejected the request schema or tool payload." ) ,
1264+ {
1265+ errorBody : JSON . stringify ( {
1266+ error : {
1267+ message : "messages.12.content.3: Invalid `signature` in `thinking` block" ,
1268+ type : "invalid_request_error" ,
1269+ } ,
1270+ } ) ,
12691271 } ,
1270- } ) ;
1272+ ) ;
12711273 expect ( shouldRecoverAnthropicThinkingError ( err , sessionMeta ) ) . toBe ( true ) ;
12721274 } ) ;
12731275
12741276 it ( "recovers when the thinking detail is a structured object on .data" , ( ) => {
12751277 // Generic SDK wrappers sometimes surface the provider response as a
12761278 // parsed object rather than a JSON string. The detector must serialize
12771279 // the object and pattern-match the serialized form.
1278- const err = new Error ( "LLM request failed." ) ;
1279- err . data = {
1280- error : { message : "Invalid signature on thinking block" } ,
1281- } ;
1280+ const err = Object . assign ( new Error ( "LLM request failed." ) , {
1281+ data : {
1282+ error : { message : "Invalid signature on thinking block" } ,
1283+ } ,
1284+ } ) ;
12821285 expect ( shouldRecoverAnthropicThinkingError ( err , sessionMeta ) ) . toBe ( true ) ;
12831286 } ) ;
12841287
12851288 it ( "does NOT recover for a rate-limit error (negative)" , ( ) => {
1286- const err = new Error ( "rate_limit_error: too many requests" ) ;
1287- err . errorBody = JSON . stringify ( { error : { message : "rate_limit_error: too many requests" } } ) ;
1289+ const err = Object . assign ( new Error ( "rate_limit_error: too many requests" ) , {
1290+ errorBody : JSON . stringify ( { error : { message : "rate_limit_error: too many requests" } } ) ,
1291+ } ) ;
12881292 expect ( shouldRecoverAnthropicThinkingError ( err , sessionMeta ) ) . toBe ( false ) ;
12891293 } ) ;
12901294
12911295 it ( "does NOT recover for a context-overflow error (negative)" , ( ) => {
1292- const err = new Error ( "context length exceeded" ) ;
1293- err . errorBody = JSON . stringify ( { error : { message : "context length exceeded" } } ) ;
1296+ const err = Object . assign ( new Error ( "context length exceeded" ) , {
1297+ errorBody : JSON . stringify ( { error : { message : "context length exceeded" } } ) ,
1298+ } ) ;
12941299 expect ( shouldRecoverAnthropicThinkingError ( err , sessionMeta ) ) . toBe ( false ) ;
12951300 } ) ;
12961301
12971302 it ( "does NOT recover for an auth error (negative)" , ( ) => {
1298- const err = new Error ( "invalid api key" ) ;
1299- err . errorBody = JSON . stringify ( { error : { message : "invalid api key" } } ) ;
1303+ const err = Object . assign ( new Error ( "invalid api key" ) , {
1304+ errorBody : JSON . stringify ( { error : { message : "invalid api key" } } ) ,
1305+ } ) ;
13001306 expect ( shouldRecoverAnthropicThinkingError ( err , sessionMeta ) ) . toBe ( false ) ;
13011307 } ) ;
13021308
13031309 it ( "does NOT recover for a generic-only schema rejection (no provider detail anywhere)" , ( ) => {
13041310 // Generic .message with empty .errorBody — must NOT trigger, since
13051311 // this is the failure shape that the broadened candidate set could
13061312 // accidentally over-match if pattern was too loose.
1307- const err = new Error (
1308- "LLM request failed: provider rejected the request schema or tool payload." ,
1313+ const err = Object . assign (
1314+ new Error ( "LLM request failed: provider rejected the request schema or tool payload." ) ,
1315+ { errorBody : "" } ,
13091316 ) ;
1310- err . errorBody = "" ;
13111317 expect ( shouldRecoverAnthropicThinkingError ( err , sessionMeta ) ) . toBe ( false ) ;
13121318 } ) ;
13131319
13141320 it ( "does NOT recover for an unrelated use of the word 'invalid' (negative)" , ( ) => {
1315- const err = new Error ( "LLM request failed: invalid model name" ) ;
1316- err . errorBody = JSON . stringify ( { error : { message : "invalid model name 'foo-bar'" } } ) ;
1321+ const err = Object . assign ( new Error ( "LLM request failed: invalid model name" ) , {
1322+ errorBody : JSON . stringify ( { error : { message : "invalid model name 'foo-bar'" } } ) ,
1323+ } ) ;
13171324 expect ( shouldRecoverAnthropicThinkingError ( err , sessionMeta ) ) . toBe ( false ) ;
13181325 } ) ;
13191326
@@ -1334,12 +1341,14 @@ describe("shouldRecoverAnthropicThinkingError — broadened candidate set", () =
13341341 // null from safeJsonStringifyForPattern and never reaches the pattern
13351342 // matcher.
13361343 const huge = "thinking or redacted_thinking blocks " . repeat ( 1500 ) ; // ~52 KiB
1337- const err = new Error (
1338- "LLM request failed: provider rejected the request schema or tool payload." ,
1344+ const err = Object . assign (
1345+ new Error ( "LLM request failed: provider rejected the request schema or tool payload." ) ,
1346+ {
1347+ errorBody : JSON . stringify ( {
1348+ error : { message : huge } ,
1349+ } ) ,
1350+ } ,
13391351 ) ;
1340- err . errorBody = JSON . stringify ( {
1341- error : { message : huge } ,
1342- } ) ;
13431352 expect ( shouldRecoverAnthropicThinkingError ( err , sessionMeta ) ) . toBe ( false ) ;
13441353 } ) ;
13451354
0 commit comments