1+ /**
2+ * Timeout, terminal-release, and diagnostic helpers for Codex dynamic tool
3+ * calls.
4+ */
15import {
26 embeddedAgentLog ,
37 type EmbeddedRunAttemptParams ,
@@ -15,10 +19,14 @@ import {
1519 type JsonValue ,
1620} from "./protocol.js" ;
1721
22+ /** Default timeout for Codex dynamic tool calls. */
1823export const CODEX_DYNAMIC_TOOL_TIMEOUT_MS = 90_000 ;
24+ /** Hard cap for per-call Codex dynamic tool timeout overrides. */
1925export const CODEX_DYNAMIC_TOOL_MAX_TIMEOUT_MS = 600_000 ;
2026const CODEX_DYNAMIC_IMAGE_GENERATION_TOOL_TIMEOUT_MS = 120_000 ;
27+ /** Timeout for image-understanding style dynamic tool calls. */
2128export const CODEX_DYNAMIC_IMAGE_TOOL_TIMEOUT_MS = 60_000 ;
29+ /** Timeout for message-delivery dynamic tool calls. */
2230export const CODEX_DYNAMIC_MESSAGE_TOOL_TIMEOUT_MS = 120_000 ;
2331const LOG_FIELD_MAX_LENGTH = 160 ;
2432
@@ -109,6 +117,10 @@ function formatDynamicToolTimeoutDetails(params: {
109117 } ;
110118}
111119
120+ /**
121+ * Runs a dynamic tool call with run-abort and per-call timeout handling,
122+ * returning a Codex protocol response instead of throwing.
123+ */
112124export async function handleDynamicToolCallWithTimeout ( params : {
113125 call : CodexDynamicToolCallParams ;
114126 toolBridge : Pick < CodexDynamicToolBridge , "handleToolCall" > ;
@@ -199,6 +211,7 @@ function failedDynamicToolResponse(
199211 return response ;
200212}
201213
214+ /** Strips OpenClaw-only metadata before sending a dynamic tool response to Codex. */
202215export function toCodexDynamicToolProtocolResponse (
203216 response : CodexDynamicToolCallResponse ,
204217) : CodexDynamicToolCallResponse {
@@ -208,6 +221,7 @@ export function toCodexDynamicToolProtocolResponse(
208221 } ;
209222}
210223
224+ /** Adds async-started progress details when a tool result continues out of band. */
211225export function toCodexDynamicToolProgressResponse (
212226 response : CodexDynamicToolCallResponse ,
213227 protocolResponse : CodexDynamicToolCallResponse ,
@@ -236,6 +250,7 @@ type TerminalDynamicToolReleaseState = {
236250 pendingOpenClawDynamicToolCompletionIdsCount : number ;
237251} ;
238252
253+ /** Decides whether a terminal dynamic tool response can release the Codex turn. */
239254export function shouldReleaseTurnAfterTerminalDynamicTool (
240255 state : TerminalDynamicToolReleaseState ,
241256) : boolean {
@@ -250,12 +265,14 @@ export function shouldReleaseTurnAfterTerminalDynamicTool(
250265 ) ;
251266}
252267
268+ /** Returns true when a non-async result should block terminal-release shortcuts. */
253269export function shouldBlockTerminalReleaseForNonTerminalDynamicToolResult (
254270 response : CodexDynamicToolCallResponse ,
255271) : boolean {
256272 return response . asyncStarted !== true ;
257273}
258274
275+ /** Action chosen after checking terminal dynamic-tool diagnostics. */
259276export type TerminalDynamicToolBatchAction =
260277 | "idle"
261278 | "wait"
@@ -270,6 +287,7 @@ type TerminalDynamicToolBatchState = {
270287 hasPendingTerminalDynamicToolRelease : boolean ;
271288} ;
272289
290+ /** Resolves whether terminal diagnostic state should release, wait, or stay idle. */
273291export function resolveTerminalDynamicToolBatchAction (
274292 state : TerminalDynamicToolBatchState ,
275293) : TerminalDynamicToolBatchAction {
@@ -289,6 +307,7 @@ export function resolveTerminalDynamicToolBatchAction(
289307 return "idle" ;
290308}
291309
310+ /** Returns true for diagnostic events that terminate a dynamic tool call. */
292311export function isDynamicToolTerminalDiagnosticEvent (
293312 event : DiagnosticEventPayload ,
294313) : event is TerminalToolExecutionDiagnostic {
@@ -299,6 +318,7 @@ export function isDynamicToolTerminalDiagnosticEvent(
299318 ) ;
300319}
301320
321+ /** Matches terminal diagnostics to a specific dynamic tool call id/name. */
302322export function isMatchingDynamicToolTerminalDiagnostic ( params : {
303323 event : TerminalToolExecutionDiagnostic ;
304324 call : CodexDynamicToolCallParams ;
@@ -328,6 +348,7 @@ export function isMatchingDynamicToolTerminalDiagnostic(params: {
328348 ) ;
329349}
330350
351+ /** Checks pending diagnostics for a terminal event matching a tool call. */
331352export function hasPendingDynamicToolTerminalDiagnostic ( params : {
332353 call : CodexDynamicToolCallParams ;
333354 runId ?: string ;
@@ -348,6 +369,7 @@ export function hasPendingDynamicToolTerminalDiagnostic(params: {
348369 } ) ;
349370}
350371
372+ /** Resolves per-tool timeout, applying media/message defaults and hard caps. */
351373export function resolveDynamicToolCallTimeoutMs ( params : {
352374 call : CodexDynamicToolCallParams ;
353375 config : EmbeddedRunAttemptParams [ "config" ] ;
0 commit comments