Skip to content

feat(webapp): org-gated internal API origin in run env vars - #4366

Merged
myftija merged 6 commits into
mainfrom
feature/internal-api-origin-org-flag
Jul 28, 2026
Merged

feat(webapp): org-gated internal API origin in run env vars#4366
myftija merged 6 commits into
mainfrom
feature/internal-api-origin-org-flag

Conversation

@myftija

@myftija myftija commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Adds an opt-in way for operators to route deployed runs' API traffic through a different origin than the public one, per organization. Set INTERNAL_API_ORIGIN on the webapp and enable the internalApiOriginEnabled feature flag (globally or per org, with the org override winning in both directions): deployed runs for enabled orgs then get TRIGGER_API_URL set to the internal origin instead of API_ORIGIN. Useful for gradually moving run traffic onto a private network path.

Design

The origin is resolved when an attempt starts, so flag changes take effect on the next attempt and roll back the same way, with no task redeploys. The org override is read fresh per attempt; the global default comes from the cached flags registry (a cold read fails safe to the public origin). When INTERNAL_API_ORIGIN is unset the flag is a no-op and no extra queries run, so existing deployments are unaffected. Dev runs always use the public origin, and TRIGGER_STREAM_URL remains unchanged.

myftija added 3 commits July 24, 2026 16:31
Deployed runs get TRIGGER_API_URL from INTERNAL_API_ORIGIN when the
org's internalApiOriginEnabled feature flag resolves on (org override
wins in both directions, global default otherwise). No-op unless
INTERNAL_API_ORIGIN is set. Resolved at attempt start, so flag changes
apply on the next attempt without redeploys.
… cached flags registry

Review follow-ups: the global default now comes from the in-memory
globalFlagsRegistry snapshot (cold read fails safe to the public
origin) instead of a per-attempt featureFlag query, and the deliberate
non-switching of TRIGGER_STREAM_URL is documented.
@coderabbitai

coderabbitai Bot commented Jul 24, 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: 86050240-635e-4d87-9cba-a0c34652c325

📥 Commits

Reviewing files that changed from the base of the PR and between d90a794 and 4133bc0.

📒 Files selected for processing (3)
  • apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.ts
  • apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts
  • apps/webapp/app/v3/services/worker/workerGroupTokenService.server.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.ts
  • apps/webapp/app/v3/services/worker/workerGroupTokenService.server.ts
  • apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (21)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (11, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (9, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (5, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (10, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (12, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (4, 12)
  • GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp
  • GitHub Check: typecheck / typecheck
  • GitHub Check: runops-guard / runops-guard
  • GitHub Check: code-quality / code-quality
  • GitHub Check: audit
  • GitHub Check: audit
  • GitHub Check: 🛡️ E2E Auth Tests (full)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (actions)

Walkthrough

Adds the internalApiOriginEnabled feature flag with strict boolean validation and organization-level override resolution. Adds the optional INTERNAL_API_ORIGIN environment variable and uses the resolved flag state to select the production TRIGGER_API_URL origin, while leaving TRIGGER_STREAM_URL unchanged. Adds tests for valid overrides, defaults, and invalid feature-flag inputs, plus a change entry documenting the behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description summarizes the change but omits the required template sections: issue link, checklist, testing, changelog, and screenshots. Add the template sections, including Closes #, checklist items, testing steps, a changelog summary, and a screenshots section.
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: org-gated internal API origin for run environment variables.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/internal-api-origin-org-flag

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.

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

… staleness

The internal-api-origin lookup used the writer client in a file that reads
via $replica; flag reads tolerate snapshot staleness. Also: the resolution
comment now states that a global-default flip lags by the registry reload
interval per instance (only org overrides apply on the very next attempt),
the invalid-override test asserts fallback to an enabled global default,
and the release note is written for self-hosters.
@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4133bc0

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

… flags

Read the org's feature flags off the environment already loaded at attempt
start instead of a per-attempt query, and take the global default from the
INTERNAL_API_ORIGIN_ENABLED env var — matching the scheduled-queue-split
resolver. Both prod env-var loaders now include organization.featureFlags.
coderabbitai[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

…registry

Resolve the global default from the cached DB feature-flags snapshot so the
admin global toggle takes effect, with INTERNAL_API_ORIGIN_ENABLED as the
fallback when unset. Load organization.featureFlags only when
INTERNAL_API_ORIGIN is configured.
Comment thread apps/webapp/app/v3/featureFlags.ts
@myftija
myftija merged commit 44eca4d into main Jul 28, 2026
46 checks passed
@myftija
myftija deleted the feature/internal-api-origin-org-flag branch July 28, 2026 09:28
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.

3 participants