Skip to content

perf(webapp): scope env var create pre-check to submitted keys - #4579

Merged
ericallam merged 1 commit into
mainfrom
perf/scope-env-var-create-precheck
Aug 12, 2026
Merged

perf(webapp): scope env var create pre-check to submitted keys#4579
ericallam merged 1 commit into
mainfrom
perf/scope-env-var-create-precheck

Conversation

@ericallam

Copy link
Copy Markdown
Member

Summary

Setting or importing environment variables ran a conflict pre-check that loaded every variable in the project and every value across all of its environments, only to decide whether the submitted keys already had a value in the target environments. On projects with many variables and environments that meant reading tens of thousands of rows on each create/import call.

This scopes the pre-check to the submitted keys and target environments, so it reads only the rows it actually inspects (submitted keys × target envs), wrapped in boundedIn to keep the prepared-statement cache stable. Same conflict detection, a handful of rows instead of the whole project's env-var values.

@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 81520bf

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

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a04bd0fd-9082-464a-9767-131b96005394

📥 Commits

Reviewing files that changed from the base of the PR and between 7a49950 and 81520bf.

📒 Files selected for processing (1)
  • .server-changes/scope-env-var-create-precheck.md
📜 Recent review details
⏰ Context from checks skipped due to timeout. (17)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (9, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (4, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 12)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp
  • GitHub Check: obsmap / 🧪 Unit Tests: Observability Map
  • GitHub Check: runops-guard / runops-guard
  • GitHub Check: code-quality / code-quality
  • GitHub Check: audit
  • GitHub Check: audit
  • GitHub Check: Analyze (actions)
  • GitHub Check: Analyze (javascript-typescript)
🧰 Additional context used
🧠 Learnings (6)
📚 Learning: 2026-07-26T13:14:02.968Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 4378
File: .server-changes/realtime-run-reads-from-primary.md:0-0
Timestamp: 2026-07-26T13:14:02.968Z
Learning: For files in the .server-changes directory, the body text is published verbatim as dashboard-facing user release notes. Write entries in terms of user-visible behavior (what users can do/see), and avoid implementation-oriented details such as environment-variable names, internal mechanisms, or configuration knobs. If you need to include operational/configuration specifics, put those details in the PR description instead of the .server-changes entry.

Applied to files:

  • .server-changes/scope-env-var-create-precheck.md
📚 Learning: 2026-04-15T15:39:31.575Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/webapp.mdc:0-0
Timestamp: 2026-04-15T15:39:31.575Z
Learning: Applies to apps/webapp/**/*.{ts,tsx} : Access environment variables through the `env` export of `env.server.ts` instead of directly accessing `process.env`

Applied to files:

  • .server-changes/scope-env-var-create-precheck.md
📚 Learning: 2026-08-05T16:10:45.358Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 4515
File: docs/self-hosting/env/webapp.mdx:29-33
Timestamp: 2026-08-05T16:10:45.358Z
Learning: In `docs/self-hosting/env/webapp.mdx`, document only environment variables that apply to the single-database self-hosted webapp configuration. Do not add `RUN_OPS_*`, `RUN_OPS_LEGACY_*`, or `CONTROL_PLANE_*` variables because they apply only to the cloud multi-database split and would mislead self-hosted operators.

Applied to files:

  • .server-changes/scope-env-var-create-precheck.md
📚 Learning: 2026-07-30T18:44:03.619Z
Learnt from: 0ski
Repo: triggerdotdev/trigger.dev PR: 4426
File: apps/webapp/test/memberDevEnvironments.server.test.ts:124-125
Timestamp: 2026-07-30T18:44:03.619Z
Learning: In `apps/webapp` service tests, `apps/webapp/test/setup.ts` loads `.env` and supplies defaults for required environment variables, so transitive imports of `~/env.server` are supported when production services require them. Do not require dependency injection solely to avoid this established test import path; introduce configuration injection only when it provides production-level value, such as a broader `createEnvironment` abstraction.

Applied to files:

  • .server-changes/scope-env-var-create-precheck.md
📚 Learning: 2026-07-15T18:37:08.044Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: apps/webapp/CLAUDE.md:0-0
Timestamp: 2026-07-15T18:37:08.044Z
Learning: Applies to apps/webapp/app/**/*.ts : Access environment variables through the `env` export from `app/env.server.ts`; never use `process.env` directly.

Applied to files:

  • .server-changes/scope-env-var-create-precheck.md
📚 Learning: 2026-05-14T14:54:39.095Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3545
File: .server-changes/agent-view-sessions.md:10-10
Timestamp: 2026-05-14T14:54:39.095Z
Learning: In the `trigger.dev` repository, do not flag inconsistent dot vs slash notation in route/path strings inside `.server-changes/*.md` files. These markdown files are consumed verbatim into the changelog, so the mixed notation (e.g., `resources.orgs.../runs.$runParam/...`) is intentional and should be preserved as-is.

Applied to files:

  • .server-changes/scope-env-var-create-precheck.md
🔇 Additional comments (1)
.server-changes/scope-env-var-create-precheck.md (1)

1-6: LGTM!


Walkthrough

The environment-variable repository now imports boundedIn. Its create() query filters environment-variable records by submitted keys and filters their values by submitted environment IDs. A change description documents the optimized precheck behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the implementation and benefit but omits the required issue reference, checklist, testing, changelog, and screenshots sections. Add the required template sections and complete the issue reference, checklist, testing steps, changelog, and screenshots fields.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly describes the main change: scoping the environment-variable creation pre-check to submitted keys.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/scope-env-var-create-precheck

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.

@ericallam
ericallam marked this pull request as ready for review August 12, 2026 05:46

@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

coderabbitai[bot]

This comment was marked as resolved.

EnvironmentVariablesRepository.create() ran a conflict pre-check that loaded every variable in the project and every value across all environments, just to check whether the submitted keys already had a value in the target environments. Scope the pre-check to the submitted keys and target environments (wrapped in boundedIn) so it reads a handful of rows instead of the whole project's env-var values.
@ericallam
ericallam force-pushed the perf/scope-env-var-create-precheck branch from 7a49950 to 81520bf Compare August 12, 2026 06:31
@ericallam
ericallam merged commit 26cdedd into main Aug 12, 2026
53 of 61 checks passed
@ericallam
ericallam deleted the perf/scope-env-var-create-precheck branch August 12, 2026 07:15
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