@@ -1464,6 +1464,19 @@ export async function runCodexAppServerAttempt(
14641464 } ) ;
14651465 } ;
14661466
1467+ const isTerminalTurnNotificationForTurn = (
1468+ notification : CodexServerNotification ,
1469+ notificationTurnId : string ,
1470+ ) : boolean => {
1471+ if ( ! isTurnNotification ( notification . params , thread . threadId , notificationTurnId ) ) {
1472+ return false ;
1473+ }
1474+ return (
1475+ notification . method === "turn/completed" ||
1476+ isCodexTurnAbortMarkerNotification ( notification , { currentPromptText : promptBuild . prompt } )
1477+ ) ;
1478+ } ;
1479+
14671480 const handleNotification = async ( notification : CodexServerNotification ) => {
14681481 userInputBridge ?. handleNotification ( notification ) ;
14691482 if ( ! projector || ! turnId ) {
@@ -1562,7 +1575,7 @@ export async function runCodexAppServerAttempt(
15621575 const isTurnAbortMarker =
15631576 isCurrentTurnNotification &&
15641577 isCodexTurnAbortMarkerNotification ( notification , { currentPromptText : promptBuild . prompt } ) ;
1565- const isTurnTerminal = isTurnCompletion || isTurnAbortMarker ;
1578+ const isTurnTerminal = isTerminalTurnNotificationForTurn ( notification , turnId ) ;
15661579 if ( isTurnTerminal ) {
15671580 terminalTurnNotificationQueued = true ;
15681581 }
@@ -1596,16 +1609,7 @@ export async function runCodexAppServerAttempt(
15961609 pendingNotifications . push ( notification ) ;
15971610 return Promise . resolve ( ) ;
15981611 }
1599- const isCurrentTurnNotification = isTurnNotification (
1600- notification . params ,
1601- thread . threadId ,
1602- turnId ,
1603- ) ;
1604- if (
1605- isCurrentTurnNotification &&
1606- ( notification . method === "turn/completed" ||
1607- isCodexTurnAbortMarkerNotification ( notification , { currentPromptText : promptBuild . prompt } ) )
1608- ) {
1612+ if ( isTerminalTurnNotificationForTurn ( notification , turnId ) ) {
16091613 terminalTurnNotificationQueued = true ;
16101614 }
16111615 notificationQueue = notificationQueue . then (
@@ -2034,6 +2038,14 @@ export async function runCodexAppServerAttempt(
20342038 nativePostToolUseRelayEnabled :
20352039 nativeHookRelay ?. allowedEvents . includes ( "post_tool_use" ) === true ,
20362040 } ) ;
2041+ if (
2042+ isTerminalTurnStatus ( turn . turn . status ) ||
2043+ pendingNotifications . some ( ( notification ) =>
2044+ isTerminalTurnNotificationForTurn ( notification , activeTurnId ) ,
2045+ )
2046+ ) {
2047+ terminalTurnNotificationQueued = true ;
2048+ }
20372049 closeCleanup = (
20382050 client as {
20392051 addCloseHandler ?: ( handler : ( client : CodexAppServerClient ) => void ) => ( ) => void ;
0 commit comments