Skip to content

feat(webapp,run-engine): Redis waitpoint coordinator arm behind a per-org mint flag - #4793

Draft
d-cs wants to merge 9 commits into
feat/waitpoint-envelope-resolver-tri-13441from
feat/waitpoint-mint-flag-wiring-tri-13442
Draft

feat(webapp,run-engine): Redis waitpoint coordinator arm behind a per-org mint flag#4793
d-cs wants to merge 9 commits into
feat/waitpoint-envelope-resolver-tri-13441from
feat/waitpoint-mint-flag-wiring-tri-13442

Conversation

@d-cs

@d-cs d-cs commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds the Redis arm of the waitpoint coordinator, plus the per-organization flag that decides which arm mints a new waitpoint. Nothing routes to the new arm yet: the flag defaults to unset, WAITPOINT_SYSTEM_DEFAULT defaults to legacy, and every call site still pins the legacy value. Behaviour is unchanged.

Stacked on #4779. Draft while the remaining wiring lands, and open early so CI runs the container suites.

Design

The coordinator seam already existed, with one Postgres implementation behind it. This adds a second implementation and the machinery to choose between them at mint time. Every operation after a mint routes by the waitpoint id's own shape, never by re-reading the flag, so a flag flip can only change where the next waitpoint is born. That is also why the flag needs no grace window: there is no interval in which one waitpoint could end up split across the two systems.

Three rules in the new arm carry the correctness weight.

An edge that is in neither the run's pending set nor its delivered set reports PENDING, and increments a counter. The store keeps every edge in exactly one of the two, so being in neither means the run shard lost state. Reading that as "not pending, therefore complete" would resume a run whose waitpoint never completed. This is deliberately not a rule about completion envelopes: a waitpoint can be COMPLETED while carrying none, and treating that as unresolved would block a healthy run forever.

A lockless batch absorb refuses to write item edges unless the parent's BATCH waitpoint is present and still pending. Absorbing items without the run lock is only safe while that waitpoint holds the pending set open; otherwise a concurrent completion can observe an empty pending set mid-absorb and resume the parent early.

The MANUAL projection row is written to Postgres after the store commit, and no coordination path reads it back. A failed projection write is logged and counted rather than thrown, because the waitpoint already exists and is already coordinating.

The BATCH waitpoint create also moves onto the seam. Its P2002 catch moves with it to the Postgres arm, where it belongs: that catch is a unique-index contract, and against a store that reports duplicates through SET NX it would read a genuine store error as a duplicate batch. The block step keeps its own P2002 catch, because the previous shape wrapped both the create and the block in one try, and narrowing that here would be a behaviour change smuggled into an extraction.

Verification

Run locally before the machine ran out of container capacity: the new store-arm suite (10 cases), the shape mapper (6), the mint-kind resolver (6), and the existing waitpoint suites that pin the batch contract (46 across waitpointPublicRouter, batchTriggerAndWait, batchTwoPhase, waitpointSystem) with no test-file diffs. Typecheck clean for both packages.

Not yet re-run locally: a mutation check on the two correctness rules above. Leaving that to CI here and repeating it locally before this leaves draft.

…ncy (#4781)

Gives read-through and idempotency their gen-2 shard arms, so an id that
names its own shard is read there and nowhere else.

#4764 has landed, so this now targets `main` directly and no longer
depends on an unmerged branch. It builds on what that PR supplied:
`resolveShard`, `runOpsShardHandles` and the keyed router.

TRI-13431

## What changes

**Read-through routes by `resolveShard`, not by the binary residency
classifier.** A gen-2 id reads its own shard's replica once and probes
no other store. A gen-1 v1 id still reads new only.

**Callers now declare `idKind`.** A cuid gives no way to tell a run id
from a waitpoint id, and the two must route differently:

- a legacy-classified **run** id reads the legacy replica only — there
is no cuid run migration, so the new-store probe cannot find it;
- a cuid **waitpoint** keeps the new-first pair probe, which is
load-bearing because a cuid waitpoint can be co-located with its run on
the new store.

There is no default, because a default would pick one of those arms
silently. The field `runId` is renamed to `id`, since it carried both
kinds already.

**`ReadThroughResult` carries `found`.** `source` is an open-ended union
once shards exist, so a consumer testing found-ness by listing the hit
sources reads a gen-2 hit as a miss. One consumer did exactly that.
Discriminating on `found` makes that class of bug a compile error rather
than something a reviewer has to spot.

**Idempotency resolves its client through one shard-keyed map.** Both
call sites go through `clientForShardKey`, so they cannot disagree about
which store owns an id. An absent key takes an explicit logged branch to
the fallback, not a silent legacy default. The `classify` seam is
retyped to return a `ShardKey`: `Residency` (`"NEW"`) and the reserved
shard keys (`"new"`) differ only by case, and `ShardKey` collapses to
`string`, so the compiler would not have caught feeding one into the
other.

The dead `isMigrated` branch is deleted. Nothing implemented it, and the
one production comment recorded that omitting it was deliberate.

**`PostgresRunStore._residency` widens to `ShardKey`.** Still unused;
the store stays unaware of its siblings.

## Two behaviour fixes found while doing the above

**An unconfigured shard key logs and returns not-found instead of
throwing.** The waitpoint route takes the id from a URL parameter, and
any base32hex core plus `[a-z0-9]` plus `"2"` parses as gen-2. The route
turns a throw into a 500, so throwing here would let any authenticated
client generate 500s and error logs by guessing shard chars, of which
there are 36. An error-logged not-found is neither silent nor a
misroute. Throwing stays correct on the router path, where ids are
minted rather than received.

**The two cross-seam batch hydration sites were gen-2 blind.**
`hydrateRunsAcrossSeam` and `ApiBatchResultsPresenter` classified with
the binary `ownerEngine`, so a gen-2 run id joined the gen-1 `new`
group, missed there, and — classifying dedicated-family — never reached
the legacy probe either. The id was dropped from a bulk-action page and
from batch results with no error. Both now partition ids by shard key
and read each configured shard once.

Also: a gen-2 waitpoint that missed its shard replica fell back to the
gen-1 new writer, a different database, silently disabling
read-your-writes for the freshly minted token that fallback exists to
serve. It now falls back to its own shard's writer.

## Merge safety

Inert while `RUN_OPS_SHARDS` is unset: the shard maps are empty, so
every gen-2 arm is unreachable, and gen-2 minting is not live yet.

The one live change is the gen-1 run arm, and it removes work rather
than adding it. `RoutingRunStore.findRun` never forwards the caller's
client object — it routes by id and reads only the client's presence and
replica brand — so `readRunForEvent`'s "new" closure already resolved a
legacy-classified run id to the legacy store. The arm removes a
duplicated read of the legacy replica. A test pins this, because a
future caller passing a raw client and a run id would lose the
pre-cutover 27-char case, which is new-resident but classifies legacy.

## Testing

14 tests added, testcontainers throughout, no mocks. 22 affected test
files pass; typecheck, lint, format and knip are clean.

Both arms were verified by neutralising them and confirming the new
tests fail. The batch-results test needed rewriting after that check:
the first version passed with the fix neutralised, because it used one
container as both the gen-1 new client and the shard replica, so it was
not testing what it claimed.

Note for review: run testcontainer suites in small batches. Sixteen at
once starves Docker and everything times out at 60 seconds.

The run-ops legacy-guard baseline is refreshed in its own commit. The
baseline is keyed by line number, so partitioning the batch-results read
shifted four pre-existing entries and added one. Baselined violations in
that file go from four to five, all reads; the new one is the shard read
beside two gen-1 reads already there.

No changeset and no `.server-changes` entry: a user notices nothing
while the flag is unset.
@changeset-bot

changeset-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1e28906

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 Aug 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5b0b433f-4ba5-49fd-934d-0728d1f49a7d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The change adds waitpoint system configuration and a validated organization feature flag. It resolves mint kinds with global defaults, organization overrides, bounded caching, replica fallback, and fail-safe legacy behavior. It extends coordinator contracts for batch waitpoints and mint kinds. It adds Redis-backed waitpoint coordination, status handling, completion delivery, idempotency, batch guards, and database projections. Existing batch creation now uses the coordinator while preserving duplicate-key behavior. It also adds shard-aware read, hydration, idempotency, and unroutable-ID handling.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 34.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 37 files. (1 skipped:… 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 clearly identifies the Redis waitpoint coordinator arm and its per-organization mint flag, which are the primary changes.
Description check ✅ Passed The description is detailed, on-topic, and covers the design, behavior, and verification results. It does not use every template section, but it provides equivalent testing and change details, so the …
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.
Full details: Description check

Explanation

The description is detailed, on-topic, and covers the design, behavior, and verification results. It does not use every template section, but it provides equivalent testing and change details, so the description is mostly complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 34.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 37 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/waitpoint-mint-flag-wiring-tri-13442

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.

@d-cs d-cs closed this Aug 26, 2026
@d-cs d-cs reopened this Aug 26, 2026
d-cs added 4 commits August 26, 2026 17:06
The org's waitpointSystem flag decides where a NEW waitpoint is minted;
WAITPOINT_SYSTEM_DEFAULT is the fallback and defaults to legacy. A flag-read
failure mints legacy, matching computeRunIdMintKind's fail-safe.

No flip-grace machinery: every operation after a mint routes by the waitpoint's
id shape and never re-reads the flag, so a flip can never split one waitpoint
across the two systems.

Nothing consumes this yet.
…nator seam

blockRunWithCreatedBatch built its waitpoint with runStore.createWaitpoint
directly, so it had no arm to route to. It now goes through the coordinator.

The P2002 catch moves to the legacy arm, where it belongs: it is the
duplicate-batch contract for a unique index, and it is dead against a store that
reports a duplicate through NX instead. Leaving it wrapped around a store create
would read a genuine store error as a duplicate batch.

The block step keeps its own P2002 catch. The previous shape wrapped the create
and the block in one try, so a P2002 from either returned null; narrowing that
here would be a behaviour change smuggled into an extraction.

Seam also gains the mint kind on the create params and batchWaitpointId on the
lockless params. Both are pinned to their legacy values at every call site, so
behaviour is unchanged.
The coordinator seam returns Prisma Waitpoint, and callers read its columns
directly, but a store-resident waitpoint has no row. This maps the store's
record, status and completion onto that shape.

Every column is listed explicitly rather than spread. A missed non-null column
would surface as undefined in a consumer far from here that had no reason to
guard, and the type checker catches an omission here instead.

An absent idempotency key throws rather than synthesizing one: the column is
non-null and half of the (environmentId, idempotencyKey) unique index, so an
invented value could collide with a real one.
Implements the coordinator seam against the Redis store, so waitpoint state
can live there instead of Postgres. Unreachable until a mint routes to it.

Three rules carry the correctness weight:

An edge that is in neither the run's pending nor its delivered set reports
PENDING and increments a counter. The store keeps every edge in exactly one
of those sets, so being in neither means the run shard lost state. Reading
that as "not pending, therefore complete" would resume a run whose waitpoint
never completed. Note this is deliberately not a rule about completion
envelopes: a waitpoint can be COMPLETED carrying none, and treating that as
unresolved would block a healthy run forever.

A lockless absorb refuses to write item edges unless the parent's BATCH
waitpoint is present and still pending. Absorbing items without the run lock
is only safe while that waitpoint holds the pending set open, otherwise a
concurrent completion can see an empty set mid-absorb and resume the parent
early.

The MANUAL projection row is written after the store commit and never read
back for coordination. A failed projection write is logged and counted rather
than thrown: the waitpoint already exists and is already coordinating, so
failing the create would report failure for work that succeeded.

Also adds a single-key record read to the store client. The seam returns the
Postgres row shape and only the immutable record carries the columns that
shape needs.
@d-cs
d-cs force-pushed the feat/waitpoint-mint-flag-wiring-tri-13442 branch from fd52adc to c4e21e6 Compare August 26, 2026 16:07
@d-cs d-cs self-assigned this Aug 26, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 6


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f5ef88f7-7af6-48fe-91ac-762eef3cff06

📥 Commits

Reviewing files that changed from the base of the PR and between 7f9da73 and c4e21e6.

📒 Files selected for processing (14)
  • apps/webapp/app/env.server.ts
  • apps/webapp/app/v3/featureFlags.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.ts
  • apps/webapp/vitest.config.ts
  • internal-packages/run-engine/src/engine/index.ts
  • internal-packages/run-engine/src/engine/systems/waitpointSystem.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/legacyPostgresCoordinator.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.test.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeCoordinator.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/types.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.test.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📜 Review details
🧰 Additional context used
📓 Path-based instructions (15)
New code must target Run Engine V2 through the singleton in `app/v3/runEngine.server.ts`; do not reintroduce V1 execution paths. V1 branches may only reject or finalize gracefully with a clean 4xx.

📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md)

Files:

  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • apps/webapp/app/v3/featureFlags.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.ts
Never use `request.signal` to detect client disconnects. Use `getRequestAbortSignal()` from `app/services/httpAsyncStorage.server.ts`, which is wired to Express response close events.

📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md)

Files:

  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • apps/webapp/app/v3/featureFlags.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.ts
  • apps/webapp/app/env.server.ts
We use vitest exclusively. **Never mock anything** - use testcontainers instead.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.test.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.test.ts
Test files must not import `app/env.server.ts`; pass configuration as options instead.

📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md)

Files:

  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
For dashboard changes, visually verify the running Remix app with Chrome DevTools MCP, using snapshots, screenshots, interaction, and console-message checks as appropriate.

📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md)

Files:

  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • apps/webapp/app/v3/featureFlags.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.ts
  • apps/webapp/app/env.server.ts
**Prefer static imports over dynamic imports.** Only use dynamic `import()` when:

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeCoordinator.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • apps/webapp/vitest.config.ts
  • internal-packages/run-engine/src/engine/systems/waitpointSystem.ts
  • apps/webapp/app/v3/featureFlags.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/legacyPostgresCoordinator.ts
  • internal-packages/run-engine/src/engine/index.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.test.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.test.ts
  • apps/webapp/app/env.server.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/types.ts
Add crumbs as you write code — not just when debugging. Mark lines with

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeCoordinator.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • apps/webapp/vitest.config.ts
  • internal-packages/run-engine/src/engine/systems/waitpointSystem.ts
  • apps/webapp/app/v3/featureFlags.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/legacyPostgresCoordinator.ts
  • internal-packages/run-engine/src/engine/index.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.test.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.test.ts
  • apps/webapp/app/env.server.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/types.ts
Integrate OpenTelemetry tracer and meter instrumentation in RunEngine systems for observability

📄 CodeRabbit inference engine (internal-packages/run-engine/CLAUDE.md)

Files:

  • internal-packages/run-engine/src/engine/systems/waitpointSystem.ts
Use zod for validation in packages/core and apps/webapp

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • apps/webapp/vitest.config.ts
  • apps/webapp/app/v3/featureFlags.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.ts
  • apps/webapp/app/env.server.ts
Do not import `env.server.ts` directly or indirectly into test files; instead pass environment-dependent values through options/parameters to make code testable

📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)

Files:

  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
Access environment variables through the `env` export of `env.server.ts` instead of directly accessing `process.env`

📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)

Files:

  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • apps/webapp/vitest.config.ts
  • apps/webapp/app/v3/featureFlags.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.ts
  • apps/webapp/app/env.server.ts
Use vitest for all tests in the Trigger.dev repository

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.test.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.test.ts
Use function declarations instead of default exports

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeCoordinator.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • apps/webapp/vitest.config.ts
  • internal-packages/run-engine/src/engine/systems/waitpointSystem.ts
  • apps/webapp/app/v3/featureFlags.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/legacyPostgresCoordinator.ts
  • internal-packages/run-engine/src/engine/index.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.test.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.test.ts
  • apps/webapp/app/env.server.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/types.ts
Use types over interfaces for TypeScript

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeCoordinator.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • apps/webapp/vitest.config.ts
  • internal-packages/run-engine/src/engine/systems/waitpointSystem.ts
  • apps/webapp/app/v3/featureFlags.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/legacyPostgresCoordinator.ts
  • internal-packages/run-engine/src/engine/index.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.test.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.test.ts
  • apps/webapp/app/env.server.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/types.ts
When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs

📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)

Files:

  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeCoordinator.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts
  • apps/webapp/vitest.config.ts
  • internal-packages/run-engine/src/engine/systems/waitpointSystem.ts
  • apps/webapp/app/v3/featureFlags.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/legacyPostgresCoordinator.ts
  • internal-packages/run-engine/src/engine/index.ts
  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/waitpointShape.test.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.test.ts
  • apps/webapp/app/env.server.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.ts
  • internal-packages/run-engine/src/engine/waitpointCoordinator/types.ts
🧠 Learnings (1)
📚 Learning: 2026-05-18T14:40:02.173Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3658
File: packages/core/src/v3/realtimeStreams/manager.test.ts:1-147
Timestamp: 2026-05-18T14:40:02.173Z
Learning: In the triggerdotdev/trigger.dev repo, the policy “Never mock anything — use testcontainers instead” should only be enforced for integration tests that interact with real external services (e.g., Redis, Postgres) via actual infrastructure. For unit tests that exercise pure in-memory logic (e.g., cache semantics) it is OK to stub collaborators such as `ApiClient` using Vitest (`vi.fn()`) to assert call counts or control behavior. Do not flag `vi.fn()`-based `ApiClient` stubs in unit tests as violations of the testcontainers policy.

Applied to files:

  • apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.test.ts

Comment thread apps/webapp/app/env.server.ts
Comment thread apps/webapp/app/v3/waitpointMigration/waitpointMintKind.server.ts
Comment on lines +170 to +185
async #assertBatchWaitpointPending(params: RegisterBlocksLocklessParams): Promise<void> {
if (!params.batchWaitpointId) {
return;
}

const state = await this.store.readBlockState(params.runId);
if (state.pendingIds.includes(params.batchWaitpointId)) {
return;
}

this.batchGuardViolations.add(1);
throw new Error(
`Lockless absorb for run ${params.runId} requires the parent BATCH waitpoint ` +
`${params.batchWaitpointId} to be present and pending on the run shard`
);
}

@coderabbitai coderabbitai Bot Aug 26, 2026

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.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Make the parent-pending guard atomic with item-edge absorption.

Lines 175-177 only perform a preflight read. A concurrent completion can remove the parent BATCH entry after this read and before registerBlocks() stores item edges. The parent run can then observe no pending waitpoints and resume before the item edges exist.

Move the parent-state assertion into the run-shard operation that absorbs the item edges.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, and I am leaving this thread open for a human call rather than closing it.

You are right that the check does not close the window. It reads the run shard, then the absorb writes in a separate operation, so a completion landing between the two is detected on a later call rather than prevented. It is a detector, not a barrier. 8c4c6af states that in the code instead of letting the previous comment imply atomicity, and makes a missing parent id throw rather than skip, but neither of those makes it atomic.

Closing it properly means moving the pending-set assertion inside the absorb script so the check and the edge write share one atomic action. That edits the Lua the earlier coordinator work owns, which is why I am not doing it unilaterally here.

Worth noting the plan this work follows anticipated the gap: it assigns the in-code assertion to this stage and the race test to a later one, on the grounds that this variant is unmodeled in both verification campaigns. So the current state is what was specified. Whether specified is good enough is the question I am putting to a reviewer.

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.

@d-cs, agreed. The current code detects the unsafe state but does not prevent the race.

The finding remains open because #assertBatchWaitpointPending() and store.registerBlocks() are separate run-shard operations. A complete fix must perform the parent pending-set check and item-edge absorption in one atomic Lua operation.

The stated staged plan explains the current implementation. It does not remove the correctness risk. A human reviewer can decide whether to accept that deferred work for this PR.

(ᵔᴥᵔ)


✏️ Learnings added
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 4793
File: internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.ts:176-197
Timestamp: 2026-08-26T16:34:03.944Z
Learning: In `internal-packages/run-engine/src/engine/waitpointCoordinator/storeArm.ts`, `StoreWaitpointCoordinatorArm.#assertBatchWaitpointPending()` is intentionally a non-atomic preflight detector. It reads run-shard state separately from `store.registerBlocks()`, so it cannot prevent a concurrent completion between the check and item-edge absorption. To close this race, the pending-set assertion and absorption must execute in the same run-shard Lua operation. The migration plan assigns the in-code detector to the current stage and defers the race test to a later stage.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

@pkg-pr-new

pkg-pr-new Bot commented Aug 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trigger.dev/build

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

trigger.dev

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

@trigger.dev/core

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

@trigger.dev/python

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

@trigger.dev/react-hooks

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

@trigger.dev/redis-worker

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

@trigger.dev/rsc

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

@trigger.dev/schema-to-json

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

@trigger.dev/sdk

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

commit: c4e21e6

…the batch guard

Four fixes from review.

A completed MANUAL waitpoint left its Postgres projection row PENDING. The
token API and the dashboard read status, output and completedAt from that row,
so a finished token reported as still waiting with no output. The completion
now writes through to the projection, best effort like the create-time write.

A lockless absorb that arrives with no parent BATCH waitpoint id now throws
instead of returning early. Skipping silently meant an unwired caller would
disable the pending-set guard rather than fail, which is the exact failure the
guard exists to catch.

mintAssociatedWaitpointData gains anchorRunId on the coordinator contract. The
store arm derives a RUN waitpoint id from the run's own id body, so without the
anchor on the shared type the two arms disagreed about the call shape.

The mint-kind resolver splits into a pure module and an env-bound wrapper, so
its test no longer loads env.server through the import chain. Test import time
drops from 2.7s to 7ms, which is the chain being gone rather than a speedup.

Also states plainly in the code that the batch guard is a preflight detector
and not a barrier: it reads the run shard, then the absorb writes separately,
so a completion landing between the two is detected next call, not prevented.
Closing that window means moving the assertion inside the absorb script.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (2)
apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts (1)

22-40: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add required crumbs for the new shard-routing paths.

Add // @Crumbs markers or an approved `#region `@crumbs block for the new routing decisions. If no approved namespace applies, ask before adding one.

  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts#L22-L40: add crumbs for configured-shard selection and fallback selection.
  • apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts#L36-L44: add crumbs for the local shard-to-client mapping.
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts#L15-L38: add crumbs for the new shard-routing test setup.

As per coding guidelines, “Add crumbs as you write code” and do not invent a namespace.

Source: Coding guidelines

apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts (1)

16-17: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Mint the gen-2 fixture ID with generateRunOpsIdV2.

The hand-built string encodes the gen-2 layout as a comment. If the ID format changes, resolveShard reclassifies this constant as new or legacy, and the shard tests keep passing while exercising the gen-1 path instead. The sibling test apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts already uses the generator.

♻️ Proposed change
-// 26-char gen-2 body: shard char at index 24, version "2" at index 25.
-const SHARD_A_RUN_ID = "run_" + "c".repeat(24) + "a2";
+const SHARD_A_RUN_ID = generateRunOpsIdV2("a");

Add the import:

import { generateRunOpsIdV2 } from "`@trigger.dev/core/v3/isomorphic`";

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1e327c8f-55cc-49f0-bbba-70d9938eef5b

📥 Commits

Reviewing files that changed from the base of the PR and between c4e21e6 and 9c4f23d.

📒 Files selected for processing (24)
  • apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts
  • apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts
  • apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts
  • apps/webapp/app/runEngine/concerns/resolveWaitpointThroughReadThrough.server.ts
  • apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
  • apps/webapp/app/services/routeBuilders/unroutableId.server.ts
  • apps/webapp/app/v3/runEngineHandlersShared.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.ts
  • apps/webapp/app/v3/runOpsMigration/track1-baseline.json
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts
  • apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts
  • apps/webapp/test/readRunForEvent.replicaLag.test.ts
  • apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts
  • apps/webapp/test/unroutableIdStatus.test.ts
  • internal-packages/run-store/src/PostgresRunStore.ts
  • internal-packages/run-store/src/runOpsStore.shardMap.test.ts
  • internal-packages/run-store/src/runOpsStore.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

📜 Review details
🧰 Additional context used
📓 Path-based instructions (15)
Use Remix flat-file route conventions with dot-separated segments; for example, `api.v1.tasks.$taskId.trigger.ts` maps to `/api/v1/tasks/:taskId/trigger`.

📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md)

Files:

  • apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts
New code must target Run Engine V2 through the singleton in `app/v3/runEngine.server.ts`; do not reintroduce V1 execution paths. V1 branches may only reject or finalize gracefully with a clean 4xx.

📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md)

Files:

  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/app/v3/runEngineHandlersShared.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
Never use `request.signal` to detect client disconnects. Use `getRequestAbortSignal()` from `app/services/httpAsyncStorage.server.ts`, which is wired to Express response close events.

📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md)

Files:

  • apps/webapp/app/services/routeBuilders/unroutableId.server.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/app/v3/runEngineHandlersShared.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.ts
  • apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
  • apps/webapp/app/runEngine/concerns/resolveWaitpointThroughReadThrough.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts
  • apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
  • apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts
We use vitest exclusively. **Never mock anything** - use testcontainers instead.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • apps/webapp/test/unroutableIdStatus.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/test/readRunForEvent.replicaLag.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • internal-packages/run-store/src/runOpsStore.shardMap.test.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
Test files must not import `app/env.server.ts`; pass configuration as options instead.

📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md)

Files:

  • apps/webapp/test/unroutableIdStatus.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/test/readRunForEvent.replicaLag.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
For dashboard changes, visually verify the running Remix app with Chrome DevTools MCP, using snapshots, screenshots, interaction, and console-message checks as appropriate.

📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md)

Files:

  • apps/webapp/app/services/routeBuilders/unroutableId.server.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/app/v3/runEngineHandlersShared.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.ts
  • apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
  • apps/webapp/app/runEngine/concerns/resolveWaitpointThroughReadThrough.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts
  • apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
  • apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts
**Prefer static imports over dynamic imports.** Only use dynamic `import()` when:

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • apps/webapp/app/services/routeBuilders/unroutableId.server.ts
  • apps/webapp/test/unroutableIdStatus.test.ts
  • internal-packages/run-store/src/PostgresRunStore.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/test/readRunForEvent.replicaLag.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/app/v3/runEngineHandlersShared.server.ts
  • apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.ts
  • internal-packages/run-store/src/runOpsStore.ts
  • apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts
  • internal-packages/run-store/src/runOpsStore.shardMap.test.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts
  • apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
  • apps/webapp/app/runEngine/concerns/resolveWaitpointThroughReadThrough.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts
  • apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
  • apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts
Add crumbs as you write code — not just when debugging. Mark lines with

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • apps/webapp/app/services/routeBuilders/unroutableId.server.ts
  • apps/webapp/test/unroutableIdStatus.test.ts
  • internal-packages/run-store/src/PostgresRunStore.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/test/readRunForEvent.replicaLag.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/app/v3/runEngineHandlersShared.server.ts
  • apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.ts
  • internal-packages/run-store/src/runOpsStore.ts
  • apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts
  • internal-packages/run-store/src/runOpsStore.shardMap.test.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts
  • apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
  • apps/webapp/app/runEngine/concerns/resolveWaitpointThroughReadThrough.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts
  • apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.ts
  • apps/webapp/app/v3/runOpsMigration/track1-baseline.json
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
  • apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts
Use zod for validation in packages/core and apps/webapp

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • apps/webapp/app/services/routeBuilders/unroutableId.server.ts
  • apps/webapp/test/unroutableIdStatus.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/test/readRunForEvent.replicaLag.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/app/v3/runEngineHandlersShared.server.ts
  • apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.ts
  • apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts
  • apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
  • apps/webapp/app/runEngine/concerns/resolveWaitpointThroughReadThrough.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts
  • apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
  • apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts
Do not import `env.server.ts` directly or indirectly into test files; instead pass environment-dependent values through options/parameters to make code testable

📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)

Files:

  • apps/webapp/test/unroutableIdStatus.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/test/readRunForEvent.replicaLag.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
Access environment variables through the `env` export of `env.server.ts` instead of directly accessing `process.env`

📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)

Files:

  • apps/webapp/app/services/routeBuilders/unroutableId.server.ts
  • apps/webapp/test/unroutableIdStatus.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/test/readRunForEvent.replicaLag.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/app/v3/runEngineHandlersShared.server.ts
  • apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.ts
  • apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts
  • apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
  • apps/webapp/app/runEngine/concerns/resolveWaitpointThroughReadThrough.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts
  • apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
  • apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts
Use vitest for all tests in the Trigger.dev repository

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • apps/webapp/test/unroutableIdStatus.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/test/readRunForEvent.replicaLag.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • internal-packages/run-store/src/runOpsStore.shardMap.test.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
Use function declarations instead of default exports

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • apps/webapp/app/services/routeBuilders/unroutableId.server.ts
  • apps/webapp/test/unroutableIdStatus.test.ts
  • internal-packages/run-store/src/PostgresRunStore.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/test/readRunForEvent.replicaLag.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/app/v3/runEngineHandlersShared.server.ts
  • apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.ts
  • internal-packages/run-store/src/runOpsStore.ts
  • apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts
  • internal-packages/run-store/src/runOpsStore.shardMap.test.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts
  • apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
  • apps/webapp/app/runEngine/concerns/resolveWaitpointThroughReadThrough.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts
  • apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
  • apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts
Use types over interfaces for TypeScript

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • apps/webapp/app/services/routeBuilders/unroutableId.server.ts
  • apps/webapp/test/unroutableIdStatus.test.ts
  • internal-packages/run-store/src/PostgresRunStore.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/test/readRunForEvent.replicaLag.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/app/v3/runEngineHandlersShared.server.ts
  • apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.ts
  • internal-packages/run-store/src/runOpsStore.ts
  • apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts
  • internal-packages/run-store/src/runOpsStore.shardMap.test.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts
  • apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
  • apps/webapp/app/runEngine/concerns/resolveWaitpointThroughReadThrough.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts
  • apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
  • apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts
When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs

📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)

Files:

  • apps/webapp/app/services/routeBuilders/unroutableId.server.ts
  • apps/webapp/test/unroutableIdStatus.test.ts
  • internal-packages/run-store/src/PostgresRunStore.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.test.ts
  • apps/webapp/test/readRunForEvent.replicaLag.test.ts
  • apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts
  • apps/webapp/app/v3/runEngineHandlersShared.server.ts
  • apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts
  • apps/webapp/app/v3/runOpsMigration/shardHandles.server.ts
  • internal-packages/run-store/src/runOpsStore.ts
  • apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts
  • internal-packages/run-store/src/runOpsStore.shardMap.test.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.test.ts
  • apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts
  • apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
  • apps/webapp/app/runEngine/concerns/resolveWaitpointThroughReadThrough.server.ts
  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts
  • apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.ts
  • apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts
  • apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts
🧠 Learnings (2)
📚 Learning: 2026-08-21T14:26:14.909Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 4752
File: internal-packages/run-store/src/runOpsStore.shardMap.test.ts:5-11
Timestamp: 2026-08-21T14:26:14.909Z
Learning: For these RoutingRunStore unit tests, use an instrumented fakeStore() with a shared ordered call log when verifying routing algebra such as sequential probe order and merge precedence. Use testcontainer-backed tests separately for database behavior, including mixed residency and replica-lag scenarios.

Applied to files:

  • internal-packages/run-store/src/runOpsStore.shardMap.test.ts
📚 Learning: 2026-06-04T18:16:35.386Z
Learnt from: nicktrn
Repo: triggerdotdev/trigger.dev PR: 3836
File: apps/supervisor/src/backpressure/backpressureMonitor.ts:3-5
Timestamp: 2026-06-04T18:16:35.386Z
Learning: When reviewing TypeScript in this repo, apply the rule “prefer type aliases over interfaces” only to data/object shapes and union/intersection type modeling. If an interface is being used as a behavioral contract for collaborators to implement (e.g., method-shape interfaces that define required behavior, such as `BackpressureLogger` / `BackpressureSignalSource` in `apps/supervisor/src/backpressure/backpressureMonitor.ts`), keep it as an `interface` and do not flag it as a type-alias-vs-interface violation.

Applied to files:

  • apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts
  • apps/webapp/app/runEngine/concerns/idempotencyResidency.server.ts
🔇 Additional comments (11)
apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts (1)

2-2: LGTM!

Also applies to: 26-27, 188-238

apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.ts (1)

34-36: 🗄️ Data Integrity & Integration

No caller-contract issue is present. The only call sites are in apps/webapp/app/v3/services/bulk/BulkActionV2.batchReadThrough.server.test.ts; each readNew forwards client, and the provided logger defines error. Other callers omit the optional logger.

apps/webapp/test/apiBatchResultsPresenter.dedicatedSeam.test.ts (1)

6-6: 📐 Maintainability & Code Quality

No fixture change is needed.

makeNShardRunOpsPostgresTest is exported and provides legacyPrisma, newPrisma, and shardPrismas.

apps/webapp/app/v3/runOpsMigration/readThrough.server.ts (1)

6-17: LGTM!

Also applies to: 26-76, 78-139

apps/webapp/app/v3/runOpsMigration/readThrough.server.test.ts (1)

16-30: LGTM!

Also applies to: 46-46, 57-58, 69-69, 78-79, 91-98, 110-110, 126-127, 138-138, 152-198, 200-257, 259-308

apps/webapp/app/v3/runOpsMigration/waitpointTokenResolve.server.test.ts (1)

141-142: LGTM!

Also applies to: 154-154

apps/webapp/app/v3/runEngineHandlersShared.server.ts (1)

38-39: LGTM!

Also applies to: 51-51

apps/webapp/app/runEngine/concerns/resolveWaitpointThroughReadThrough.server.ts (1)

1-20: LGTM!

Also applies to: 31-41, 57-90

apps/webapp/test/resolveWaitpointThroughReadThrough.readthrough.test.ts (1)

4-4: LGTM!

Also applies to: 289-323, 325-360, 362-389

apps/webapp/app/routes/engine.v1.runs.$runFriendlyId.waitpoints.tokens.$waitpointFriendlyId.wait.ts (1)

41-48: LGTM!

Also applies to: 65-69

internal-packages/run-store/src/PostgresRunStore.ts (1)

33-33: LGTM!

Also applies to: 2761-2761

…-tri-13441' into feat/waitpoint-mint-flag-wiring-tri-13442
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Observability map

As of 1e28906.

20/100 over 449 measured of 467 entry points (base 19, up 1)

What this PR changed

route base head now failing
/engine/v1/runs/:runFriendlyId/waitpoints/tokens/:waitpointFriendlyId/wait 0 50

FIX FIRST

  • /api/v1/projects/:projectRef/envvars (sensitive) - auth-boundary, request-context
  • /auth/sso (sensitive) - auth-boundary, request-context
  • /_app/orgs/:organizationSlug/settings/team (sensitive) - error-classification, auth-scope, request-context

AUDIT 3 of 50 sensitive mutations record an actor. 47 without one.
CONTEXT 23 of 449 entry points name a tenant on a failure path. 347 appear only here, 39 of them sensitive, in the JSON rather than the fix list.

What the score is made of
CHECKS
  error-classification  183 applicable, 105 pass,   0 sole, global without it 12
  auth-boundary          62 applicable,  57 pass,   0 sole, global without it 16
  auth-scope             19 applicable,  17 pass,   0 sole, global without it 19
  request-context       449 applicable,  23 pass, 244 sole, global without it 64
  audit-trail            50 applicable,   3 pass,   0 sole, not in the score

The score and findings here are report-only and never gate the merge. Separately, a required test suite keeps this tool's symbol and route lists in sync with the code they name, and can fail a pull request that renames or removes a symbol they reference, or that adds the first route with a segment they anticipate. Each failure names the list to edit. The rules and their reasons: internal-packages/observability-map/README.md.

The mint-kind resolver and the shared mint-kind type are both dead code until
the commits that wire them up land. Knip is right to flag them.

The webapp module joins the ignore list beside runOpsMintShard.server.ts, which
sits there for the same reason. The engine type takes a @knipignore tag, since
that package has no ignore block.

Both come back out when their consumers land.
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