fix(codex): clamp turn collector timeout

This commit is contained in:
Peter Steinberger
2026-05-30 15:56:29 -04:00
parent 417022864b
commit 0530596eef
2 changed files with 23 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
import { describe, expect, it, vi } from "vitest";
import { createCodexConversationTurnCollector } from "./conversation-turn-collector.js";
@@ -188,4 +189,24 @@ describe("codex conversation turn collector", () => {
vi.useRealTimers();
}
});
it("clamps oversized turn wait timers", async () => {
vi.useFakeTimers();
try {
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
const collector = createCodexConversationTurnCollector("thread-1");
collector.setTurnId("turn-1");
const completion = collector.wait({ timeoutMs: MAX_TIMER_TIMEOUT_MS + 1 });
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
collector.handleNotification({
method: "turn/completed",
params: { threadId: "thread-1", turn: { id: "turn-1", status: "completed", items: [] } },
});
await expect(completion).resolves.toEqual({ replyText: "" });
} finally {
vi.useRealTimers();
}
});
});

View File

@@ -1,3 +1,4 @@
import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
import { asOptionalRecord as readRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
import {
readCodexNotificationThreadId,
@@ -143,7 +144,7 @@ export function createCodexConversationTurnCollector(threadId: string) {
reject(new Error("codex app-server bound turn timed out"));
clearWaitState();
},
Math.max(100, params.timeoutMs),
resolveTimerTimeoutMs(params.timeoutMs, 100, 100),
);
timeout.unref?.();
});