Skip to content

fix: subscribeToBatch Zod stream crash on partial shape updates (#3510)#3699

Closed
deepshekhardas wants to merge 1 commit into
triggerdotdev:mainfrom
deepshekhardas:fix/3510-zod-stream-partial-shapes
Closed

fix: subscribeToBatch Zod stream crash on partial shape updates (#3510)#3699
deepshekhardas wants to merge 1 commit into
triggerdotdev:mainfrom
deepshekhardas:fix/3510-zod-stream-partial-shapes

Conversation

@deepshekhardas
Copy link
Copy Markdown

When ElectricSQL sends partial shape updates during initial sync (where not all columns are present in every message), zodShapeStream would crash the entire ReadableStream by calling controller.error(). This killed the subscription for all downstream consumers.

Fixes the issue by logging a warning and skipping unparseable chunks instead of terminating the stream. The RowState in ReadableShapeStream correctly accumulates full row data across insert/update messages and only emits when up-to-date, but edge cases during reconnection or initial sync could emit incomplete rows.

…gerdotdev#3510)

Change zodShapeStream to skip unparseable chunks instead of crashing
the entire stream. When ElectricSQL sends partial shape updates during
initial sync (missing fields like taskIdentifier, friendlyId, createdAt),
the Zod safeParse fails and controller.error() terminates the stream
for all subscribers. Now logs a warning and skips the chunk instead.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 22, 2026

⚠️ No Changeset found

Latest commit: 6f59b56

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6c2ff71c-ee96-400c-81ae-88e1936426cd

📥 Commits

Reviewing files that changed from the base of the PR and between c80b85e and 6f59b56.

📒 Files selected for processing (1)
  • packages/core/src/v3/apiClient/stream.ts

Walkthrough

This PR modifies the error-handling logic in zodShapeStream within the API client stream processing. When a received chunk fails Zod schema validation, the code now checks for console availability, logs a warning message about the skipped chunk, and continues processing the stream instead of throwing an error that would terminate the stream.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

Hi @deepshekhardas, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this May 22, 2026
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment on lines +65 to 69
} else if (typeof console !== "undefined") {
console.warn(
`[zodShapeStream] Skipping unparseable shape chunk: ${result.error.message}`
);
}
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.

@deepshekhardas
Copy link
Copy Markdown
Author

Hi team, this fixes #3510 — subscribeToBatch/subscribeToRun stream crashes when ElectricSQL sends partial shape updates during initial sync. Stream now skips unparseable chunks instead of terminating. Would appreciate a review and merge. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant