Skip to content

feat(marqs): optimize batch context fetching in sharedQueueConsumer - #4466

Closed
deepshekhardas wants to merge 3 commits into
triggerdotdev:mainfrom
deepshekhardas:feat/legend-batch-optimization
Closed

feat(marqs): optimize batch context fetching in sharedQueueConsumer#4466
deepshekhardas wants to merge 3 commits into
triggerdotdev:mainfrom
deepshekhardas:feat/legend-batch-optimization

Conversation

@deepshekhardas

Copy link
Copy Markdown

Performance optimization for batch context fetching in sharedQueueConsumer.

deepshekhardas added 3 commits February 14, 2026 07:14
triggerdotdev#2796)

When a user removes the machine configuration from a task and redeploys, task.machine becomes undefined. Prisma's create() silently skips undefined fields for Json columns rather than setting them to NULL. This change uses the nullish coalescing operator to explicitly pass null, ensuring the machineConfig column is cleared in the database.
…undWorkerTask create

Applied the fix pattern to ensure retryConfig, queueConfig, and payloadSchema are also explicitly cleared when removed from task definition, as suggested in PR feedback.
Efficiently select and map batch relation in AttemptForExecutionGetPayload and _executionFromAttempt to restore batch context during dequeue. Part of Legend Rank mission.
@changeset-bot

changeset-bot Bot commented Aug 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 152c383

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

github-actions Bot commented Aug 2, 2026

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 Aug 2, 2026
@coderabbitai

coderabbitai Bot commented Aug 2, 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: d4661251-3a7e-44b7-acd3-7890f34f739d

📥 Commits

Reviewing files that changed from the base of the PR and between 14824b0 and 152c383.

📒 Files selected for processing (2)
  • apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts
  • apps/webapp/app/v3/services/createBackgroundWorker.server.ts

Walkthrough

The queue consumer now selects optional task-run batch identifiers and includes the batch friendly ID in execution payloads. Existing work scheduling, deployment selection, and resume payload behavior remain unchanged. Worker task creation now stores absent retry, queue, machine, and payload schema values as null.

✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch feat/legend-batch-optimization
🧪 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.

@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 3 potential issues.

Open in Devin Review

console.log("✅ Started the SharedQueueConsumer");

this.#doWork().finally(() => {});
this.#doWork().finally(() => { });

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.

🟡 Code committed without running the required formatter

Empty callback bodies were rewritten with a stray space inside the braces (() => { } at apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts:265 and again at line 420) instead of the formatter's output, so the committed file no longer matches the repository's enforced formatting.

Impact: Formatting checks / pnpm run format will rewrite these lines, adding noise to the diff and to subsequent PRs.

Prettier rule from AGENTS.md and the exact deviations

AGENTS.md ("Coding style") states: "Formatting is enforced using Prettier. Run pnpm run format before committing." Prettier always emits () => {} for an empty arrow body, never () => { }. Both occurrences (apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts:265 and apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts:420) are purely incidental reformatting unrelated to the PR's purpose.

Suggested change
this.#doWork().finally(() => { });
this.#doWork().finally(() => {});
Open in Devin Review

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

Comment on lines +1763 to +1767
batch: attempt.taskRun.batch
? {
id: attempt.taskRun.batch.friendlyId,
}
: undefined,

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.

🟡 New conditional block is indented differently from what the project formatter produces

The newly added conditional value is written with hand-rolled indentation (batch: attempt.taskRun.batch ? { ... } : undefined at apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts:1763-1767) rather than the layout the required formatter produces, so the committed file is not formatter-clean.

Impact: The formatting check will flag the file and re-indent these lines, producing avoidable churn.

Expected Prettier output and other affected spots

AGENTS.md requires running pnpm run format before committing. Prettier indents an object literal inside a ternary branch so its members align under the opening brace:

  batch: attempt.taskRun.batch
    ? {
        id: attempt.taskRun.batch.friendlyId,
      }
    : undefined,

The same unformatted-indentation issue appears in the reflowed deployment ternary (apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts:622-627) and in the getResumePayload return type union (apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts:1913-1915), both of which are unrelated reformatting of untouched code.

Suggested change
batch: attempt.taskRun.batch
? {
id: attempt.taskRun.batch.friendlyId,
}
: undefined,
batch: attempt.taskRun.batch
? {
id: attempt.taskRun.batch.friendlyId,
}
: undefined,
Open in Devin Review

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

Comment on lines +277 to +284
retryConfig: task.retry ?? null,
queueConfig: task.queue ?? null,
machineConfig: task.machine ?? null,
triggerSource: task.triggerSource === "schedule" ? "SCHEDULED" : "STANDARD",
fileId: tasksToBackgroundFiles?.get(task.id) ?? null,
maxDurationInSeconds: task.maxDuration ? clampMaxDuration(task.maxDuration) : null,
queueId: queue.id,
payloadSchema: task.payloadSchema as any,
payloadSchema: (task.payloadSchema as any) ?? null,

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.

🟡 Pull request bundles an unrelated change alongside the stated feature

A separate, unrelated change to how missing task configuration is stored (retryConfig/queueConfig/payloadSchema defaults at apps/webapp/app/v3/services/createBackgroundWorker.server.ts:277-284) is included in a pull request whose stated purpose is optimizing batch context fetching, so the review scope covers two independent issues.

Impact: Reviewers must evaluate two unrelated changes at once, which the project's contribution rules disallow.

Contribution rule and note on the change itself

CONTRIBUTING.md states: "We only accept PRs that address a single issue. Please do not submit PRs containing multiple unrelated fixes or features. If you have multiple contributions, open a separate PR for each one."

Additionally, these fields are only ever supplied to prisma.backgroundWorkerTask.create() for a brand new row, where an omitted (undefined) value already results in a NULL column, so the ?? null additions do not change behaviour; for nullable Json columns Prisma also expects Prisma.DbNull/Prisma.JsonNull rather than a plain null.

Open in Devin Review

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

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