Skip to content

feat: per-environment default region#3878

Open
myftija wants to merge 14 commits into
mainfrom
env-level-region-default
Open

feat: per-environment default region#3878
myftija wants to merge 14 commits into
mainfrom
env-level-region-default

Conversation

@myftija

@myftija myftija commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Moves the default region selection from the project to the environment level. Resolution now follows env default → project default → global default, so existing projects keep working with no backfill. The region allowlist stays project-scoped; only the default moves. Preview branches inherit their parent's region, and DEV stays disabled.

myftija added 7 commits June 9, 2026 16:21
Adds a nullable FK for per-environment default region selection. Resolution
will fall back to the project default, then the global default.
Optional per-environment default region, mapped from the Prisma row in
toAuthenticated(). Read in the trigger path to route runs.
getDefaultWorkerGroupForProject now checks the environment default before
the project default. Adds resolveEffectiveDefaultWorkerGroupId as the shared
fallback chain (env -> project -> global).
SetDefaultRegionService now sets RuntimeEnvironment.defaultWorkerGroupId
(allowlist checks stay project-scoped). Regions route resolves the env in
its loader and action.
RegionsPresenter marks the effective default (env -> project -> global) and
all callers pass the current environment id.
Preview branches copy the parent env's defaultWorkerGroupId. Adds a unit
test for the env -> project -> global fallback order.
Prisma's checked create input rejects a raw FK scalar alongside relation
connects; use defaultWorkerGroup.connect instead.
@changeset-bot

changeset-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1267e48

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 25 packages
Name Type
@trigger.dev/core Patch
@trigger.dev/build Patch
trigger.dev Patch
@trigger.dev/plugins Patch
@trigger.dev/python Patch
@trigger.dev/redis-worker Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/sdk Patch
@internal/cache Patch
@internal/clickhouse Patch
@internal/llm-model-catalog Patch
@trigger.dev/rbac Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/schedule-engine Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/tsql Patch
@internal/zod-worker Patch
@internal/sdk-compat-tests Patch
@trigger.dev/react-hooks Patch
@trigger.dev/rsc Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 9, 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

This pull request implements per-environment default worker group selection. The change adds an optional defaultWorkerGroupId column to the RuntimeEnvironment database table and extends the AuthenticatedEnvironment type to expose this field. A new helper function resolveEffectiveDefaultWorkerGroupId implements a three-tier fallback resolution (environment → project → global default). Services and presenters are updated to accept and use this environment-scoped default when determining regions and worker queues. Routes now pass the environment ID to the RegionsPresenter and the SetDefaultRegionService operates at the environment level instead of the project level, storing the default worker group selection on the runtime environment record.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description clearly explains the change, its impact, and fallback behavior, but does not follow the provided template structure with required sections like Checklist, Testing, and Changelog. Add the required template sections: complete the Checklist, describe testing steps, and provide a Changelog entry. Include issue reference (Closes #) and screenshots if applicable.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: per-environment default region' accurately and concisely summarizes the main change: moving default region selection from project to environment level.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
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 env-level-region-default

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.

devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

- Scope RegionsPresenter env lookup to the resolved project (+ archivedAt: null)
  so a mismatched env id can't surface a default from another project.
- Index RuntimeEnvironment.defaultWorkerGroupId via a separate CONCURRENTLY
  migration to keep FK checks off a seq scan.
devin-ai-integration[bot]

This comment was marked as resolved.

The org layout caches regions for useRegions(); the set-default action
redirects to the same URL, so add a shouldRevalidate hook (mirroring the
pause/resume pattern) to refresh the default shown in Test/Replay.
@myftija myftija added the preview label Jun 9, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

…e templates

Two callers still read the project-level default directly, which the UI no
longer updates. Use resolveEffectiveDefaultWorkerGroupId (env -> project ->
global) in:
- api.v1.workers isDefault flag
- computeTemplateCreation.resolveMode (MICROVM template decision)
coderabbitai[bot]

This comment was marked as resolved.

…lver

- RuntimeEnvironment.defaultWorkerGroupId is now a plain nullable column (no FK,
  no relation, no index): a deleted region is tolerated and resolution falls back
  to project -> global. Avoids Prisma drift and FK-check overhead on a cold table.
- api.v1.workers and computeTemplateCreation.resolveMode now reuse
  getDefaultWorkerGroupForProject instead of re-reading the global flag, so their
  isDefault / MICROVM decisions match exactly where runs route (and resolve the
  global default the same way as the trigger path).
devin-ai-integration[bot]

This comment was marked as resolved.

RegionsPresenter now resolves the effective default through
getDefaultWorkerGroupForProject (existence-checked env -> project -> global),
so the UI default always matches where runs route and never points at a
deleted region. Removes the id-only resolveEffectiveDefaultWorkerGroupId
helper (and its test) now that all four sites share one resolver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant