@@ -6271,6 +6271,98 @@ describe("CodexAdapterV2 post-settle continuation", () => {
62716271 ) ,
62726272 ) ;
62736273
6274+ it . effect . each (
6275+ (
6276+ [
6277+ { notificationStatus : 500 , completionStatus : 429 , expectedClass : "usage_limit" } ,
6278+ { notificationStatus : 429 , completionStatus : 500 , expectedClass : "provider_error" } ,
6279+ { notificationStatus : null , completionStatus : 429 , expectedClass : "usage_limit" } ,
6280+ { notificationStatus : 429 , completionStatus : null , expectedClass : "usage_limit" } ,
6281+ { notificationStatus : 429 , completionStatus : 429 , expectedClass : "usage_limit" } ,
6282+ { notificationStatus : 500 , completionStatus : 500 , expectedClass : "provider_error" } ,
6283+ ] as const
6284+ ) . flatMap ( ( scenario ) => [ false , true ] . map ( ( willRetry ) => ( { ...scenario , willRetry } ) ) ) ,
6285+ ) (
6286+ "honors completion HTTP status from $notificationStatus to $completionStatus (retry: $willRetry)" ,
6287+ ( { notificationStatus, completionStatus, expectedClass, willRetry } ) =>
6288+ Effect . scoped (
6289+ Effect . gen ( function * ( ) {
6290+ const name = `${ notificationStatus } -${ completionStatus } -${ willRetry } ` ;
6291+ const nativeThreadId = `native-exhaustion-status-${ name } ` ;
6292+ const nativeTurnId = `turn-exhaustion-status-${ name } ` ;
6293+ const message = "Provider stopped this request." ;
6294+ const additionalDetails = "Detailed notification evidence." ;
6295+ const transcript = makeCodexReplayTranscript ( {
6296+ scenario : `codex-exhaustion-status-${ name } ` ,
6297+ entries : [
6298+ ...codexReplayPreamble ( { nativeThreadId, nativeTurnId, prompt : "Continue." } ) ,
6299+ {
6300+ type : "emit_inbound" ,
6301+ label : "error" ,
6302+ frame : {
6303+ method : "error" ,
6304+ params : {
6305+ threadId : nativeThreadId ,
6306+ turnId : nativeTurnId ,
6307+ willRetry,
6308+ error : {
6309+ message,
6310+ codexErrorInfo : {
6311+ responseTooManyFailedAttempts : { httpStatusCode : notificationStatus } ,
6312+ } ,
6313+ additionalDetails,
6314+ } ,
6315+ } ,
6316+ } ,
6317+ } ,
6318+ {
6319+ type : "emit_inbound" ,
6320+ label : "turn/completed" ,
6321+ frame : {
6322+ method : "turn/completed" ,
6323+ params : {
6324+ threadId : nativeThreadId ,
6325+ turn : {
6326+ ...makeCodexReplayTurn ( { id : nativeTurnId , status : "failed" } ) ,
6327+ error : {
6328+ message,
6329+ codexErrorInfo : {
6330+ responseTooManyFailedAttempts : { httpStatusCode : completionStatus } ,
6331+ } ,
6332+ } ,
6333+ } ,
6334+ } ,
6335+ } ,
6336+ } ,
6337+ ] ,
6338+ } ) ;
6339+ const harness = yield * makeCodexReplayHarness ( transcript ) ;
6340+ yield * harness . runtime . startTurn (
6341+ makeCodexTestTurnInput ( {
6342+ threadId : harness . threadId ,
6343+ providerThread : harness . providerThread ,
6344+ now : yield * DateTime . now ,
6345+ text : "Continue." ,
6346+ attemptId : RunAttemptId . make ( `attempt-exhaustion-status-${ name } ` ) ,
6347+ } ) ,
6348+ ) ;
6349+ yield * harness . firstTerminal ;
6350+ const terminal = harness . terminalEvents ( ) [ 0 ] ;
6351+ assert . equal ( terminal ?. status , "failed" ) ;
6352+ if ( terminal ?. status !== "failed" ) return ;
6353+ assert . equal ( terminal . failure . class , expectedClass ) ;
6354+ assert . equal ( terminal . failure . code , "responseTooManyFailedAttempts" ) ;
6355+ assert . equal ( terminal . threadDisposition , "reusable" ) ;
6356+ const notificationClass = notificationStatus === 429 ? "usage_limit" : "provider_error" ;
6357+ assert . equal (
6358+ terminal . failure . message ,
6359+ expectedClass === notificationClass ? additionalDetails : message ,
6360+ ) ;
6361+ if ( willRetry ) assert . equal ( terminal . retry ?. attempt , 1 ) ;
6362+ } ) . pipe ( Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
6363+ ) ,
6364+ ) ;
6365+
62746366 const FAILED_SCENARIO = "codex-failed-mid-command" ;
62756367 const FAILED_NATIVE_THREAD = "native-codex-failed-thread" ;
62766368 const FAILED_NATIVE_TURN = "native-codex-failed-turn" ;
0 commit comments