Repository navigation
ci: add Firebase App Hosting rollout safety net - #155
Conversation
On 2026-04-10 two merges to main silently did not receive an
auto-rollout: the Cloud Build succeeded, the Cloud Run revision
came up healthy, but Firebase App Hosting never created a rollout
resource to shift traffic. The workaround was to POST a manual
rollout via the REST API. Without that, traffic sat on an old
revision indefinitely.
The rolloutPolicy on the `api` backend is vanilla
(`{codebaseBranch: main}`) and both affected builds are
field-for-field identical to the seven builds that auto-rolled out
successfully, so the root cause is almost certainly a transient
control-plane bug in Firebase App Hosting itself. Related:
firebase/firebase-tools#8866.
This workflow catches the silent skip automatically:
1. Waits up to 10 min for a READY build matching the pushed commit
SHA to appear in the App Hosting backend.
2. Polls the rollouts endpoint for up to 5 more minutes.
3. If no rollout references that build, POSTs one manually with
rolloutId = `rollout-safety-net-<date>-<shortsha>`.
4. Files a GitHub issue so we know the safety net fired.
Auth is keyless via the existing Workload Identity Federation
provider (`projects/.../workloadIdentityPools/github/providers/magic-bracket-repo`).
A dedicated `rollout-safety-net@` service account with
`roles/firebaseapphosting.admin` has been created and bound to the
repo's principalSet — no long-lived keys stored anywhere. The
workflow is a few curl/jq calls and costs $0.
Only trusted inputs (`github.sha`, `github.repository`,
`github.server_url`) are consumed, and all of them are passed to
shell via `env:` to avoid any `${{ }}` interpolation inside `run:`
blocks. Verified by running actionlint locally.
jq queries verified live against commit f646765 (the PR #154 merge
that triggered the second silent skip) — the workflow would have
found build-2026-04-10-011 and the manual rollout I created.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Note Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported. |
|
@claude do a code review |
|
Claude finished @TytaniumDev's task in 2m 5s —— View job Code ReviewOverall this is solid work — the security posture is excellent and the happy-path logic is correct. A few medium and minor issues to consider. Security ✅
Medium Issues1.
get() {
curl -sS -H "Authorization: Bearer $(gcloud auth print-access-token)" "$@"
}Without Recommend either: get() {
curl -sSf -H "Authorization: Bearer $(gcloud auth print-access-token)" "$@"
}...and then the 2. POST response is never checked for errors
CREATE_RESULT=$(get -X POST \
-H "Content-Type: application/json" \
-d "$CREATE_BODY" \
"$API/rollouts?rolloutId=$ROLLOUT_ID")
echo "$CREATE_RESULT"If the POST returns 409 Conflict (e.g., Firebase fired an auto-rollout in the gap between step 2 ending and step 3 running) or 400 Bad Request, the workflow continues silently to the verification step. The verify then fails because Minor Issues3. Fixed
sleep 5
VERIFY=$(get "$API/rollouts/$ROLLOUT_ID") || VERIFY=''The comment on line 145-146 says "the response is an Operation, not the rollout itself". If for attempt in 1 2 3; do
sleep 5
VERIFY=$(get "$API/rollouts/$ROLLOUT_ID") || VERIFY=''
echo "$VERIFY" | jq -e '.build' >/dev/null 2>&1 && break
echo " [verify $attempt/3] Rollout not yet visible, retrying..."
done4.
ROLLOUTS_JSON=$(get "$API/rollouts?pageSize=1000") || ROLLOUTS_JSON='{}'The Firebase App Hosting REST API doesn't document a maximum Nits
Summary
The security and concurrency design are both well-thought-out. The WIF setup, |
There was a problem hiding this comment.
Code Review - Approved
No issues found. Checked for bugs, security issues, and CLAUDE.md compliance.
Security: All ${{ }} expressions are passed through env: into the shell (not interpolated directly in run: blocks) — correct injection-prevention practice. The rollout ID is built from a date string and a 7-char hex SHA, both safe in a URL. The POST body is constructed via jq -nc rather than string interpolation.
Logic: Polling loops are correct (60 × 10 s = 10 min for build, 30 × 10 s = 5 min for rollout). Exit paths are appropriate — no READY build exits with exit 0 and a warning (non-fatal, correct since the build may have legitimately failed elsewhere); finding an existing rollout exits cleanly; issue-creation failure is non-fatal.
Observation (not blocking): curl -sS without --fail means HTTP 4xx/5xx responses from the Firebase App Hosting API won't cause curl to exit non-zero — API errors are silently treated as "no results yet" and polling continues. This is acceptable for a safety net since it avoids false alarms during transient auth or control-plane blips; the downside is a silent 15-minute spin if auth is broken, but the operator will notice via the workflow summary.
CLAUDE.md: CI/infra-only change, no application code or data flow affected — DATA_FLOW.md update not required.
Production incident: stale-sweeper Cloud Scheduler job has been failing with 503s since 2026-04-11 20:15 UTC. Cloud Run logs confirm the API container is being OOM-killed (SIGABRT, signal 6) mid-sweep with memory usage landing at 526-535 MiB — just past the 512 MiB ceiling #153 set. Because #151 made the sweeper the only recovery path for stuck jobs, an OOMing sweeper means stuck jobs are no longer being recovered. This reverts the memory portion of #153. Per #153's own commit message, recurring OOMs are "a signal the architectural work isn't complete" — a follow-up will investigate what regressed between #153 and now (candidates: #154, #155, #156). Shipping the memory bump first to stop the bleeding and clear the alert. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Production incident: stale-sweeper Cloud Scheduler job has been failing with 503s since 2026-04-11 20:15 UTC. Cloud Run logs confirm the API container is being OOM-killed (SIGABRT, signal 6) mid-sweep with memory usage landing at 526-535 MiB — just past the 512 MiB ceiling #153 set. Because #151 made the sweeper the only recovery path for stuck jobs, an OOMing sweeper means stuck jobs are no longer being recovered. This reverts the memory portion of #153. Per #153's own commit message, recurring OOMs are "a signal the architectural work isn't complete" — a follow-up will investigate what regressed between #153 and now (candidates: #154, #155, #156). Shipping the memory bump first to stop the bleeding and clear the alert. Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Summary
Adds `.github/workflows/rollout-safety-net.yml`. On every push to `main`, it verifies that Firebase App Hosting actually created a rollout for the new build — and if it didn't, creates one manually and files an issue so we notice. Uses keyless auth (Workload Identity Federation) with a dedicated service account; no long-lived keys stored anywhere.
Why
On 2026-04-10 two merges to `main` produced successful Cloud Builds + healthy Cloud Run revisions, but Firebase App Hosting silently did not create a rollout resource to shift traffic. Both times the fix was `POST /v1/.../backends/api/rollouts` via the REST API. Without that, traffic sat on an old revision indefinitely — tonight I caught it in ~15 minutes by watching logs, but an unattended deploy could sit stuck for hours.
A read-only forensics pass (separate subagent investigation, findings summarized in the commit) ruled out every config-side explanation:
It's almost certainly a transient Firebase App Hosting control-plane glitch, which means we can't fix the root cause on our side — we can only detect and recover. This workflow does exactly that.
What the workflow does
On `push: branches: [main]`:
Happy path (auto-rollout fires normally): the workflow finds the rollout within the first few seconds of step 3 and exits silently with zero side effects. Only fires on the pathological case.
Auth / infrastructure
The workflow piggy-backs on the same WIF provider (`projects/14286370379/locations/global/workloadIdentityPools/github/providers/magic-bracket-repo`) that the existing `deploy.yml` uses — no new WIF infrastructure.
Security
Only trusted inputs are consumed: `github.sha`, `github.repository`, `github.server_url`. All are passed to shell via `env:` rather than direct `${{ }}` interpolation inside `run:` blocks, per GitHub's workflow injection guidance. Verified clean by `rhysd/actionlint:latest`.
Cost
$0. A handful of curl calls per push, WIF is free, no running containers.
Test plan
Rollback
If something goes wrong, delete `.github/workflows/rollout-safety-net.yml` and the workflow stops running. The service account can be cleaned up via `gcloud iam service-accounts delete rollout-safety-net@magic-bracket-simulator.iam.gserviceaccount.com` if desired, but there's no cost to leaving it.
🤖 Generated with Claude Code