What issue are you seeing?
The TypeScript SDK defines a top-level fatal stream error event, but Thread.run() does not handle it.
ThreadErrorEvent is defined in sdk/typescript/src/events.ts as:
export type ThreadErrorEvent = {
type: "error";
message: string;
};
and it is included in the ThreadEvent union.
However, Thread.run() in sdk/typescript/src/thread.ts only handles:
item.completed
turn.completed
turn.failed
It does not handle event.type === "error".
As a result, if the underlying CodexExec.run() stream emits a fatal top-level error event, Thread.run() resolves successfully with an empty turn instead of rejecting.
Observed result from a focused local regression test:
{
"items": [],
"finalResponse": "",
"usage": null
}
This can make SDK callers interpret a fatal stream failure as a successful empty response.
What steps can reproduce the bug?
Using current openai/codex main at 155c04ad4, add a focused Jest test that stubs CodexExec.run() to emit a top-level error event:
import { Thread } from "../src/thread";
it("throws on fatal top-level stream errors", async () => {
const exec = {
async *run() {
yield JSON.stringify({ type: "error", message: "fatal stream error" });
},
};
const thread = new Thread(exec as never, {}, {});
await expect(thread.run("fail")).rejects.toThrow("fatal stream error");
});
Then run:
corepack pnpm --filter @openai/codex-sdk exec jest tests/run.test.ts -t "fatal top-level" --runInBand
Current result:
Received promise resolved instead of rejected
Resolved to value: {"finalResponse": "", "items": [], "usage": null}
What is the expected behavior?
Thread.run() should reject when it receives a fatal top-level stream error event.
A narrow fix would be to handle event.type === "error" in sdk/typescript/src/thread.ts, for example by throwing new Error(event.message), and add regression coverage for this case.
Additional information
I searched existing issues and PRs for Thread.run, runStreamed, ThreadErrorEvent, top-level stream errors, and TypeScript SDK stream error handling, and did not find an exact duplicate.
This is separate from normal turn.failed handling. The issue is specifically that the SDK event union already includes a top-level ThreadErrorEvent, but the buffered Thread.run() API ignores it.
What issue are you seeing?
The TypeScript SDK defines a top-level fatal stream error event, but
Thread.run()does not handle it.ThreadErrorEventis defined insdk/typescript/src/events.tsas:and it is included in the
ThreadEventunion.However,
Thread.run()insdk/typescript/src/thread.tsonly handles:item.completedturn.completedturn.failedIt does not handle
event.type === "error".As a result, if the underlying
CodexExec.run()stream emits a fatal top-level error event,Thread.run()resolves successfully with an empty turn instead of rejecting.Observed result from a focused local regression test:
{ "items": [], "finalResponse": "", "usage": null }This can make SDK callers interpret a fatal stream failure as a successful empty response.
What steps can reproduce the bug?
Using current
openai/codexmain at155c04ad4, add a focused Jest test that stubsCodexExec.run()to emit a top-level error event:Then run:
Current result:
What is the expected behavior?
Thread.run()should reject when it receives a fatal top-level stream error event.A narrow fix would be to handle
event.type === "error"insdk/typescript/src/thread.ts, for example by throwingnew Error(event.message), and add regression coverage for this case.Additional information
I searched existing issues and PRs for
Thread.run,runStreamed,ThreadErrorEvent, top-level stream errors, and TypeScript SDK stream error handling, and did not find an exact duplicate.This is separate from normal
turn.failedhandling. The issue is specifically that the SDK event union already includes a top-levelThreadErrorEvent, but the bufferedThread.run()API ignores it.