@@ -993,6 +993,7 @@ export class PauseResumeManager {
993993 pausedExecutionId : pausedExecution . id ,
994994 parentExecutionId : pausedExecution . executionId ,
995995 contextId,
996+ stopAfterBlockReached : result . metadata ?. stopAfterBlockReached === true ,
996997 } )
997998 }
998999 }
@@ -1478,6 +1479,9 @@ export class PauseResumeManager {
14781479 isClientSession : baseSnapshot . metadata . isClientSession ,
14791480 resumeFromSnapshot : true ,
14801481 resumeTerminalNoop : stateCopy ?. resumeTerminalNoop === true ,
1482+ resumeHasPendingPauses : Object . entries ( pausePoints ) . some (
1483+ ( [ id , point ] ) => id !== contextId && point . resumeStatus !== 'resumed'
1484+ ) ,
14811485 }
14821486
14831487 const resumeSnapshot = new ExecutionSnapshot (
@@ -2095,6 +2099,7 @@ export class PauseResumeManager {
20952099 pausedExecutionId ?: string
20962100 parentExecutionId ?: string
20972101 contextId ?: string
2102+ stopAfterBlockReached ?: boolean
20982103 } ) : Promise < void > {
20992104 const { resumeEntryId, pausedExecutionId, parentExecutionId, contextId } = args
21002105 const now = new Date ( )
@@ -2178,6 +2183,45 @@ export class PauseResumeManager {
21782183
21792184 if ( ! pausedExecution || ! contextId ) return
21802185
2186+ if ( args . stopAfterBlockReached ) {
2187+ await tx
2188+ . update ( pausedExecutions )
2189+ . set ( {
2190+ pausePoints : sql `(
2191+ SELECT COALESCE(jsonb_object_agg(point.key, point.value), '{}'::jsonb)
2192+ FROM jsonb_each(jsonb_set(
2193+ ${ updatePausePointResumeStateSql ( contextId , 'resumed' ) } ,
2194+ ARRAY[${ contextId } , 'resumedAt'],
2195+ ${ JSON . stringify ( now . toISOString ( ) ) } ::jsonb
2196+ )) AS point
2197+ WHERE point.value->>'resumeStatus' = 'resumed'
2198+ )` ,
2199+ totalPauseCount : sql `${ pausedExecutions . resumedCount } + 1` ,
2200+ resumedCount : sql `${ pausedExecutions . resumedCount } + 1` ,
2201+ status : 'fully_resumed' ,
2202+ nextResumeAt : null ,
2203+ automaticResumeRetryCount : 0 ,
2204+ metadata : sql `${ pausedExecutions . metadata } - 'automaticResumeWaiting'` ,
2205+ updatedAt : now ,
2206+ } )
2207+ . where ( eq ( pausedExecutions . id , targetPausedExecutionId ) )
2208+ await tx
2209+ . update ( resumeQueue )
2210+ . set ( {
2211+ status : 'failed' ,
2212+ completedAt : now ,
2213+ failureReason : 'Execution stopped after its target block' ,
2214+ } )
2215+ . where (
2216+ and (
2217+ eq ( resumeQueue . parentExecutionId , targetParentExecutionId ) ,
2218+ eq ( resumeQueue . pausedExecutionId , targetPausedExecutionId ) ,
2219+ eq ( resumeQueue . status , 'pending' )
2220+ )
2221+ )
2222+ return
2223+ }
2224+
21812225 await tx
21822226 . update ( pausedExecutions )
21832227 . set ( {
0 commit comments