Repository navigation
ci(firestore): auto-queue the index migration a merged manifest already approved - #11794
Merged
Merged
Conversation
…ing to `gcp_firestore_indexes.yml` was `workflow_dispatch:` only, so nothing applied a merged manifest. #11731 fixed the manifest generator and merged at 2026-08-18T01:10:37Z; prod was unchanged, and `GET /v3/memories` 503'd for every user for ~5h (1,498 x 503, zero 200s in a 6h window) on a composite index that existed only on paper. Trigger the reconcile automatically on a `main` push that changes `firestore.indexes.json`. Automatic runs target `prod` and are authorized by that GitHub Environment's required reviewer instead of the typed confirmation a push cannot supply; `workflow_dispatch` keeps `APPLY_FIRESTORE_INDEXES` mandatory and any other trigger fails closed. The environment and the lock are resolved with an explicit dispatch-or-default expression, and `check-deployment-concurrency.py` learns to render it. A bare `github.event.inputs.environment` renders empty on push, which would bind no GitHub Environment at all and silently bypass the prod approval, and would leave the concurrency group serializing nothing. Move the lane off the shared `deploy-backend-stack-${env}` lock onto its own `firestore-schema-${env}` domain, enforced by a new `validate_firestore_schema_lock_isolation` policy. Create-only reconciliation only moves an index MISSING -> CREATING -> READY, so it can never invalidate a readiness answer a deploy already obtained; the deploy ordering guarantee is owned by the fail-closed `firestore_readiness` job, not by the lock. Sharing the lock bought no ordering property and cost 5 hours: a `gcp_backend.yml` run parked in `waiting` on an unactioned prod approval since Aug 16 held deploy-backend-stack-prod, so the dispatched schema repair queued behind the outage it was repairing. `validate_automatic_backend_stack_lifecycle` now resolves interpolated concurrency groups instead of matching the literal string. The literal match could not see `deploy-backend-stack-${{ ... }}`, which is why the obvious version of this change (push trigger, shared lock) passed CI; it also could not see that `gcp_backend_listen_helm.yml` has been a second automatic writer on the dev backend-stack lock, so that is now registered explicitly rather than invisibly. `test_static_firestore_index_migration_is_manual_and_main_scoped` pinned the old dispatch-only shape and the shared lock by name; it is renamed and retargeted at the new contract, keeping every assertion whose intent survives (main-scoped, create-only plan-before-apply, exact-SHA checkout, no `--check-only` in the writer) and adding the two whose absence is silent: no empty environment binding, no backend-stack group. Verified: python3 .github/scripts/check-deployment-concurrency.py --self-test -> OK python3 .github/scripts/check-deployment-concurrency.py -> OK (24 writers) actionlint .github/workflows/gcp_firestore_indexes.yml -> clean backend tests/unit/test_firestore_index_config.py -> 8 passed backend tests/unit/test_verify_backend_release_vector.py -> 49 passed Reverting the lane to the draft shape (push + shared lock) makes the repo check fail on three independent assertions. Co-Authored-By: Claude Opus 5 <[email protected]>
Reconciliation is create-only, so the manifest is only half a source of truth: an index dropped from `firestore.indexes.json`, or hand-created in the console during an incident (two were, on 2026-08-18), keeps serving with nothing pointing at it and nothing noticing. Deleting automatically is not the fix -- a still-serving older Cloud Run revision can need an index the new manifest dropped, which makes an automatic delete an outage primitive. Report the drift instead: `--check-only` and `--dry-run` now emit a non-blocking `::warning::` per undeclared live index. Both backend deploy lanes already run `--check-only` on every deploy, so this surfaces on an existing blocking step rather than adding a lane, and the token list of those audited invocations is unchanged. Removal stays a human action. Datastore-mode indexes and the implicit terminal `__name__` alias are excluded so the report has no false positives. Verified: backend tests/unit/test_reconcile_firestore_indexes.py -> 33 passed. Co-Authored-By: Claude Opus 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GET /v3/memoriesreturned 503 for every user on every platform for ~5 hours on2026-08-18 (1,498 × 503, zero 200s in a 6h window; 355 distinct client IPs in 2h). The
required
memoriescomposite index (updated_at DESC + __name__ ASC) did not exist inprod.
The fix was already merged. #11684 diagnosed it; #11731 fixed the manifest generator and
added the entries, merging at 2026-08-18T01:10:37Z. Prod did not change, because:
gcp_firestore_indexes.ymlwasworkflow_dispatch:only — across every revision since
ed434840d7; no trigger was ever removed. Its lastrun before the incident was Aug 13, four days before fix(backend): declare opposite-direction Firestore list-scan indexes + converge cascade-retract CAS (#11684, #11726) #11731 merged.
concurrency: deploy-backend-stack-${env}withgcp_backend.yml, and agcp_backend.ymlrun had sat inwaitingon an unactioned prod approval since Aug 16holding that lock. A dispatched reconcile queued behind it indefinitely and only ran
after that stale run was force-cancelled.
(The third hole — the manifest generator silently dropping the index so the deploy-time
firestore_readinessgate passed vacuously — is closed by #11731 and is not re-fixedhere.)
Critique of the draft plan — what I rejected
The draft was: add
pushonmainfiltered tofirestore.indexes.json, run--provision-missing, plus "something that stops a stalewaitingrun fromdeadlocking the lane", justified by the workflow being create-only and already
serialising against deploys. Right instinct, three wrong mechanisms.
Rejected —
pushwhile keepinggithub.event.inputs.environment. On apusheventthat expression evaluates to the empty string. The draft silently produces
environment:— no GitHub Environment binding at all, so the prod required-reviewerapproval is bypassed — and
group: deploy-backend-stack-, a third group thatserialises against nothing, which voids the draft's own "it already serialises against
deploys" safety argument for exactly the runs it adds. Both must be resolved by
expression.
Rejected — keeping the shared
deploy-backend-stack-${env}lock. The draft creditsthe lock with an ordering guarantee it does not provide.
READY" is enforced by
gcp_backend.yml:189/gcp_backend_auto_dev.yml:246firestore_readiness(--check-only, fail-closed), not by the lock. The lock onlyprevents interleaving.
--provision-missingonly creates, so an index moves MISSING → CREATING → READY and never backwards. A
concurrent reconcile therefore cannot invalidate a readiness read that already returned
READY. The race is theoretical, not real.
hostage to a deploy approval nobody had actioned. Coupling the repair path to the thing
being repaired is the actual defect.
only one pending run per concurrency group, so an auto-triggered reconcile on
deploy-backend-stack-developmentcan evict the pendinggcp_backend_auto_dev.ymlruncarrying an admitted Release Eligibility SHA — the hazard documented verbatim in
validate_automatic_backend_stack_lifecycle's own docstring.Rejected — a mechanism to unstick stale
waitingruns. Every concrete version isworse than the structural fix. There is no timeout for approval waits; auto-expiring
waitingruns means CI silently cancelling a production deploy someone deliberatelyqueued; loosening the prod environment policy trades this incident for a worse class. The
right mechanism is that the schema lane must not be in the deploy lane's lock domain at
all, so neither can deadlock the other.
Rejected — auto-apply to prod without a human. Auto-queue is what was actually
missing. The failure was "a human had to remember a workflow exists", not "a human was
involved".
Rejected alternatives to the trigger, and the deliberate boundary question. The draft
does not contradict the design intent in those workflow comments — it keeps the writer
boundary exactly where it is. The alternatives do contradict it:
gcp_backend.ymldirectly violates "deploy workflows remain read-onlyand can only gate on the serving schema", and is mechanically blocked by
FIRESTORE_SCHEMA_WRITERS.audience are dead checks"), and a schedule that writes prod schema unattended is worse
than a push-triggered one.
now happen — but it is a gate, not a fix. It never creates the index.
Design
1. Auto-trigger, human-approve.
pushonmainfiltered tofirestore.indexes.json. Automatic runs resolve toprod; the prod GitHub Environment'srequired reviewer is the approval. That turns "remember a workflow exists" into "click
Approve on a run already sitting there, named after the commit".
2. The
APPLY_FIRESTORE_INDEXESconfirmation, without weakening the manual path. Apushcannot supply it, so its substitute is the environment approval — strictly stronger(a second person, out of band) than a string typed by whoever dispatched the run. The
typed confirmation stays mandatory for
workflow_dispatch, and any other trigger failsclosed.
3. Explicit environment resolution.
${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'prod' }}for both
environment:and the concurrency group.check-deployment-concurrency.py'sresolve_environmentlearns to render this form, sothe group stays legible to every policy that reasons about it.
4. Its own lock domain.
firestore-schema-${env},cancel-in-progress: false,enforced by a new
validate_firestore_schema_lock_isolationpolicy that rejects anyFirestore schema writer whose group resolves into
deploy-backend-stack-*or fails toresolve to a concrete lock. The
(gcp_firestore_indexes.yml, gcp_backend_auto_dev.yml)lock family pair is dropped; dev ≠ prod is still asserted.
Residual within the lane — a
waitingreconcile blocking the next reconcile — is benign:the manifest is desired state, so GitHub evicting the older pending run in favour of the
newer commit's is correct, not lossy.
5. Dev is deliberately not in the automatic run. One workflow has one workflow-level
concurrency group, so covering both environments in one run would force a shared group and
reintroduce a cross-environment lock. Dev keeps its one-click dispatch (no approval
configured) and its auto-deploy already fails closed and loudly on a missing index. Called
out as a residual below.
6. Create-only drift is reported, never acted on. Nothing removes an index dropped
from the manifest, and nothing noticed the two indexes hand-created in the console during
the incident. Auto-deleting is an outage primitive — a still-serving older Cloud Run
revision can need an index the new manifest dropped. So
--check-onlyand--dry-runnowemit a non-blocking
::warning::per undeclared live index. Both deploy lanes already run--check-onlyon every deploy, so this lands on an existing blocking step rather thanadding a lane, and the token list of those audited invocations is unchanged (
--check-onlystill satisfies
is_readiness_check). Deletion stays a human action.7. The guard that would have caught the draft.
validate_automatic_backend_stack_lifecyclenow resolves interpolated concurrencygroups instead of matching the literal string
deploy-backend-stack-development.Pre-existing defect found
The literal-string match also could not see that
gcp_backend_listen_helm.ymlhas beena second automatic writer on the dev backend-stack lock — it has
push: branches: [main]and a group resolving to
deploy-backend-stack-development, i.e. exactly the evictionhazard that check was written to prevent. This PR does not change its lock (out of scope,
and it is a live deploy path), but registers it explicitly in
AUTOMATIC_BACKEND_STACK_WRITERSwith a comment, converting an invisible hazard into anaudited one.
A test was rewritten alongside the code it asserts — why
test_static_firestore_index_migration_is_manual_and_main_scopedpinned the workflow'sold shape by name:
workflow_dispatch:-only,group: deploy-backend-stack-${{ github.event.inputs.environment }}, andenvironment: ${{ github.event.inputs.environment }}. Those three literals are exactlywhat this PR changes, so it is renamed to
test_static_firestore_index_migration_is_approved_and_main_scopedand retargeted.The external source for the new expected values is not this PR's reasoning, it is the
incident and GitHub's own semantics: (a) the run history shows the lane's last execution
before the outage was Aug 13, four days before #11731 merged, so dispatch-only is the
defect being removed; (b) GitHub renders
github.event.inputs.*as the empty string onnon-
workflow_dispatchevents, which is why the new assertions forbid a bareenvironment: ${{ github.event.inputs.environment }}rather than requiring it — the samerendering that
gcp_backend_listen_helm.ymlalready relies on with its|| 'development'default.Every assertion whose intent survives the redesign is kept verbatim: main-scoped
if:,exact-
github.shacheckout plus its verification,credentials_jsonbinding,plan-before-apply ordering, exactly one
--dry-runand one--provision-missing, no--check-onlyin the writer,--timeout-seconds 3600. Two assertions were added forfailure modes that are silent rather than loud (empty environment binding, backend-stack
group). It is a static tripwire, not behavioral coverage — the automatic lane can only be
executed by a real push to
main.Commit type
ci(...), notfix(...). This is CI/deploy-lane infrastructure — nothing in product orbackend runtime behaviour changes — so no
Failure-Class:declaration is required, andscripts/pr-preflight --suggestconfirms: "Nofix:commits were detected; nodeclaration is required." The runtime bug itself was fixed by #11731 and #11791.
No new checks, probes, or scripts
Every assertion added lands in an existing lane.
check-deployment-concurrency.pyalreadyruns in
.github/workflows/repo-checks.yml:146,149andscripts/pre-push:796,797; the newtests are in already-discovered backend unit files. No
.github/checks-manifest.yamlentryis needed because no new script exists.
Verification
Adversarial check — the draft plan's exact shape is now rejected. Reverting only the
concurrency group to
deploy-backend-stack-${{ github.event.inputs.environment }}whilekeeping the
pushtrigger:Three independent assertions catch it; the pre-change checker caught none of them.
What I could NOT verify — residual risk
This automation is not proven. Be honest about what is and is not established:
pushtrigger has never fired. It can only be exercised by a real merge tomainthat changesfirestore.indexes.json. Everything above is a static assertion onworkflow text plus hermetic unit tests. First real proof will be the next manifest PR.
github.event.inputs.environmentrenders empty onpush(the bug this design exists toavoid) is documented GitHub behaviour and matches the incident's observed
gcp_backend_listen_helm.ymlpattern, but I did not run a push event to observe it.waitinggcp_backend.ymlrun. I did not read the Environment settings. If prod doesnot require a reviewer, this change becomes auto-apply-to-prod rather than
auto-queue — please confirm before merging. That is the single assumption the safety
argument rests on.
Firestore index was created or deleted by this work; prod is already reconciled.
tested against synthetic inventories. The two indexes hand-created during the incident
should appear on the next deploy's readiness step; that is the observation to check.
dev auto-deploy can still be blocked on a missing index until someone dispatches the
reconcile for
development. It fails loudly rather than silently, but it is real toiland a deliberate scope cut.
gcp_backend_listen_helm.yml's shared automatic lock is documented, not fixed.waitingrun still holds a lock with no alert. Within the schema lane the nextpush supersedes it; across lanes the domains are now separate. But nothing pages anyone
about a run parked in
waiting— the general observability gap the incident exposed isnarrowed, not closed.
Refs #11684. Follow-up to #11731.