diff --git a/src/cli/helpers/stream.ts b/src/cli/helpers/stream.ts index b619f79..1c957b0 100644 --- a/src/cli/helpers/stream.ts +++ b/src/cli/helpers/stream.ts @@ -364,7 +364,6 @@ export async function drainStreamWithResume( if ( result.stopReason === "error" && result.lastRunId && - result.lastSeqId !== null && abortSignal && !abortSignal.aborted ) { @@ -400,7 +399,9 @@ export async function drainStreamWithResume( const resumeStream = await client.runs.messages.stream( result.lastRunId, { - starting_after: result.lastSeqId, + // If lastSeqId is null the stream failed before any seq_id-bearing + // chunk arrived; use 0 to replay the run from the beginning. + starting_after: result.lastSeqId ?? 0, batch_size: 1000, // Fetch buffered chunks quickly }, // { maxRetries: 0 }, @@ -457,8 +458,6 @@ export async function drainStreamWithResume( if (result.stopReason === "error") { const skipReasons: string[] = []; if (!result.lastRunId) skipReasons.push("no_run_id"); - if (result.lastSeqId === null || result.lastSeqId === undefined) - skipReasons.push("no_seq_id"); if (!abortSignal) skipReasons.push("no_abort_signal"); if (abortSignal?.aborted) skipReasons.push("user_aborted"); diff --git a/src/cli/helpers/streamProcessor.ts b/src/cli/helpers/streamProcessor.ts index 9147081..652be0e 100644 --- a/src/cli/helpers/streamProcessor.ts +++ b/src/cli/helpers/streamProcessor.ts @@ -52,7 +52,7 @@ export class StreamProcessor { } // Track seq_id (drainStream line 122-124) - if ("seq_id" in chunk && chunk.seq_id) { + if ("seq_id" in chunk && chunk.seq_id != null) { this.lastSeqId = chunk.seq_id; }