From 19262f632f8d80c06c9a11a46cfc0c21f4a1487a Mon Sep 17 00:00:00 2001 From: Pranav <56645758+pranav4501@users.noreply.github.com> Date: Sat, 10 May 2025 18:16:19 -0500 Subject: [PATCH] fix: guard against missing choices (#817) - Fixes guard by using optional chaining to safely check chunk.choices?.[0] before accessing. - Currently, accessing chunk.choices[0] without checking could throw if choices was missing from the chunk. --- codex-cli/src/utils/responses.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codex-cli/src/utils/responses.ts b/codex-cli/src/utils/responses.ts index 6a763ebf..f0586ba4 100644 --- a/codex-cli/src/utils/responses.ts +++ b/codex-cli/src/utils/responses.ts @@ -487,7 +487,7 @@ async function* streamResponses( let isToolCall = false; for await (const chunk of completion as AsyncIterable) { // console.error('\nCHUNK: ', JSON.stringify(chunk)); - const choice = chunk.choices[0]; + const choice = chunk.choices?.[0]; if (!choice) { continue; }