@@ -458,15 +458,35 @@ export function ExecutionView({ executionId, onFollowUpCreated, onStatusChange,
458458 } , [ ] )
459459
460460 // Handle cancel action for a specific execution
461+ // For persistent sessions, this interrupts (stops current work, keeps session alive)
462+ // For non-persistent sessions, this cancels (terminates execution)
461463 const handleCancel = async ( execId : string ) => {
462464 setCancelling ( true )
463465 try {
464- await executionsApi . cancel ( execId )
466+ // Find the execution to check if it's a persistent session
467+ const execution = chainData ?. executions . find ( ( e ) => e . id === execId )
468+ let isPersistentSession = false
469+ if ( execution ?. config ) {
470+ try {
471+ const config = JSON . parse ( execution . config )
472+ isPersistentSession = config . sessionMode === 'persistent'
473+ } catch {
474+ // Invalid config JSON, default to non-persistent
475+ }
476+ }
477+
478+ if ( isPersistentSession ) {
479+ // Interrupt: stops current work but keeps session alive
480+ await executionsApi . interrupt ( execId )
481+ } else {
482+ // Cancel: fully terminates the execution
483+ await executionsApi . cancel ( execId )
484+ }
465485 // Reload chain to get updated status
466486 const data = await executionsApi . getChain ( executionId )
467487 setChainData ( data )
468488 } catch ( err ) {
469- setError ( err instanceof Error ? err . message : 'Failed to cancel execution' )
489+ setError ( err instanceof Error ? err . message : 'Failed to stop execution' )
470490 } finally {
471491 setCancelling ( false )
472492 }
@@ -506,7 +526,7 @@ export function ExecutionView({ executionId, onFollowUpCreated, onStatusChange,
506526
507527 // Check if this is a persistent session that's ready for another prompt
508528 const isPersistentSessionReady =
509- lastExecution . status === 'waiting ' || lastExecution . status === 'paused'
529+ lastExecution . status === 'pending ' || lastExecution . status === 'paused'
510530
511531 setSubmittingFollowUp ( true )
512532 try {
@@ -528,7 +548,7 @@ export function ExecutionView({ executionId, onFollowUpCreated, onStatusChange,
528548 } )
529549
530550 // Send prompt to existing persistent session
531- // WebSocket will update the status back to 'waiting ' when complete
551+ // WebSocket will update the status back to 'pending ' when complete
532552 await executionsApi . sendPrompt ( lastExecution . id , prompt )
533553 } else {
534554 // Create a new follow-up execution
@@ -575,7 +595,7 @@ export function ExecutionView({ executionId, onFollowUpCreated, onStatusChange,
575595 const lastExecution = chainData . executions [ chainData . executions . length - 1 ]
576596
577597 // Only end if the session is in a state that can be ended
578- if ( lastExecution . status !== 'waiting ' && lastExecution . status !== 'paused' ) {
598+ if ( lastExecution . status !== 'pending ' && lastExecution . status !== 'paused' ) {
579599 return
580600 }
581601
@@ -866,8 +886,8 @@ export function ExecutionView({ executionId, onFollowUpCreated, onStatusChange,
866886 if ( ! chainData || chainData . executions . length === 0 ) return
867887 const rootExec = chainData . executions [ 0 ]
868888 const lastExec = chainData . executions [ chainData . executions . length - 1 ]
869- // Only allow cancel for actively running executions (not waiting/paused persistent sessions)
870- const canCancel = [ 'preparing' , 'pending' , 'running' ] . includes ( lastExec . status )
889+ // Only allow cancel for actively running executions
890+ const canCancel = lastExec . status === 'running'
871891
872892 onHeaderDataChange ?.(
873893 {
@@ -940,7 +960,7 @@ export function ExecutionView({ executionId, onFollowUpCreated, onStatusChange,
940960 lastExecution . status === 'stopped' ||
941961 lastExecution . status === 'cancelled'
942962 const isPersistentSessionReady =
943- lastExecution . status === 'waiting ' || lastExecution . status === 'paused'
963+ lastExecution . status === 'pending ' || lastExecution . status === 'paused'
944964 const canEnableFollowUp = lastExecutionTerminal || isPersistentSessionReady
945965
946966 // Determine if the execution is actively running (not waiting/paused)
@@ -990,8 +1010,7 @@ export function ExecutionView({ executionId, onFollowUpCreated, onStatusChange,
9901010 onTodosUpdate = { handleTodosUpdate }
9911011 onAvailableCommandsUpdate = { isLast ? handleAvailableCommandsUpdate : undefined }
9921012 onCancel = {
993- isLast &&
994- [ 'preparing' , 'pending' , 'running' ] . includes ( execution . status )
1013+ isLast && execution . status === 'running'
9951014 ? ( ) => handleCancel ( execution . id )
9961015 : undefined
9971016 }
@@ -1050,7 +1069,7 @@ export function ExecutionView({ executionId, onFollowUpCreated, onStatusChange,
10501069 { endingSession ? 'Ending...' : 'End Session' }
10511070 </ Button >
10521071 < span className = "text-xs text-muted-foreground" >
1053- Session { lastExecution . status === 'paused' ? 'paused' : 'waiting ' } for input
1072+ Session { lastExecution . status === 'paused' ? 'paused' : 'pending ' } for input
10541073 </ span >
10551074 </ div >
10561075 ) }
0 commit comments