Skip to content

fix(deploy): validate rendered runtime env before apply - #12098

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/runtime-env-boolean-coercion
Aug 23, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/runtime-env-boolean-coercion

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Make render_backend_runtime_env.py emit validator state from the same literal env values, secret references, and network flags it sends to deploy-cloudrun (backend/scripts/render_backend_runtime_env.py:96-100, backend/scripts/render_backend_runtime_env.py:190-207).
  • Move the pre-deploy runtime-env gate after rendering and validate that exact state artifact instead of a state synthesized back from the manifest (.github/actions/deploy-backend-stack/action.yml:416-439).
  • Require the GMP sidecar export/replace editor to match the rendered state both after gcloud export and after YAML serialization, before services replace (backend/scripts/attach_cloud_run_gmp_sidecar.py:392-417, backend/scripts/attach_cloud_run_gmp_sidecar.py:451-482).
  • Remove the synthetic --check-rendered-cloud-run validator mode; offline pre-deploy validation now uses the same --cloud-run-state input contract as every other offline state check (backend/scripts/runtime_env_validation/manifest.py:636-680).

Root cause

PR #11998 introduced the exact coercion boundary in backend/scripts/attach_cloud_run_gmp_sidecar.py: its original version parsed gcloud run services describe --format=export with yaml.safe_load at line 287 and wrote the result back with yaml.safe_dump at line 325. gcloud emits YAML 1.2, where plain on / off are strings; PyYAML's safe loader uses YAML 1.1 boolean resolution. The load therefore changed off / off / on into False / False / True, and the dump plus gcloud run services replace persisted false / false / true.

The loader correction from PR #12083 is already on this branch's current main: GcloudExportLoader restricts boolean resolution to the YAML 1.2 core spellings (backend/scripts/attach_cloud_run_gmp_sidecar.py:21-48) and the export is read with it (backend/scripts/attach_cloud_run_gmp_sidecar.py:409). This PR makes that correction fail closed against the deploy's rendered contract, so a future dialect regression cannot reach services replace (backend/scripts/attach_cloud_run_gmp_sidecar.py:253-268, backend/tests/unit/test_attach_cloud_run_gmp_sidecar.py:309-391).

The pre/post disagreement was separate: before this PR, _build_rendered_cloud_run_state in backend/scripts/runtime_env_validation/cloud_run.py:32-106 copied values directly out of the manifest, so --check-rendered-cloud-run compared the manifest to itself. The post-deploy path read actual Cloud Run state. The pre-deploy pass therefore said nothing about the renderer or sidecar round trip. The workflow now validates the actual renderer artifact and gives that same artifact to the only export/replace mutation (.github/actions/deploy-backend-stack/action.yml:416-439, .github/actions/deploy-backend-stack/action.yml:483-503).

Guard placement

This is not a new shared primitive: the GMP attach is the only backend deploy step that exports a whole Cloud Run service, edits it, and replaces it. The local pre-apply guard is therefore at that mutation boundary and directly covers the failure introduced by PR #11998 and observed in run 32620507075 (backend/scripts/attach_cloud_run_gmp_sidecar.py:392-482). The general renderer/validator contract remains shared through the JSON state consumed by validate_runtime_env (backend/scripts/render_backend_runtime_env.py:190-207, backend/scripts/runtime_env_validation/manifest.py:672-680).

I did not add a lexical ban on unquoted on / off / yes / no in the checked-in runtime manifest. All 373 current value nodes load as strings, and the incident manifest values were already quoted; such a ban would guard the wrong producer and would reject valid YAML 1.2 output from gcloud. The behavioral tests instead cover all four tokens at the renderer boundary and force a YAML 1.1 retype at the export/replace boundary (backend/tests/unit/test_render_backend_runtime_env.py:75-113, backend/tests/unit/test_attach_cloud_run_gmp_sidecar.py:331-390).

Verification

Red-first confirmation before the implementation:

  • test_render_backend_runtime_env.py failed because no rendered-state function/artifact existed.
  • test_attach_cloud_run_gmp_sidecar.py showed the simulated YAML 1.1 retype reached services replace without raising.
  • test_verify_backend_release_vector.py showed the pre-deploy validator still ran before the real render.

Focused green tests, run as individual modules:

  • test_render_backend_runtime_env.py: 25 passed.
  • test_attach_cloud_run_gmp_sidecar.py: 11 passed.
  • test_backend_runtime_env_validator.py: 85 passed.
  • test_verify_backend_release_vector.py: 49 passed.
  • test_workflow_contracts.py: 25 passed.
  • test_listen_finalization_cloud_tasks.py: 97 passed.

Additional checks:

  • A production-shaped local render followed by validate-backend-runtime-env.py --env prod --check-workflows --cloud-run-state <state> passed and the state contained exact off / off / on values.
  • bash backend/scripts/check_runtime_env_compose.sh reported backend/deploy/runtime_env.yaml is up to date.
  • Read-only gcloud run revisions describe reconfirmed the serving revision has off / off / on and the rejected candidate has false / false / true for the three affected flags.
  • No deploy, production configuration mutation, or traffic shift was performed.

Product invariants

None (scripts/pr-preflight --suggest).

Failure-Class: FC-serialiser-dialect-mismatch-retypes-values

Review in cubic

Failure-Class: FC-serialiser-dialect-mismatch-retypes-values
@Git-on-my-level
Git-on-my-level merged commit 48d9625 into main Aug 23, 2026
40 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/runtime-env-boolean-coercion branch August 23, 2026 17:58
formed2forge pushed a commit to formed2forge/omi that referenced this pull request Aug 24, 2026
…e#12098)

Failure-Class: FC-serialiser-dialect-mismatch-retypes-values

Co-authored-by: r <r@r>
kodjima33 pushed a commit that referenced this pull request Aug 24, 2026
…12114)

The pre-deploy runtime-env gate now validates the artifact the renderer
produces (#12098), but that artifact only carries services. `_validate_cloud_run`
skips its whole job branch when the state has no `jobs` key, so the env, secret
and `forbidden_env` contract declared for notifications-job and
memory-maintenance-job is no longer checked anywhere: the job workflows run the
validator with `--check-workflows` only, and the post-deploy live check is
services-only by design. The comment in `_fetch_live_cloud_run_state` still
promises that "the job contract is still validated statically against the
rendered state".

Render jobs into the state from the same helpers that already render their
deploy inputs in the same invocation, so the gate sees them again.

Failure-Class: FC-mirrored-model-omits-new-member
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