Skip to content

fix(deploy): let Cloud Run preflight see past the metrics sidecar - #12080

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/preflight-tolerates-gmp-sidecar
Aug 23, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/preflight-tolerates-gmp-sidecar

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

What broke

Automatic development backend deploys have failed on every run since the Managed Prometheus sidecar landed in #11998:

preflight-cloud-run-deploy.py: error: Legacy public-binding migration
requires exactly one container per Cloud Run service

deploy-backend-stack attaches the GMP collector to the candidate revision after the deploy, so from the first attach onward the service describes two containers. _single_container counted containers to prove there was one unambiguous set of runtime bindings to read, and the collector — which carries none of those bindings — broke the count. A correctly configured service now fails an argument check.

Live confirmation:

backend   dev=[backend-1;collector]   prod=[backend-1]

The fix

Select the application container by excluding the sidecar by name, instead of counting containers. This is the same rule attach_cloud_run_gmp_sidecar.py already applies when it resolves the ingress container, so the two scripts now agree on what the sidecar is.

This is not development-only

check_runtime_bindings is gated to the auto-dev profile, but migrate_legacy_public_bindings runs unconditionally in deploy-backend-stack, and the sidecar attach step is likewise ungated. Production has one container today, so the sequence there would be:

  1. First production deploy attaches the sidecar and succeeds.
  2. Every production deploy after it fails this check.

This lands before that trap arms rather than after.

A second occurrence, deliberately not fixed here

backend/scripts/sync_ledger_fence_cutover.py:307 has the same defect:

if len(images) != 1:
    raise CutoverError("Cloud Run candidate must have exactly one container image")

It collects images across every container and requires exactly one, and its SERVICES tuple includes backend — the service that now carries the collector. It is workflow_dispatch-only, so it blocks nothing today, but the next manual sync-ledger fence cutover would fail on it.

It is left out of this PR on purpose: that script sets up no sibling imports, so sharing the sidecar name with it means either duplicating a magic string (the drift that caused this class) or adding import machinery to a deploy-critical script under backend-import-purity. That deserves its own change rather than riding along with an urgent unblock.

Verification

Both new tests fail against the current script with the exact error string seen in CI, and pass with the fix. Coverage runs in both directions: a service carrying the collector is accepted, and a service with two genuine application containers is still rejected.

  • tests/unit/test_preflight_cloud_run_deploy.py — 18 passed
  • plus test_attach_cloud_run_gmp_sidecar.py, test_backend_runtime_env_validator.py, test_render_backend_runtime_env.py — 114 passed

Failure-Class: new

Review in cubic

Automatic development deploys have failed since the Managed Prometheus
sidecar landed in #11998:

    preflight-cloud-run-deploy.py: error: Legacy public-binding migration
    requires exactly one container per Cloud Run service

The sidecar is attached to the candidate revision after the deploy, so the
service carries two containers from then on. `_single_container` counted
containers to prove there was one unambiguous set of runtime bindings to
read, and the collector -- which holds none of those bindings -- broke that
count. Select the application container by excluding the sidecar by name
instead, which is the same rule `attach_cloud_run_gmp_sidecar.py` already
applies when it resolves the ingress container.

This is not development-only. `check_runtime_bindings` is gated to the
auto-dev profile, but `migrate_legacy_public_bindings` runs unconditionally
in `deploy-backend-stack`, and the sidecar attach is likewise ungated. The
first production deploy would attach the sidecar and succeed; every
production deploy after it would fail this argument check. Production has
one container today (`backend-1`), so the fix lands before the trap arms
rather than after.

Tests cover both call sites and both directions: a service carrying the
collector passes, and a service with two genuine application containers is
still rejected. Both new tests fail against the current script with the
exact error seen in CI.

Co-Authored-By: Claude Opus 5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit e357334 into main Aug 23, 2026
40 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/preflight-tolerates-gmp-sidecar branch August 23, 2026 04:47
Git-on-my-level added a commit that referenced this pull request Aug 23, 2026
…12081)

Development backend deploys still fail after #12080, now inside gcloud:

    ERROR: gcloud crashed (ValueError): Invalid secret path
    'projects/based-hardware-dev/secrets/cloud-run-gmp-config' in annotation

`_merge_secret_annotation` wrote the config secret into
`run.googleapis.com/secrets` using the project ID. gcloud parses that
annotation with

    ^projects/(?P<project>[0-9]{1,19})/secrets/(?P<secret>[a-zA-Z0-9-_]{1,255})...

(googlecloudsdk/command_lib/run/secrets_mapping.py), so the project segment
must be numeric. Resolve the project number and write that instead.

The shape of this is worth naming. Cloud Run accepts the attach with either
form, so nothing fails at attach time; the annotation is only re-parsed by
the *next* `gcloud run deploy` on that service. The first deploy after the
sidecar lands succeeds, and the one after it crashes on a service nobody
touched in between -- which is why this read as unrelated to #11998.

Production has no sidecar attached yet, so it has never written this
annotation and is not carrying the defect. It would have written it on its
first deploy and crashed on its second.

`patch_service` stays pure: `attach_sidecar` resolves the number and passes
it in, so no test needs a subprocess. A numeric project is passed through
without calling gcloud at all. The new annotation test asserts against the
gcloud regex verbatim rather than a hand-copied expectation.

Failure-Class: new

Co-authored-by: r <r@r>
Co-authored-by: Claude Opus 5 <[email protected]>
abunet added a commit to abunet/omi that referenced this pull request Aug 23, 2026
Six commits, no conflicts. Nineteen of the forty files are Swift desktop (legacy Home
visibility, BasedHardware#11933, plus the v0.12.209 changelog). The rest is upstream's Cloud Run / GCP
deploy lane: converging automatic dev deploys (BasedHardware#12019), a preflight that can see past the
metrics sidecar (BasedHardware#12080), and the GMP secret annotation written with a project number
(BasedHardware#12081).

Post-merge audit (ADR-0029/0030): nothing to resolve.

  ports        untouched — no file under database/store/, utils/{auth,vector,object_store}/,
               _client.py, or the notification transport is in the diff at all
  fidelity     the four new backend modules (attach_cloud_run_gmp_sidecar,
               firebase_release_probe_token, preflight-cloud-run-deploy,
               runtime_env_validation/workflows) introduce no raw persistence and no
               firebase_admin.auth — they are deploy tooling, not request-path code
  guards       9/9 exit 0, including the env-parity guard: upstream declared no new runtime
               variable this time

Worth noting for our own backlog: BasedHardware#12080 and the GMP sidecar attach script are the
Cloud Run mechanism behind PROMETHEUS_SIDECAR_PORT, which the previous merge wrote off as a
shape we do not deploy. Upstream building on it confirms the write-off was the right call
rather than a gap on our side.

Verification
  contract lane 55 files, 1083 passed, 78 skipped (live-tier only), 0 failed
  full sweep 1027 files in 3m19s, FAIL set identical to the pre-merge baseline
  upstream's five new backend test files run and pass under our runner
  (8 + 9 + 13 + 18 + 49), and their two new .github guard suites pass (37 + 67 subtests)
Git-on-my-level added a commit that referenced this pull request Aug 23, 2026
Development backend deploys fail at the post-deploy runtime-env validator:

    ERROR [cloud_run/backend]: env MEMORY_ENABLED value mismatch: expected 'on'

The deploy sets it correctly -- the gcloud command carries MEMORY_ENABLED=on
-- and the live revision then holds 'true'. The sidecar attach rewrites it
in between.

gcloud emits YAML 1.2, where `on` is a string; production's untouched export
literally contains `value: on`. PyYAML implements YAML 1.1, where on/off/yes/no
are booleans. `attach_sidecar` safe_loads that export, patches it, and
safe_dumps it back through `services replace`, so `on` lands as the string
'true'. All three of the manifest's on/off keys are rewritten; none survive.

Nothing fails at attach time. Cloud Run stores the rewritten string, and every
consumer accepts the coerced spelling, so behaviour is unchanged. It surfaces
one step later in a validator, on a service nobody edited -- the same delayed
shape as #12080 and #12081.

Restrict the bool resolver to the YAML 1.2 core set so the round trip preserves
what gcloud wrote. safe_dump already quotes ambiguous strings, so only the read
side changes. containerPort, periodSeconds and containerConcurrency still load
as integers and real booleans still load as booleans.

Production has never attached the sidecar, so its export still says `value: on`.
Its first attach would rewrite all three flags and then fail its own gate.

The test fixture is copied verbatim from a real `--format=export` of the
production service, including the unquoted `value: on`. A hand-written fixture
would have been written in the dialect the author already assumes.

Failure-Class: new

Co-authored-by: r <r@r>
Co-authored-by: Claude Opus 5 <[email protected]>
formed2forge pushed a commit to formed2forge/omi that referenced this pull request Aug 24, 2026
…sedHardware#12080)

Automatic development deploys have failed since the Managed Prometheus
sidecar landed in BasedHardware#11998:

    preflight-cloud-run-deploy.py: error: Legacy public-binding migration
    requires exactly one container per Cloud Run service

The sidecar is attached to the candidate revision after the deploy, so the
service carries two containers from then on. `_single_container` counted
containers to prove there was one unambiguous set of runtime bindings to
read, and the collector -- which holds none of those bindings -- broke that
count. Select the application container by excluding the sidecar by name
instead, which is the same rule `attach_cloud_run_gmp_sidecar.py` already
applies when it resolves the ingress container.

This is not development-only. `check_runtime_bindings` is gated to the
auto-dev profile, but `migrate_legacy_public_bindings` runs unconditionally
in `deploy-backend-stack`, and the sidecar attach is likewise ungated. The
first production deploy would attach the sidecar and succeed; every
production deploy after it would fail this argument check. Production has
one container today (`backend-1`), so the fix lands before the trap arms
rather than after.

Tests cover both call sites and both directions: a service carrying the
collector passes, and a service with two genuine application containers is
still rejected. Both new tests fail against the current script with the
exact error seen in CI.

Co-authored-by: r <r@r>
Co-authored-by: Claude Opus 5 <[email protected]>
formed2forge pushed a commit to formed2forge/omi that referenced this pull request Aug 24, 2026
…asedHardware#12081)

Development backend deploys still fail after BasedHardware#12080, now inside gcloud:

    ERROR: gcloud crashed (ValueError): Invalid secret path
    'projects/based-hardware-dev/secrets/cloud-run-gmp-config' in annotation

`_merge_secret_annotation` wrote the config secret into
`run.googleapis.com/secrets` using the project ID. gcloud parses that
annotation with

    ^projects/(?P<project>[0-9]{1,19})/secrets/(?P<secret>[a-zA-Z0-9-_]{1,255})...

(googlecloudsdk/command_lib/run/secrets_mapping.py), so the project segment
must be numeric. Resolve the project number and write that instead.

The shape of this is worth naming. Cloud Run accepts the attach with either
form, so nothing fails at attach time; the annotation is only re-parsed by
the *next* `gcloud run deploy` on that service. The first deploy after the
sidecar lands succeeds, and the one after it crashes on a service nobody
touched in between -- which is why this read as unrelated to BasedHardware#11998.

Production has no sidecar attached yet, so it has never written this
annotation and is not carrying the defect. It would have written it on its
first deploy and crashed on its second.

`patch_service` stays pure: `attach_sidecar` resolves the number and passes
it in, so no test needs a subprocess. A numeric project is passed through
without calling gcloud at all. The new annotation test asserts against the
gcloud regex verbatim rather than a hand-copied expectation.

Failure-Class: new

Co-authored-by: r <r@r>
Co-authored-by: Claude Opus 5 <[email protected]>
formed2forge pushed a commit to formed2forge/omi that referenced this pull request Aug 24, 2026
…Hardware#12083)

Development backend deploys fail at the post-deploy runtime-env validator:

    ERROR [cloud_run/backend]: env MEMORY_ENABLED value mismatch: expected 'on'

The deploy sets it correctly -- the gcloud command carries MEMORY_ENABLED=on
-- and the live revision then holds 'true'. The sidecar attach rewrites it
in between.

gcloud emits YAML 1.2, where `on` is a string; production's untouched export
literally contains `value: on`. PyYAML implements YAML 1.1, where on/off/yes/no
are booleans. `attach_sidecar` safe_loads that export, patches it, and
safe_dumps it back through `services replace`, so `on` lands as the string
'true'. All three of the manifest's on/off keys are rewritten; none survive.

Nothing fails at attach time. Cloud Run stores the rewritten string, and every
consumer accepts the coerced spelling, so behaviour is unchanged. It surfaces
one step later in a validator, on a service nobody edited -- the same delayed
shape as BasedHardware#12080 and BasedHardware#12081.

Restrict the bool resolver to the YAML 1.2 core set so the round trip preserves
what gcloud wrote. safe_dump already quotes ambiguous strings, so only the read
side changes. containerPort, periodSeconds and containerConcurrency still load
as integers and real booleans still load as booleans.

Production has never attached the sidecar, so its export still says `value: on`.
Its first attach would rewrite all three flags and then fail its own gate.

The test fixture is copied verbatim from a real `--format=export` of the
production service, including the unquoted `value: on`. A hand-written fixture
would have been written in the dialect the author already assumes.

Failure-Class: new

Co-authored-by: r <r@r>
Co-authored-by: Claude Opus 5 <[email protected]>
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