Repository navigation
Add backend runtime env validator - #8520
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
There was a problem hiding this comment.
4 issues found across 6 files
Confidence score: 3/5
backend/scripts/validate-backend-runtime-env.pycan crash with an unhandledCalledProcessErrorwhengcloudis 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.pycompares expected values as strings against raw YAML-parsed types, which can flag false mismatches (for example8080vs"8080") and erode trust in validation results — normalize both sides to a consistent type before comparison.backend/scripts/validate-backend-runtime-env.pyhas brittle shape handling (cloud_runnon-dict and malformed GKE service entries) that can raiseAttributeError/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') |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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'] |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
💡 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".
| secrets: | ||
| OMI_LLM_GATEWAY_SERVICE_TOKEN: | ||
| secret: OMI_LLM_GATEWAY_SERVICE_TOKEN | ||
| version: latest |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
backend/deploy/runtime_env.yamlas the first canonical backend runtime env manifest.backend/scripts/validate-backend-runtime-env.pyto validate manifest entries against checked-in GKE Helm values and optional Cloud Run state/live revisions.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 -qpython -m py_compile backend/scripts/validate-backend-runtime-env.pypython backend/scripts/validate-backend-runtime-env.py --env devpython backend/scripts/validate-backend-runtime-env.py --env prodpython backend/scripts/validate-backend-runtime-env.py --env dev --check-live-cloud-runpython 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.yamlpython 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.yamlgit diff --checkKnown current drift, intentionally surfaced by the new command:
python backend/scripts/validate-backend-runtime-env.py --env prod --check-live-cloud-runfails because prod Cloud Runbackend,backend-sync, andbackend-integrationare missingOMI_LLM_GATEWAY_URLandOMI_LLM_GATEWAY_SERVICE_TOKENbindings.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 tolatest, with a regression test for old pinned versions.Closes part of #8515.