Skip to content

refactor(run-engine,webapp): route TaskRun writes through a new RunStore adapter#3981

Merged
d-cs merged 24 commits into
mainfrom
run-store-write-adapter
Jun 19, 2026
Merged

refactor(run-engine,webapp): route TaskRun writes through a new RunStore adapter#3981
d-cs merged 24 commits into
mainfrom
run-store-write-adapter

Conversation

@d-cs

@d-cs d-cs commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Introduces @internal/run-store, a typed layer that TaskRun writes go through, and routes the existing direct prisma.taskRun.* writes from the V2 run engine and the shared webapp services onto it. The deprecated V1 engine write paths are intentionally left as-is (they write directly to TaskRun). This is a behavior-preserving refactor: the same rows are written, with the same SQL, against the same table. It puts V2 and shared run persistence behind one interface, so future storage changes have a single seam instead of writes scattered across many call sites.

Design

RunStore exposes one method per run-lifecycle write (create, dequeue lock, attempt start/complete/fail, retry, cancel, expire, checkpoint suspend and resume, delay and reschedule, debounce, metadata, idempotency-key clear, tag and stream append). PostgresRunStore implements each as the exact write the call site performed before, against the existing TaskRun table. A NoopRunStore is provided for tests.

The V2 run engine reaches the store through a new field on its shared system resources; the webapp reaches it through a base-service member and a server singleton. Every method accepts an optional transaction client, so in-transaction writes are unchanged.

Behavior is covered by unit tests for each store method (real Postgres via testcontainers) and by the existing run-engine suite staying green.

d-cs added 19 commits June 17, 2026 13:35
Replaces the seven throwing stubs on PostgresRunStore with verbatim
relocations of the Prisma statements from runAttemptSystem: startAttempt,
completeAttemptSuccess, recordRetryOutcome, requeueRun,
recordBulkActionMembership, cancelRun, and failRunPermanently. Each method
splices the caller-supplied select/include into the Prisma call. Tests
use real Postgres containers and cover each method including edge cases
(append semantics, conditional fields in cancelRun).
…y-clear, and array-append methods

Replaces the seven throwing stubs in PostgresRunStore with verbatim-relocated
Prisma statements sourced from delayedRunSystem, debounceSystem, updateMetadata,
idempotencyKeys, resetIdempotencyKey, batchTriggerV3, and the realtime-stream
route handlers.

- rescheduleRun: writes delayUntil always; queueTimestamp when provided; nested
  DELAYED executionSnapshot when snapshot arg provided
- enqueueDelayedRun: sets status PENDING + queuedAt
- rewriteDebouncedRun: pass-through update with associatedWaitpoint include
- updateMetadata: optimistic-lock path (updateMany with version predicate) or
  direct path (update without predicate); both return { count }
- clearIdempotencyKey: three discriminated-union branches — byId clears both
  columns, byPredicate clears both, byFriendlyIds clears only idempotencyKey
- pushTags: push-append to runTags array; returns { updatedAt }
- pushRealtimeStream: push-append to realtimeStreams array; returns void
…bapp BaseService

Add RunStore field to SystemResources, instantiate PostgresRunStore in
RunEngine constructor (after prisma/readOnlyPrisma are set), and expose
it on the resources object passed to all systems. Create a webapp
singleton (runStore.server.ts) and thread it as a default parameter
into BaseService so subclasses can access it without changes.
@changeset-bot

changeset-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2367196

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 Jun 17, 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bb5b58d8-ce0c-49e3-ac31-dab013c4c456

📥 Commits

Reviewing files that changed from the base of the PR and between 76f3494 and 2367196.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • apps/webapp/package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/webapp/package.json
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (40)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 10)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (9, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (11, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (12, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (8, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (3, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (4, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (7, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (5, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (10, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 10)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (6, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (1, 12)
  • GitHub Check: internal / 🧪 Unit Tests: Internal (2, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 10)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (9, 10)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (10, 10)
  • GitHub Check: packages / 🧪 Unit Tests: Packages (1, 3)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 10)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 10)
  • GitHub Check: packages / 🧪 Unit Tests: Packages (3, 3)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 10)
  • GitHub Check: sdk-compat / Cloudflare Workers
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (5, 10)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (4, 10)
  • GitHub Check: sdk-compat / Deno Runtime
  • GitHub Check: sdk-compat / Node.js 20.20 (ubuntu-latest)
  • GitHub Check: sdk-compat / Node.js 22.12 (ubuntu-latest)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: sdk-compat / Bun Runtime
  • GitHub Check: packages / 🧪 Unit Tests: Packages (2, 3)
  • GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp
  • GitHub Check: 🛡️ E2E Auth Tests (full)
  • GitHub Check: audit
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Build and publish previews

Walkthrough

This PR introduces a new @internal/run-store internal workspace package that defines a RunStore interface and a PostgresRunStore implementation backed by Prisma. The interface covers the full TaskRun persistence surface: run creation, attempt lifecycle transitions, retry/cancel/fail/expire flows, worker locking, checkpoint suspend/resume, delayed/debounce scheduling, metadata versioned updates, idempotency key clearing (three targeting modes), tag pushing, and realtime stream registration. A NoopRunStore test double and a comprehensive 1,530-line integration test suite are included. The RunEngine and all engine subsystems (RunAttemptSystem, DequeueSystem, CheckpointSystem, TtlSystem, DelayedRunSystem, DebounceSystem, PendingVersionSystem) are updated to call runStore methods instead of direct prisma.taskRun.* calls. In the webapp, a singleton runStore is exported from runStore.server.ts, injected into BaseService as a protected property, and used by BatchTriggerV3Service, RescheduleTaskRunService, ResetIdempotencyKeyService, UpdateMetadataService, the idempotency key concern, and three API/realtime routes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the primary change: introducing and routing TaskRun writes through a new RunStore adapter across run-engine and webapp services.
Description check ✅ Passed The description is comprehensive and well-structured, covering summary, design, and testing approach, though the required PR template sections are not followed.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch run-store-write-adapter

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.

@d-cs d-cs self-assigned this Jun 17, 2026
coderabbitai[bot]

This comment was marked as resolved.

@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

@pkg-pr-new

pkg-pr-new Bot commented Jun 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trigger.dev/build

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

trigger.dev

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

@trigger.dev/core

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

@trigger.dev/python

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

@trigger.dev/react-hooks

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

@trigger.dev/redis-worker

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

@trigger.dev/rsc

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

@trigger.dev/schema-to-json

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

@trigger.dev/sdk

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

commit: 2367196

devin-ai-integration[bot]

This comment was marked as resolved.

d-cs and others added 2 commits June 18, 2026 11:47
The service statically imported the db.server-backed runStore singleton,
which dragged the Prisma client into otherwise-light test module graphs and
opened an eager connection to DATABASE_URL on import. The metadata service
test then threw an unhandled connection error whenever no database was
reachable at the configured address.

Make runStore a required constructor option, pass the singleton at the
production construction site, and inject a testcontainer-backed store in the
tests.
@d-cs d-cs merged commit 315baf2 into main Jun 19, 2026
53 checks passed
@d-cs d-cs deleted the run-store-write-adapter branch June 19, 2026 12:57
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