Skip to content

perf(webapp): trim BackgroundWorker.metadata to the schedule slice on create#3525

Merged
ericallam merged 1 commit intomainfrom
fix/strip-background-worker-metadata
May 5, 2026
Merged

perf(webapp): trim BackgroundWorker.metadata to the schedule slice on create#3525
ericallam merged 1 commit intomainfrom
fix/strip-background-worker-metadata

Conversation

@ericallam
Copy link
Copy Markdown
Member

@ericallam ericallam commented May 5, 2026

Large deploys (projects with many tasks or source files) blocked the webapp event loop for several seconds inside Prisma's client-side serializer on BackgroundWorker.create, tail-latencying every other in-flight request on the same Node process. The metadata JSON column was being written with the full deploy manifest — every task's config, every queue and prompt, and the full source of every file — all of which already live on dedicated columns or in dedicated tables.

Fix: project the manifest to { packageVersion, contentHash, tasks: [{ id, filePath, schedule }] } on insert. The only post-write read site is changeCurrentDeployment, which feeds tasks[].schedule into syncDeclarativeSchedules at deploy promotion. The retained top-level keys and per-task filePath are kept solely so BackgroundWorkerMetadata.safeParse still succeeds on read.

Test plan

  • Deploy a project with declarative schedules; verify schedules are created on first deploy
  • Modify / remove schedules across subsequent deploys; verify sync
  • Roll back to a previous deploy; verify changeCurrentDeployment re-syncs schedules
  • Inspect BackgroundWorker.metadata on a fresh deploy — should be a small object, not the full manifest

… create

The full worker manifest stored in BackgroundWorker.metadata duplicates
source files and per-task config that already live in dedicated columns
and tables. On large deploys this inflated Prisma's client-side serialize
step to several seconds, blocking the API event loop and tail-latencying
unrelated concurrent requests.

Only the slice read after storage — schedule-bearing tasks consumed by
syncDeclarativeSchedules at deploy promotion — is persisted now.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 5, 2026

⚠️ No Changeset found

Latest commit: 1c5dacd

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 5, 2026

Walkthrough

The pull request introduces a utility function stripBackgroundWorkerMetadataForStorage that reduces BackgroundWorker.metadata to only essential fields for storage (packageVersion, contentHash, and scheduled tasks with id, filePath, and schedule). Three service files—createBackgroundWorker.server.ts, createDeploymentBackgroundWorkerV3.server.ts, and createDeploymentBackgroundWorkerV4.server.ts—are updated to use this function instead of persisting full metadata. A documentation entry describes this as an improvement to reduce event-loop blocking in Prisma's serializer during worker creation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provides detailed context about the performance issue and implementation strategy, but does not follow the required template structure with all specified sections. Add the missing template sections: close issue reference, checklist items (contributed guide, PR title convention, testing confirmation), Testing section with test steps, Changelog section, and Screenshots section as applicable.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: trimming BackgroundWorker.metadata to only the schedule slice during worker creation, which directly addresses the performance optimization.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/strip-background-worker-metadata

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.

@ericallam ericallam marked this pull request as ready for review May 5, 2026 12:24
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: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@ericallam ericallam merged commit 31999af into main May 5, 2026
44 checks passed
@ericallam ericallam deleted the fix/strip-background-worker-metadata branch May 5, 2026 13:52
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.

2 participants