Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/core/src/v3/apiClient/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ export function zodShapeStream<TShapeSchema extends z.ZodTypeAny>(

if (result.success) {
controller.enqueue(result.data);
} else {
controller.error(new Error(`Unable to parse shape: ${result.error.message}`));
} else if (typeof console !== "undefined") {
console.warn(
`[zodShapeStream] Skipping unparseable shape chunk: ${result.error.message}`
);
}
Comment on lines +65 to 69

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Parse failures silently dropped without notifying the onError callback

When a shape chunk fails Zod validation, the new code logs a console.warn and silently drops the chunk, but never invokes the options.onError callback (stream.ts:19). This means consumers have no programmatic way to detect that data is being silently discarded. In the worst case (e.g., a schema version mismatch between server and client after an upgrade), ALL chunks would fail to parse, causing the stream to produce zero data while appearing healthy — no error is thrown, no onError is called, and the consumer's for await loop hangs forever. For RunSubscription consumers (runStream.ts:616-637), this could mean a realtime subscription that never delivers any run updates and never completes, with no signal to the caller that something is wrong. The previous behavior (controller.error(...)) at least surfaced the problem immediately. The fix should invoke options?.onError?.(...) when parse failures occur, so consumers can detect and handle dropped data.

Suggested change
} else if (typeof console !== "undefined") {
console.warn(
`[zodShapeStream] Skipping unparseable shape chunk: ${result.error.message}`
);
}
} else {
if (typeof console !== "undefined") {
console.warn(
`[zodShapeStream] Skipping unparseable shape chunk: ${result.error.message}`
);
}
options?.onError?.(new Error(`Unable to parse shape: ${result.error.message}`));
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

},
})
Expand Down