@@ -2819,6 +2819,25 @@ describe("ProviderRuntimeIngestion", () => {
28192819 nextAttemptAt : "2099-01-01T01:00:02.000Z" ,
28202820 attempt : 1 ,
28212821 } ) ;
2822+
2823+ harness . emit ( {
2824+ type : "turn.completed" ,
2825+ eventId : asEventId ( "evt-runtime-usage-limit-failed" ) ,
2826+ provider : ProviderDriverKind . make ( "codex" ) ,
2827+ createdAt : attemptedAt ,
2828+ threadId : asThreadId ( "thread-1" ) ,
2829+ turnId : asTurnId ( "turn-usage-limit" ) ,
2830+ payload : { state : "failed" } ,
2831+ } ) ;
2832+ await harness . drain ( ) ;
2833+
2834+ const afterCompletion = ( await harness . readModel ( ) ) . threads . find (
2835+ ( entry ) => entry . id === ThreadId . make ( "thread-1" ) ,
2836+ ) ;
2837+ expect ( afterCompletion ?. usageLimitResume ) . toEqual ( {
2838+ nextAttemptAt : "2099-01-01T01:00:02.000Z" ,
2839+ attempt : 1 ,
2840+ } ) ;
28222841 } ) ;
28232842
28242843 it ( "clears automatic resume after a successful provider turn" , async ( ) => {
@@ -2899,6 +2918,43 @@ describe("ProviderRuntimeIngestion", () => {
28992918 expect ( thread . usageLimitResume ) . toBeNull ( ) ;
29002919 } ) ;
29012920
2921+ it ( "clears an in-flight automatic resume after a failed turn without a runtime error" , async ( ) => {
2922+ const harness = await createHarness ( ) ;
2923+ const attemptedAt = "2099-01-01T00:00:00.000Z" ;
2924+
2925+ await harness . markUsageLimited ( ) ;
2926+ await harness . dispatch ( {
2927+ type : "thread.usage-limit-resume.schedule" ,
2928+ commandId : CommandId . make ( "cmd-failed-resume-schedule" ) ,
2929+ threadId : ThreadId . make ( "thread-1" ) ,
2930+ resumeAt : attemptedAt ,
2931+ } ) ;
2932+ await harness . dispatch ( {
2933+ type : "thread.usage-limit-resume.attempt" ,
2934+ commandId : CommandId . make ( "cmd-failed-resume-attempt" ) ,
2935+ threadId : ThreadId . make ( "thread-1" ) ,
2936+ expectedAttemptAt : attemptedAt ,
2937+ createdAt : attemptedAt ,
2938+ } ) ;
2939+
2940+ harness . emit ( {
2941+ type : "turn.completed" ,
2942+ eventId : asEventId ( "evt-failed-auto-resume" ) ,
2943+ provider : ProviderDriverKind . make ( "codex" ) ,
2944+ createdAt : attemptedAt ,
2945+ threadId : asThreadId ( "thread-1" ) ,
2946+ turnId : asTurnId ( "turn-failed-auto-resume" ) ,
2947+ payload : { state : "failed" } ,
2948+ } ) ;
2949+
2950+ const thread = await waitForThread (
2951+ harness . readModel ,
2952+ ( entry ) => entry . usageLimitResume === null ,
2953+ ) ;
2954+ expect ( thread . usageLimitResume ) . toBeNull ( ) ;
2955+ expect ( thread . session ?. status ) . toBe ( "error" ) ;
2956+ } ) ;
2957+
29022958 it ( "keeps automatic resume active when a superseded turn completes" , async ( ) => {
29032959 const harness = await createHarness ( ) ;
29042960 const attemptedAt = "2099-01-01T00:00:00.000Z" ;
0 commit comments