Description
The OpenAiNativeHandler in src/api/providers/openai-native.ts has two parallel sets of SSE event handlers that process the same event types:
processEvent() (line 1159) — the "shared event processor" for core event types
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
- Remove the duplicated event handlers from
handleStreamResponse() for all event types already in coreHandledEventTypes
- Ensure all event types that need handling are in
coreHandledEventTypes
- Keep only truly unique fallback logic in
handleStreamResponse() (e.g., raw SSE parsing paths, non-core event types)
Found during code analysis.
Description
The
OpenAiNativeHandlerinsrc/api/providers/openai-native.tshas two parallel sets of SSE event handlers that process the same event types:processEvent()(line 1159) — the "shared event processor" for core event typeshandleStreamResponse()(line 687) — contains its own handlers for the same event typesThe problem
In
handleStreamResponse(), core events are first delegated toprocessEvent()(lines 732-748) viacoreHandledEventTypes, followed by acontinuestatement. However, the code below (lines 787-1113) contains fallback handlers that duplicate the same logic asprocessEvent()for identical event types:response.text.delta/response.output_text.deltaresponse.text.done/response.output_text.doneresponse.reasoning.delta/response.reasoning_text.deltaresponse.reasoning_summary.delta/response.reasoning_summary_text.deltaresponse.refusal.deltaresponse.content_part.added/response.content_part.doneresponse.output_item.added/response.output_item.doneresponse.tool_call_arguments.delta/response.function_call_arguments.deltaresponse.tool_call_arguments.done/response.function_call_arguments.doneAll of these are already in
coreHandledEventTypes(set at line 64) and get delegated toprocessEvent(), 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 incoreHandledEventTypesbut IS handled in the fallback section, that event could be processed twice — once byprocessEvent()and once by the fallback handler.Root cause
The file evolved organically:
processEvent()was added later as the shared processor, but the original handlers inhandleStreamResponse()were not removed, creating dead/duplicated code that is confusing to maintain.Suggested fix
handleStreamResponse()for all event types already incoreHandledEventTypescoreHandledEventTypeshandleStreamResponse()(e.g., raw SSE parsing paths, non-core event types)Found during code analysis.