Skip to content

Commit 87d52ad

Browse files
committed
fix: add 3s timeout to warmup request to prevent exit hang
Codex review found that the fire-and-forget warmup models.list() had no timeout. The OpenAI client defaults to a 10-minute timeout, so an unreachable API could keep the Node process alive long after the user exits.
1 parent db78e2b commit 87d52ad

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/ui/App.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,17 @@ export function createOpenAIClient(projectRoot: string = process.cwd()): {
796796
_cachedOpenAIKey = cacheKey;
797797

798798
// Fire-and-forget warmup: pre-establish TCP+TLS connection to the API
799-
// server while the user is composing their first prompt. Errors are
800-
// silently ignored — the real request will retry on its own if needed.
801-
void _cachedOpenAI.models.list().catch(() => {});
799+
// server while the user is composing their first prompt. Bounded by a
800+
// short timeout so a slow / unreachable API never blocks process exit.
801+
void (async () => {
802+
const ac = new AbortController();
803+
const timer = setTimeout(() => ac.abort(), 3000);
804+
try {
805+
await _cachedOpenAI.models.list({ signal: ac.signal }).catch(() => {});
806+
} finally {
807+
clearTimeout(timer);
808+
}
809+
})();
802810

803811
return {
804812
client: _cachedOpenAI,

0 commit comments

Comments
 (0)