@@ -1131,6 +1131,10 @@ export async function runCodexAppServerAttempt(
11311131 let timedOut = false ;
11321132 let turnCompletionIdleTimedOut = false ;
11331133 let turnWatchTimeoutKind : CodexAttemptTurnWatchTimeoutKind | undefined ;
1134+ let turnWatchTimeoutIdleMs : number | undefined ;
1135+ let turnWatchTimeoutMs : number | undefined ;
1136+ let turnWatchTimeoutLastActivityReason : string | undefined ;
1137+ let turnWatchTimeoutDetails : Record < string , unknown > | undefined ;
11341138 let turnCompletionIdleTimeoutMessage : string | undefined ;
11351139 let clientClosedPromptError : string | undefined ;
11361140 let clientClosedAbort = false ;
@@ -1221,6 +1225,10 @@ export async function runCodexAppServerAttempt(
12211225 timedOut = true ;
12221226 turnCompletionIdleTimedOut = true ;
12231227 turnWatchTimeoutKind = timeout . kind ;
1228+ turnWatchTimeoutIdleMs = timeout . idleMs ;
1229+ turnWatchTimeoutMs = timeout . timeoutMs ;
1230+ turnWatchTimeoutLastActivityReason = timeout . lastActivityReason ;
1231+ turnWatchTimeoutDetails = timeout . details ;
12241232 turnCompletionIdleTimeoutMessage =
12251233 "codex app-server turn idle timed out waiting for turn/completed" ;
12261234 } ,
@@ -2302,7 +2310,18 @@ export async function runCodexAppServerAttempt(
23022310 const promptTimeoutOutcome = buildCodexAppServerPromptTimeoutOutcome ( {
23032311 result,
23042312 turnCompletionIdleTimedOut,
2313+ turnWatchTimeoutKind,
23052314 } ) ;
2315+ const codexAppServerFailureDiagnostics =
2316+ codexAppServerFailureKind === "turn_completion_idle_timeout" &&
2317+ turnWatchTimeoutKind === "completion"
2318+ ? buildCodexAppServerTimeoutDiagnostics ( {
2319+ idleMs : turnWatchTimeoutIdleMs ,
2320+ timeoutMs : turnWatchTimeoutMs ,
2321+ lastActivityReason : turnWatchTimeoutLastActivityReason ,
2322+ details : turnWatchTimeoutDetails ,
2323+ } )
2324+ : undefined ;
23062325 const modelCallFailureKind =
23072326 classifyCodexModelCallFailureKind ( {
23082327 error : finalPromptError ,
@@ -2470,6 +2489,9 @@ export async function runCodexAppServerAttempt(
24702489 ...( codexAppServerReplayBlockedReason
24712490 ? { replayBlockedReason : codexAppServerReplayBlockedReason }
24722491 : { } ) ,
2492+ ...( codexAppServerFailureDiagnostics
2493+ ? { diagnostics : codexAppServerFailureDiagnostics }
2494+ : { } ) ,
24732495 } ,
24742496 }
24752497 : { } ) ,
@@ -2654,6 +2676,64 @@ function waitForCodexNotificationDispatchTurn(): Promise<void> {
26542676 } ) ;
26552677}
26562678
2679+ function buildCodexAppServerTimeoutDiagnostics ( params : {
2680+ idleMs ?: number ;
2681+ timeoutMs ?: number ;
2682+ lastActivityReason ?: string ;
2683+ details ?: Record < string , unknown > ;
2684+ } ) : NonNullable < EmbeddedRunAttemptResult [ "codexAppServerFailure" ] > [ "diagnostics" ] {
2685+ const readString = ( key : string ) => {
2686+ const value = params . details ?. [ key ] ;
2687+ return typeof value === "string" && value . trim ( ) ? value : undefined ;
2688+ } ;
2689+ const readNumber = ( key : string ) => {
2690+ const value = params . details ?. [ key ] ;
2691+ return typeof value === "number" && Number . isFinite ( value ) ? value : undefined ;
2692+ } ;
2693+ const readBoolean = ( key : string ) => {
2694+ const value = params . details ?. [ key ] ;
2695+ return typeof value === "boolean" ? value : undefined ;
2696+ } ;
2697+ return {
2698+ ...( params . idleMs !== undefined ? { idleMs : params . idleMs } : { } ) ,
2699+ ...( params . timeoutMs !== undefined ? { timeoutMs : params . timeoutMs } : { } ) ,
2700+ ...( params . lastActivityReason ? { lastActivityReason : params . lastActivityReason } : { } ) ,
2701+ ...( readString ( "lastNotificationMethod" )
2702+ ? { lastNotificationMethod : readString ( "lastNotificationMethod" ) }
2703+ : { } ) ,
2704+ ...( readString ( "lastNotificationItemId" )
2705+ ? { lastNotificationItemId : readString ( "lastNotificationItemId" ) }
2706+ : { } ) ,
2707+ ...( readString ( "lastNotificationItemType" )
2708+ ? { lastNotificationItemType : readString ( "lastNotificationItemType" ) }
2709+ : { } ) ,
2710+ ...( readString ( "lastNotificationItemRole" )
2711+ ? { lastNotificationItemRole : readString ( "lastNotificationItemRole" ) }
2712+ : { } ) ,
2713+ ...( readString ( "lastAssistantTextPreview" )
2714+ ? { lastAssistantTextPreview : readString ( "lastAssistantTextPreview" ) }
2715+ : { } ) ,
2716+ ...( readNumber ( "activeAppServerTurnRequests" ) !== undefined
2717+ ? { activeAppServerTurnRequests : readNumber ( "activeAppServerTurnRequests" ) }
2718+ : { } ) ,
2719+ ...( readNumber ( "activeTurnItemCount" ) !== undefined
2720+ ? { activeTurnItemCount : readNumber ( "activeTurnItemCount" ) }
2721+ : { } ) ,
2722+ ...( readBoolean ( "terminalTurnNotificationQueued" ) !== undefined
2723+ ? { terminalTurnNotificationQueued : readBoolean ( "terminalTurnNotificationQueued" ) }
2724+ : { } ) ,
2725+ ...( readBoolean ( "completionIdleWatchArmed" ) !== undefined
2726+ ? { completionIdleWatchArmed : readBoolean ( "completionIdleWatchArmed" ) }
2727+ : { } ) ,
2728+ ...( readBoolean ( "assistantCompletionIdleWatchArmed" ) !== undefined
2729+ ? { assistantCompletionIdleWatchArmed : readBoolean ( "assistantCompletionIdleWatchArmed" ) }
2730+ : { } ) ,
2731+ ...( readBoolean ( "terminalIdleWatchArmed" ) !== undefined
2732+ ? { terminalIdleWatchArmed : readBoolean ( "terminalIdleWatchArmed" ) }
2733+ : { } ) ,
2734+ } ;
2735+ }
2736+
26572737function handleApprovalRequest ( params : {
26582738 method : string ;
26592739 params : JsonValue | undefined ;
0 commit comments