Skip to content

[BUG] OpenAI Native provider — dual SSE event processing (dead code in handleStreamResponse) #506

@DScoNOIZ

Description

@DScoNOIZ

Description

The OpenAiNativeHandler in src/api/providers/openai-native.ts has two parallel sets of SSE event handlers that process the same event types:

  1. processEvent() (line 1159) — the "shared event processor" for core event types
  2. handleStreamResponse() (line 687) — contains its own handlers for the same event types

The problem

In handleStreamResponse(), core events are first delegated to processEvent() (lines 732-748) via coreHandledEventTypes, followed by a continue statement. However, the code below (lines 787-1113) contains fallback handlers that duplicate the same logic as processEvent() for identical event types:

  • response.text.delta / response.output_text.delta
  • response.text.done / response.output_text.done
  • response.reasoning.delta / response.reasoning_text.delta
  • response.reasoning_summary.delta / response.reasoning_summary_text.delta
  • response.refusal.delta
  • response.content_part.added / response.content_part.done
  • response.output_item.added / response.output_item.done
  • response.tool_call_arguments.delta / response.function_call_arguments.delta
  • response.tool_call_arguments.done / response.function_call_arguments.done

All of these are already in coreHandledEventTypes (set at line 64) and get delegated to processEvent(), making the fallback code dead code in the SDK path.

Risk

If the SDK path fails and falls back to makeResponsesApiRequest()handleStreamResponse(), and an event type is NOT in coreHandledEventTypes but IS handled in the fallback section, that event could be processed twice — once by processEvent() and once by the fallback handler.

Root cause

The file evolved organically: processEvent() was added later as the shared processor, but the original handlers in handleStreamResponse() were not removed, creating dead/duplicated code that is confusing to maintain.

Suggested fix

  1. Remove the duplicated event handlers from handleStreamResponse() for all event types already in coreHandledEventTypes
  2. Ensure all event types that need handling are in coreHandledEventTypes
  3. Keep only truly unique fallback logic in handleStreamResponse() (e.g., raw SSE parsing paths, non-core event types)

Found during code analysis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions