Skip to content

perf(run-engine,run-store): one execution snapshot per triggered run - #4419

Open
ericallam wants to merge 4 commits into
mainfrom
feature/tri-12709-collapse-run_created-and-queued-into-one-execution-snapshot
Open

perf(run-engine,run-store): one execution snapshot per triggered run#4419
ericallam wants to merge 4 commits into
mainfrom
feature/tri-12709-collapse-run_created-and-queued-into-one-execution-snapshot

Conversation

@ericallam

Copy link
Copy Markdown
Member

A non-delayed run used to get two execution snapshots the moment it was triggered: RUN_CREATED nested in the run-create transaction, immediately followed by QUEUED from its own BEGIN/INSERT/COMMIT. It now gets a single QUEUED snapshot written inside the create, and the trigger path only publishes to the queue. One fewer row per run on TaskRunExecutionSnapshot, and one fewer round trip on the trigger hot path.

EnqueueSystem gains a publishRun seam that enqueues without writing a snapshot. Every re-enqueue path (waitpoint resume, checkpoint restore, delayed enqueue, pending version, retry requeue) still calls enqueueRun and writes its own QUEUED, so only the first enqueue changes. The QUEUED snapshot still commits before the queue message, so a dequeue sees a dequeueable status exactly as before.

Two things for reviewers. Nesting the write skips createExecutionSnapshot, which is what emits executionSnapshotCreated and therefore the run timeline's [engine] QUEUED entry, so the trigger path now emits it directly, the same way the dequeue and attempt-start paths already do for their nested creates. And RUN_CREATED is still written when a dequeued run has no background worker yet, so the status and both statuses.ts helpers stay live and existing rows keep reading correctly.

Delayed runs are untouched: DELAYED then QUEUED are two genuinely different moments and stay two snapshots.

Rollback is a revert. Create-and-enqueue happen in one request in one process, so no in-flight run needs both code paths to agree during a rollout.

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a9d0749

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

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Run triggering now generates and persists an initial snapshot ID with QUEUED or DELAYED status. Non-delayed runs emit the snapshot-created event and use publishRun to enqueue without an additional snapshot write. Queue publication retains worker queue selection, priority timing, TTL handling, and attempt metadata. Tests cover non-delayed and delayed snapshot sequences, queue state, execution data, store routing, event timestamping, replica-tail behavior, and updated status assertions.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The body explains the change, but it misses the required template sections, issue link, testing steps, changelog, and screenshots. Add the template: Closes #issue, checklist, Testing steps, Changelog, and Screenshots, even if some sections are brief.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: reducing triggered runs to one execution snapshot.
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.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/tri-12709-collapse-run_created-and-queued-into-one-execution-snapshot

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.

coderabbitai[bot]

This comment was marked as resolved.

@ericallam
ericallam marked this pull request as ready for review July 29, 2026 14:01

@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: No Issues Found

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

Open in Devin Review

devin-ai-integration[bot]

This comment was marked as resolved.

@ericallam
ericallam force-pushed the feature/tri-12709-collapse-run_created-and-queued-into-one-execution-snapshot branch from a515874 to f2eed68 Compare July 29, 2026 16:11
@pkg-pr-new

pkg-pr-new Bot commented Jul 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trigger.dev/build

npm i https://pkg.pr.new/@trigger.dev/build@f2eed68

trigger.dev

npm i https://pkg.pr.new/trigger.dev@f2eed68

@trigger.dev/core

npm i https://pkg.pr.new/@trigger.dev/core@f2eed68

@trigger.dev/python

npm i https://pkg.pr.new/@trigger.dev/python@f2eed68

@trigger.dev/react-hooks

npm i https://pkg.pr.new/@trigger.dev/react-hooks@f2eed68

@trigger.dev/redis-worker

npm i https://pkg.pr.new/@trigger.dev/redis-worker@f2eed68

@trigger.dev/rsc

npm i https://pkg.pr.new/@trigger.dev/rsc@f2eed68

@trigger.dev/schema-to-json

npm i https://pkg.pr.new/@trigger.dev/schema-to-json@f2eed68

@trigger.dev/sdk

npm i https://pkg.pr.new/@trigger.dev/sdk@f2eed68

commit: f2eed68

A non-delayed run was getting RUN_CREATED nested in the run-create
transaction followed by a separate QUEUED write. It now gets a single
QUEUED snapshot inside the create, with the trigger path only publishing
to the queue.
…d trigger write

The store-routing counters now also count createRun, since the trigger
path's QUEUED snapshot is written nested in the run create. The
replica-lag test starts the run attempt so it still has a middle
snapshot to exercise rather than degenerating to an empty comparison.
… primary

startRunAttempt resolves the background worker task through readOnlyPrisma,
and this test configures a deliberately empty schema-only replica, so using it
to add a snapshot failed on the replica read instead of exercising the lag
scenario. Write the snapshot with the file's own primary-side helper.
The run's createdAt is caller-supplied and the scheduler sets it to the exact
schedule time, so using it for the emitted event backdated the queued entry on
every scheduled run's timeline. Use the write moment, as the other nested-create
paths do.
@ericallam
ericallam force-pushed the feature/tri-12709-collapse-run_created-and-queued-into-one-execution-snapshot branch from f2eed68 to a9d0749 Compare July 29, 2026 16:26
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