Skip to content

fix(responses): safely initialize reasoning summary array during event accumulation - #2018

Open
hsusul wants to merge 1 commit into
openai:mainfrom
hsusul:fix/responses-reasoning-summary-array-initialization
Open

fix(responses): safely initialize reasoning summary array during event accumulation#2018
hsusul wants to merge 1 commit into
openai:mainfrom
hsusul:fix/responses-reasoning-summary-array-initialization

Conversation

@hsusul

@hsusul hsusul commented Jul 26, 2026

Copy link
Copy Markdown
  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Problem

When processing streaming events in accumulateResponse, accumulating reasoning summary events (response.reasoning_summary_part.added, response.reasoning_summary_part.done, response.reasoning_summary_text.delta, and response.reasoning_summary_text.done) on reasoning output items where summary was omitted or uninitialized (e.g. when an output item of type reasoning is added without a pre-initialized summary array) causes an uncaught JavaScript runtime error: TypeError: Cannot read properties of undefined (reading 'push') or TypeError: Cannot read properties of undefined (reading '0').

Root Cause

  1. ResponseAccumulator.ts attempted to call output.summary.push(...) in response.reasoning_summary_part.added without checking if output.summary was defined, unlike response.content_part.added which explicitly initializes output.content = [] when nullish.
  2. response.reasoning_summary_part.done, response.reasoning_summary_text.delta, and response.reasoning_summary_text.done passed output.summary directly to getContent(output.summary, event.summary_index). When output.summary was undefined, getContent accessed content[contentIndex], throwing an unhandled TypeError.

Solution

  1. Added nullish array initialization (if (!output.summary) output.summary = [];) to response.reasoning_summary_part.added, response.reasoning_summary_part.done, response.reasoning_summary_text.delta, and response.reasoning_summary_text.done in src/lib/responses/ResponseAccumulator.ts.
  2. Updated getContent to check for nullish content arrays and throw a clear OpenAIError instead of throwing a raw JavaScript TypeError.

Regression Coverage

Added a unit test in tests/lib/ResponseAccumulator.test.ts ('handles reasoning summary events on output items with uninitialized summary') verifying that reasoning output items with uninitialized summary arrays safely accumulate summary_text parts and deltas.

Validation

  • npx jest tests/lib/ResponseAccumulator.test.ts (Passed 8/8)
  • npx jest tests/lib (Passed 16/16 test suites, 400/400 tests)
  • pnpm build (Passed with zero errors)
  • pnpm lint (Passed formatting, ESLint, and TypeScript type checks)
  • git diff --check (Passed cleanly)

Generated Code Impact

None. Changes are strictly confined to manually maintained files under src/lib/responses/ and tests/lib/.

@hsusul
hsusul requested a review from a team as a code owner July 26, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant