Skip to content

fix: wrap JSON.parse in try/catch and fix maxAttempts undefined check#4357

Closed
PedroHenrique0713 wants to merge 1 commit into
triggerdotdev:mainfrom
PedroHenrique0713:fix/json-parse-and-retry
Closed

fix: wrap JSON.parse in try/catch and fix maxAttempts undefined check#4357
PedroHenrique0713 wants to merge 1 commit into
triggerdotdev:mainfrom
PedroHenrique0713:fix/json-parse-and-retry

Conversation

@PedroHenrique0713

Copy link
Copy Markdown

Summary

Two bug fixes in Trigger.dev core package.

1. Unhandled JSON.parse rejection in

parsePacket and parsePacketAsJson called JSON.parse without try/catch on payloads. Malformed/truncated JSON threw unhandled promise rejections, breaking the stream pipeline. Fix: wrap in try/catch, return undefined on parse failure.

2. NaN comparison bypasses rate-limit guard in apiClient

retryOptions.maxAttempts! used non-null assertion but the type allows undefined. When undefined, attempt >= undefined evaluates to NaN (always falsy), silently allowing infinite retries on HTTP 429 responses. Fix: check for undefined before comparing.

…pts null check

fix(ioSerialization): wrap JSON.parse in try/catch for malformed JSON.
  Malformed or truncated JSON payloads in parsePacket/parsePacketAsJson
  threw unhandled promise rejections, breaking the stream pipeline.

fix(apiClient): guard maxAttempts against undefined in rate-limit check.
  Non-null assertion bypassed silently when maxAttempts was undefined,
  allowing infinite retries on HTTP 429 responses.
@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ef9248a

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

@github-actions

Copy link
Copy Markdown
Contributor

Hi @PedroHenrique0713, 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 Jul 23, 2026

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

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.

Devin Review found 2 potential issues.

Open in Devin Review

// Retry on rate limits with special handling for Retry-After
if (response.status === 429) {
if (attempt >= retryOptions.maxAttempts!) {
if (retryOptions.maxAttempts !== undefined && attempt >= retryOptions.maxAttempts) {

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.

🟡 Missing release note entry for a change to a published package

This pull request modifies a published package but does not include the required changeset entry (change in packages/core/src/v3/apiClient/index.ts:2378), so the fix will not appear in the user-visible release notes.
Impact: The bug fixes ship without any changelog/release-note entry and the package version will not be bumped.

Repository changeset rule

AGENTS.md and CONTRIBUTING.md both state that any change to a public package (packages/*) must include a changeset (pnpm run changeset:add). This PR changes packages/core/src/v3/apiClient/index.ts and packages/core/src/v3/utils/ioSerialization.ts but adds no file under .changeset/.

Prompt for agents
This PR modifies the published package @trigger.dev/core (packages/core) but does not include a changeset. Per AGENTS.md and CONTRIBUTING.md, any change to a public package under packages/* requires a changeset. Run pnpm run changeset:add and select a patch bump for @trigger.dev/core with a user-facing description of the two bug fixes (JSON.parse now returns undefined on malformed payloads instead of throwing, and the rate-limit retry guard no longer allows unbounded retries when maxAttempts is undefined).
Open in Devin Review

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

Comment on lines 39 to 40
case "application/super+json":
return superjson.parse(value.data);

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.

🔍 super+json parse path remains unwrapped despite PR claiming both parse functions are fixed

The PR description states malformed/truncated payloads caused unhandled rejections in parsePacket/parsePacketAsJson. The fix only wraps the application/json case in try/catch. The application/super+json case (superjson.parse(value.data) at packages/core/src/v3/utils/ioSerialization.ts:40 and :68) can also throw on malformed data and remains uncaught. If super+json packets can be truncated/corrupted the same way, this fix is incomplete and those paths will still reject. Worth confirming whether super+json payloads share the same corruption risk.

Open in Devin Review

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

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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 Plus

Run ID: e34726d8-c950-4318-9224-cc751b0d1aaa

📥 Commits

Reviewing files that changed from the base of the PR and between 722e240 and ef9248a.

📒 Files selected for processing (2)
  • packages/core/src/v3/apiClient/index.ts
  • packages/core/src/v3/utils/ioSerialization.ts

Walkthrough

Updated stream batch retry logic to safely handle an undefined maxAttempts value. Added error handling to application/json parsing in parsePacket and parsePacketAsJson so invalid JSON returns undefined instead of throwing. Other packet data types retain their existing behavior.

✨ 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.

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