Skip to content

ResponseStream rejects with a plain object when the API emits an error event #2020

Description

@morgan-coded

Streaming a Responses request that surfaces an API error frame rejects
finalResponse() with a plain object instead of an OpenAIError, so
instanceof-based error handling misses it.

Repro against the shipped class — no network, replaying a captured frame
through ResponseStream.fromReadableStream:

finalResponse REJECTED: isError=false isOpenAIError=false
raw= {"type":"error","code":"server_error","message":"boom","sequence_number":1}

Cause: error is a legitimate member of ResponseStreamEvent, so
#addEvent's default: arm re-emits it as an ordinary listener payload, and
EventStream._emit then rejects with the raw frame. The Assistants helper
handles the same class explicitly (AssistantStream.ts:381, "errors should be
processed earlier"), and the realtime emitter converts properly — Responses is
the only stream helper that doesn't.

Sending a PR alongside this: convert the frame in ResponseStream's error path,
mirroring the Assistants handling. The alternative is a transport-layer fix in
core/streaming.ts (which carries an unresolved TODO asking exactly this
question) — happy to move it there instead if you'd rather weigh the
Chat-Completions blast radius.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions