Skip to content

Add backend runtime env validator - #8520

Merged
Git-on-my-level merged 1 commit into
mainfrom
codex/backend-runtime-env-validator
Jun 28, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
codex/backend-runtime-env-validator

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jun 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add backend/deploy/runtime_env.yaml as the first canonical backend runtime env manifest.
  • Add backend/scripts/validate-backend-runtime-env.py to validate manifest entries against checked-in GKE Helm values and optional Cloud Run state/live revisions.
  • Document the validator in the LLM Gateway docs and AGENTS, and include the focused unit test in backend/test.sh.

This is validator-first only. It does not render deploy config or change deploy behavior yet; follow-up rendering/generation work is tracked in #8517.

Validation

  • cd backend && pytest tests/unit/test_backend_runtime_env_validator.py -q
  • python -m py_compile backend/scripts/validate-backend-runtime-env.py
  • python backend/scripts/validate-backend-runtime-env.py --env dev
  • python backend/scripts/validate-backend-runtime-env.py --env prod
  • python backend/scripts/validate-backend-runtime-env.py --env dev --check-live-cloud-run
  • python backend/scripts/validate-llm-gateway-env.py backend/charts/backend-listen/dev_omi_backend_listen_values.yaml backend/charts/llm-gateway/dev_omi_llm_gateway_values.yaml
  • python backend/scripts/validate-llm-gateway-env.py backend/charts/backend-listen/prod_omi_backend_listen_values.yaml backend/charts/llm-gateway/prod_omi_llm_gateway_values.yaml
  • git diff --check
  • pre-push hooks passed

Known current drift, intentionally surfaced by the new command:

  • python backend/scripts/validate-backend-runtime-env.py --env prod --check-live-cloud-run fails because prod Cloud Run backend, backend-sync, and backend-integration are missing OMI_LLM_GATEWAY_URL and OMI_LLM_GATEWAY_SERVICE_TOKEN bindings.

Review

An independent subagent reviewed the uncommitted patch before this PR. It found one issue: Cloud Run secret validation compared only the secret name, not the version/key. This PR fixes that by modeling Cloud Run secret bindings as {secret, version} and defaulting expected versions to latest, with a regression test for old pinned versions.

Closes part of #8515.

Review in cubic

@mintlify

mintlify Bot commented Jun 28, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
deepeninc 🟡 Building – Jun 28, 2026, 10:14 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@mintlify

mintlify Bot commented Jun 28, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
omi 🟢 Ready View Preview Jun 28, 2026, 10:15 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

4 issues found across 6 files

Confidence score: 3/5

  • backend/scripts/validate-backend-runtime-env.py can crash with an unhandled CalledProcessError when gcloud is unavailable, auth is expired, or a service lookup fails, so users get a traceback instead of actionable validation output and CI/debugging can fail noisily — catch subprocess failures and return a clean, structured error message before merging.
  • backend/scripts/validate-backend-runtime-env.py compares expected values as strings against raw YAML-parsed types, which can flag false mismatches (for example 8080 vs "8080") and erode trust in validation results — normalize both sides to a consistent type before comparison.
  • backend/scripts/validate-backend-runtime-env.py has brittle shape handling (cloud_run non-dict and malformed GKE service entries) that can raise AttributeError/hard-fail instead of reporting validation errors, so a bad config can terminate the whole check path — add defensive type checks and convert these paths to structured validation failures before merging.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/scripts/validate-backend-runtime-env.py">

<violation number="1" location="backend/scripts/validate-backend-runtime-env.py:120">
P2: If cloud_run is a non-dict value in the manifest (e.g. string or list), env_config.get('cloud_run', {}).get('services') raises AttributeError because .get() is called on a non-dict.</violation>

<violation number="2" location="backend/scripts/validate-backend-runtime-env.py:129">
P2: GKE validation can hard-fail on malformed service entries instead of returning structured validation errors.</violation>

<violation number="3" location="backend/scripts/validate-backend-runtime-env.py:196">
P2: str(expected_entry['value']) coerces to string but actual_entry.get('value') is the raw YAML-parsed type. A values-file value like `value: 8080` (int) vs manifest `value: "8080"` (string) would produce a false mismatch since `8080 != "8080"` in Python.</violation>

<violation number="4" location="backend/scripts/validate-backend-runtime-env.py:292">
P2: subprocess.run(check=True) raises CalledProcessError if gcloud is missing, auth is expired, or the service doesn't exist. The exception propagates as an ugly traceback instead of a clean error message.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

for key in ('gcp_project', 'region', 'gke', 'cloud_run'):
if key not in env_config:
errors.append(ValidationError(env, f'missing {key}'))
cloud_run_services = env_config.get('cloud_run', {}).get('services')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: If cloud_run is a non-dict value in the manifest (e.g. string or list), env_config.get('cloud_run', {}).get('services') raises AttributeError because .get() is called on a non-dict.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/scripts/validate-backend-runtime-env.py, line 120:

<comment>If cloud_run is a non-dict value in the manifest (e.g. string or list), env_config.get('cloud_run', {}).get('services') raises AttributeError because .get() is called on a non-dict.</comment>

<file context>
@@ -0,0 +1,305 @@
+    for key in ('gcp_project', 'region', 'gke', 'cloud_run'):
+        if key not in env_config:
+            errors.append(ValidationError(env, f'missing {key}'))
+    cloud_run_services = env_config.get('cloud_run', {}).get('services')
+    if not isinstance(cloud_run_services, dict) or not cloud_run_services:
+        errors.append(ValidationError(env, 'cloud_run.services must be a non-empty mapping'))
</file context>

if not _has_literal_value(actual_entry):
errors.append(ValidationError(scope, f'env {name} must have a literal value'))
continue
actual_value = actual_entry.get('value')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: str(expected_entry['value']) coerces to string but actual_entry.get('value') is the raw YAML-parsed type. A values-file value like value: 8080 (int) vs manifest value: "8080" (string) would produce a false mismatch since 8080 != "8080" in Python.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/scripts/validate-backend-runtime-env.py, line 196:

<comment>str(expected_entry['value']) coerces to string but actual_entry.get('value') is the raw YAML-parsed type. A values-file value like `value: 8080` (int) vs manifest `value: "8080"` (string) would produce a false mismatch since `8080 != "8080"` in Python.</comment>

<file context>
@@ -0,0 +1,305 @@
+                if not _has_literal_value(actual_entry):
+                    errors.append(ValidationError(scope, f'env {name} must have a literal value'))
+                continue
+            actual_value = actual_entry.get('value')
+            expected_value = str(expected_entry['value'])
+            if actual_value != expected_value:
</file context>

f'--region={region}',
'--format=json',
]
result = subprocess.run(command, check=True, capture_output=True, text=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: subprocess.run(check=True) raises CalledProcessError if gcloud is missing, auth is expired, or the service doesn't exist. The exception propagates as an ugly traceback instead of a clean error message.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/scripts/validate-backend-runtime-env.py, line 292:

<comment>subprocess.run(check=True) raises CalledProcessError if gcloud is missing, auth is expired, or the service doesn't exist. The exception propagates as an ugly traceback instead of a clean error message.</comment>

<file context>
@@ -0,0 +1,305 @@
+            f'--region={region}',
+            '--format=json',
+        ]
+        result = subprocess.run(command, check=True, capture_output=True, text=True)
+        service_state = json.loads(result.stdout)
+        services[service] = {
</file context>

def _validate_gke(env_config: dict[str, Any], *, strict_provisional: bool) -> list[ValidationError]:
errors: list[ValidationError] = []
for service, service_config in env_config.get('gke', {}).items():
values_file = ROOT / service_config['values_file']

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: GKE validation can hard-fail on malformed service entries instead of returning structured validation errors.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/scripts/validate-backend-runtime-env.py, line 129:

<comment>GKE validation can hard-fail on malformed service entries instead of returning structured validation errors.</comment>

<file context>
@@ -0,0 +1,305 @@
+def _validate_gke(env_config: dict[str, Any], *, strict_provisional: bool) -> list[ValidationError]:
+    errors: list[ValidationError] = []
+    for service, service_config in env_config.get('gke', {}).items():
+        values_file = ROOT / service_config['values_file']
+        values = _load_yaml(values_file)
+        actual_env = _env_entries_by_name(values.get('env', []))
</file context>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0aa35c1ba4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +94 to +97
secrets:
OMI_LLM_GATEWAY_SERVICE_TOKEN:
secret: OMI_LLM_GATEWAY_SERVICE_TOKEN
version: latest

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add core prod Cloud Run secrets to the manifest

When --env prod --check-live-cloud-run is used, _validate_cloud_run only checks the prod entries listed here. This prod section (and the repeated backend-sync/backend-integration sections) omits the existing SERVICE_ACCOUNT_JSON and ENCRYPTION_SECRET bindings that dev requires, even though backend import paths such as utils/encryption.py require ENCRYPTION_SECRET; a prod revision that drops those bindings would still pass the new validator and then fail at startup/decryption. Please add the same core prod env/secret bindings for all three services.

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 3d6ad1f into main Jun 28, 2026
4 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/backend-runtime-env-validator branch June 28, 2026 22:34

This branch was successfully deployed

1 active deployment
staging - docs — 0aa35c1b Deployed Jun 28, 2026 by mintlify[bot]
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