Skip to content

Commit bea0183

Browse files
jincheng-xydtclaude
andcommitted
fix(codex): honor timeoutSeconds when timeoutMs is absent in dynamic tool hard timeout (#98864)
Dynamic tool calls can carry a timeoutSeconds field while omitting timeoutMs. The hard-call timeout reader only checked timeoutMs, so a tool configured with timeoutSeconds fell through to the default hard-call guard. Update readDynamicToolCallTimeoutMs to treat timeoutSeconds as the seconds-form fallback when timeoutMs is absent, reusing the existing readTimeoutSecondsAsMs helper for consistency with media image config. Acceptance: - timeoutMs keeps existing behavior (takes precedence) - timeoutSeconds used as hard timeout when timeoutMs absent - Invalid/non-positive timeoutSeconds ignored (falls to default) - Values exceeding CODEX_DYNAMIC_TOOL_MAX_TIMEOUT_MS are capped Co-Authored-By: Claude <[email protected]>
1 parent 56c2d63 commit bea0183

2 files changed

Lines changed: 119 additions & 1 deletion

File tree

‎extensions/codex/src/app-server/dynamic-tool-execution.test.ts‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,121 @@ describe("dynamic tool execution helpers", () => {
163163
).toBe(CODEX_DYNAMIC_TOOL_MAX_TIMEOUT_MS);
164164
});
165165

166+
describe("timeoutSeconds fallback", () => {
167+
it("uses timeoutSeconds when timeoutMs is absent", () => {
168+
expect(
169+
resolveDynamicToolCallTimeoutMs({
170+
call: {
171+
threadId: "thread-1",
172+
turnId: "turn-1",
173+
callId: "call-seconds",
174+
namespace: null,
175+
tool: "session_status",
176+
arguments: { timeoutSeconds: 30 },
177+
},
178+
config: undefined,
179+
}),
180+
).toBe(30_000);
181+
});
182+
183+
it("prefers timeoutMs when both timeoutMs and timeoutSeconds are provided", () => {
184+
expect(
185+
resolveDynamicToolCallTimeoutMs({
186+
call: {
187+
threadId: "thread-1",
188+
turnId: "turn-1",
189+
callId: "call-both",
190+
namespace: null,
191+
tool: "session_status",
192+
arguments: { timeoutMs: 15_000, timeoutSeconds: 60 },
193+
},
194+
config: undefined,
195+
}),
196+
).toBe(15_000);
197+
});
198+
199+
it("ignores non-number timeoutSeconds", () => {
200+
expect(
201+
resolveDynamicToolCallTimeoutMs({
202+
call: {
203+
threadId: "thread-1",
204+
turnId: "turn-1",
205+
callId: "call-str-seconds",
206+
namespace: null,
207+
tool: "session_status",
208+
arguments: { timeoutSeconds: "30" },
209+
},
210+
config: undefined,
211+
}),
212+
).toBe(CODEX_DYNAMIC_TOOL_TIMEOUT_MS);
213+
});
214+
215+
it("ignores non-positive timeoutSeconds", () => {
216+
expect(
217+
resolveDynamicToolCallTimeoutMs({
218+
call: {
219+
threadId: "thread-1",
220+
turnId: "turn-1",
221+
callId: "call-zero",
222+
namespace: null,
223+
tool: "session_status",
224+
arguments: { timeoutSeconds: 0 },
225+
},
226+
config: undefined,
227+
}),
228+
).toBe(CODEX_DYNAMIC_TOOL_TIMEOUT_MS);
229+
});
230+
231+
it("ignores negative timeoutSeconds", () => {
232+
expect(
233+
resolveDynamicToolCallTimeoutMs({
234+
call: {
235+
threadId: "thread-1",
236+
turnId: "turn-1",
237+
callId: "call-neg",
238+
namespace: null,
239+
tool: "session_status",
240+
arguments: { timeoutSeconds: -5 },
241+
},
242+
config: undefined,
243+
}),
244+
).toBe(CODEX_DYNAMIC_TOOL_TIMEOUT_MS);
245+
});
246+
247+
it("caps timeoutSeconds exceeding the maximum", () => {
248+
expect(
249+
resolveDynamicToolCallTimeoutMs({
250+
call: {
251+
threadId: "thread-1",
252+
turnId: "turn-1",
253+
callId: "call-huge-seconds",
254+
namespace: null,
255+
tool: "session_status",
256+
arguments: { timeoutSeconds: 9999 },
257+
},
258+
config: undefined,
259+
}),
260+
).toBe(CODEX_DYNAMIC_TOOL_MAX_TIMEOUT_MS);
261+
});
262+
263+
it("preserves existing timeoutMs behavior unchanged", () => {
264+
const timeoutMs = CODEX_DYNAMIC_TOOL_TIMEOUT_MS + 1_000;
265+
expect(
266+
resolveDynamicToolCallTimeoutMs({
267+
call: {
268+
threadId: "thread-1",
269+
turnId: "turn-1",
270+
callId: "call-ms-only",
271+
namespace: null,
272+
tool: "session_status",
273+
arguments: { timeoutMs },
274+
},
275+
config: undefined,
276+
}),
277+
).toBe(timeoutMs);
278+
});
279+
});
280+
166281
it("uses a 90 second default for generic Codex dynamic tool calls", () => {
167282
expect(
168283
resolveDynamicToolCallTimeoutMs({

‎extensions/codex/src/app-server/dynamic-tool-execution.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,10 @@ function readDynamicToolCallTimeoutMs(value: JsonValue | undefined): number | un
443443
if (!isJsonObject(value)) {
444444
return undefined;
445445
}
446-
return readPositiveFiniteTimeoutMs(value.timeoutMs);
446+
return (
447+
readPositiveFiniteTimeoutMs(value.timeoutMs) ??
448+
readTimeoutSecondsAsMs(value.timeoutSeconds)
449+
);
447450
}
448451

449452
function readConfiguredDynamicToolTimeoutMs(

0 commit comments

Comments
 (0)