Skip to content

ci(firestore): auto-queue the index migration a merged manifest already approved - #11794

Merged
Git-on-my-level merged 2 commits into
mainfrom
ci/firestore-index-reconcile-automation
Aug 18, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
ci/firestore-index-reconcile-automation

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Problem

GET /v3/memories returned 503 for every user on every platform for ~5 hours on
2026-08-18 (1,498 × 503, zero 200s in a 6h window; 355 distinct client IPs in 2h). The
required memories composite index (updated_at DESC + __name__ ASC) did not exist in
prod.

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:

  1. Nothing applies a manifest. gcp_firestore_indexes.yml was workflow_dispatch:
    only — across every revision since ed434840d7; no trigger was ever removed. Its last
    run 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.
  2. The reconcile could not have run even if dispatched. It shared
    concurrency: deploy-backend-stack-${env} with gcp_backend.yml, and a
    gcp_backend.yml run had sat in waiting on an unactioned prod approval since Aug 16
    holding 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_readiness gate passed vacuously — is closed by #11731 and is not re-fixed
here.)

Critique of the draft plan — what I rejected

The draft was: add push on main filtered to firestore.indexes.json, run
--provision-missing, plus "something that stops a stale waiting run from
deadlocking the lane", justified by the workflow being create-only and already
serialising against deploys. Right instinct, three wrong mechanisms.

Rejected — push while keeping github.event.inputs.environment. On a push event
that expression evaluates to the empty string. The draft silently produces
environment: — no GitHub Environment binding at all, so the prod required-reviewer
approval is bypassed
— and group: deploy-backend-stack-, a third group that
serialises 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 credits
the lock with an ordering guarantee it does not provide.

  • The guarantee "a deploy whose code needs a new index must not land before the index is
    READY" is enforced by gcp_backend.yml:189 / gcp_backend_auto_dev.yml:246
    firestore_readiness (--check-only, fail-closed), not by the lock. The lock only
    prevents interleaving.
  • Interleaving is not a hazard, because reconciliation is monotone: --provision-missing
    only 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.
  • The shared lock is what turned a 5-minute fix into a 5-hour outage: schema repair was
    hostage to a deploy approval nobody had actioned. Coupling the repair path to the thing
    being repaired is the actual defect.
  • Making it automatic on the shared group is affirmatively dangerous. GitHub retains
    only one pending run per concurrency group, so an auto-triggered reconcile on
    deploy-backend-stack-development can evict the pending gcp_backend_auto_dev.yml run
    carrying an admitted Release Eligibility SHA — the hazard documented verbatim in
    validate_automatic_backend_stack_lifecycle's own docstring.

Rejected — a mechanism to unstick stale waiting runs. Every concrete version is
worse than the structural fix. There is no timeout for approval waits; auto-expiring
waiting runs means CI silently cancelling a production deploy someone deliberately
queued; 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:

  • Provision from gcp_backend.yml directly violates "deploy workflows remain read-only
    and can only gate on the serving schema", and is mechanically blocked by
    FIRESTORE_SCHEMA_WRITERS.
  • A scheduled reconcile is banned by AGENTS.md ("scheduled jobs with no blocking
    audience are dead checks"), and a schedule that writes prod schema unattended is worse
    than a push-triggered one.
  • Fail the deploy with a dispatchable proposal is already implemented and is what will
    now happen — but it is a gate, not a fix. It never creates the index.

Design

1. Auto-trigger, human-approve. push on main filtered to
firestore.indexes.json. Automatic runs resolve to prod; the prod GitHub Environment's
required 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_INDEXES confirmation, without weakening the manual path. A
push cannot 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 fails
closed.

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's resolve_environment learns to render this form, so
the 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_isolation policy that rejects any
Firestore schema writer whose group resolves into deploy-backend-stack-* or fails to
resolve 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 waiting reconcile 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-only and --dry-run now
emit a non-blocking ::warning:: per undeclared live index. Both deploy lanes already run
--check-only on every deploy, so this lands on an existing blocking step rather than
adding a lane, and the token list of those audited invocations is unchanged (--check-only
still satisfies is_readiness_check). Deletion stays a human action.

7. The guard that would have caught the draft.
validate_automatic_backend_stack_lifecycle now resolves interpolated concurrency
groups 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.yml has been
a 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 eviction
hazard 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_WRITERS with a comment, converting an invisible hazard into an
audited one.

A test was rewritten alongside the code it asserts — why

test_static_firestore_index_migration_is_manual_and_main_scoped pinned the workflow's
old shape by name: workflow_dispatch:-only,
group: deploy-backend-stack-${{ github.event.inputs.environment }}, and
environment: ${{ github.event.inputs.environment }}. Those three literals are exactly
what this PR changes, so it is renamed to
test_static_firestore_index_migration_is_approved_and_main_scoped and 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 on
non-workflow_dispatch events, which is why the new assertions forbid a bare
environment: ${{ github.event.inputs.environment }} rather than requiring it — the same
rendering that gcp_backend_listen_helm.yml already relies on with its
|| 'development' default.

Every assertion whose intent survives the redesign is kept verbatim: main-scoped if:,
exact-github.sha checkout plus its verification, credentials_json binding,
plan-before-apply ordering, exactly one --dry-run and one --provision-missing, no
--check-only in the writer, --timeout-seconds 3600. Two assertions were added for
failure 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(...), not fix(...). This is CI/deploy-lane infrastructure — nothing in product or
backend runtime behaviour changes — so no Failure-Class: declaration is required, and
scripts/pr-preflight --suggest confirms: "No fix: commits were detected; no
declaration 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.py already
runs in .github/workflows/repo-checks.yml:146,149 and scripts/pre-push:796,797; the new
tests are in already-discovered backend unit files. No .github/checks-manifest.yaml entry
is needed because no new script exists.

Verification

$ python3 .github/scripts/check-deployment-concurrency.py --self-test
deployment concurrency policy self-test OK

$ python3 .github/scripts/check-deployment-concurrency.py
deployment concurrency policy OK (24 persistent writers, 1 run-scoped exemption)

$ python3 .github/scripts/check-desktop-backend-release-policy.py
desktop-backend release boundary policy OK

$ actionlint .github/workflows/gcp_firestore_indexes.yml
(clean)

$ backend/.venv/bin/python -m pytest tests/unit/test_reconcile_firestore_indexes.py \
      tests/unit/test_firestore_index_config.py -q
41 passed in 0.12s

Adversarial check — the draft plan's exact shape is now rejected. Reverting only the
concurrency group to deploy-backend-stack-${{ github.event.inputs.environment }} while
keeping the push trigger:

$ python3 .github/scripts/check-deployment-concurrency.py
FAIL: automatic development backend-stack deployment must be owned only by
      ['gcp_backend_auto_dev.yml', 'gcp_backend_listen_helm.yml'], found
      ['gcp_backend_auto_dev.yml', 'gcp_backend_listen_helm.yml', 'gcp_firestore_indexes.yml']
FAIL: gcp_firestore_indexes.yml: concurrency group must be "firestore-schema-${{ ... }}",
      got 'deploy-backend-stack-${{ github.event.inputs.environment }}'
FAIL: gcp_firestore_indexes.yml: Firestore schema reconciliation must not share the backend
      deploy lock (resolves to 'deploy-backend-stack-development' for development);
      a waiting deploy would block schema repair
FAIL: gcp_firestore_indexes.yml: Firestore schema reconciliation must not share the backend
      deploy lock (resolves to 'deploy-backend-stack-prod' for prod);
      a waiting deploy would block schema repair
exit=1

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:

  • The push trigger has never fired. It can only be exercised by a real merge to
    main that changes firestore.indexes.json. Everything above is a static assertion on
    workflow text plus hermetic unit tests. First real proof will be the next manifest PR.
  • The GitHub expression semantics are asserted, not executed. That
    github.event.inputs.environment renders empty on push (the bug this design exists to
    avoid) is documented GitHub behaviour and matches the incident's observed
    gcp_backend_listen_helm.yml pattern, but I did not run a push event to observe it.
  • The prod environment's reviewer configuration is inferred, from the incident's
    waiting gcp_backend.yml run. I did not read the Environment settings. If prod does
    not 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.
  • No Firestore index was created or deleted, and no index was inspected live. No
    Firestore index was created or deleted by this work; prod is already reconciled.
  • The drift warnings have not been seen against real prod inventory. They are unit
    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 remains manual. A manifest change now auto-queues prod but not development, so a
    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 toil
    and a deliberate scope cut.
  • gcp_backend_listen_helm.yml's shared automatic lock is documented, not fixed.
  • A waiting run still holds a lock with no alert. Within the schema lane the next
    push 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 is
    narrowed, not closed.

Refs #11684. Follow-up to #11731.

Review in cubic

Git-on-my-level and others added 2 commits August 18, 2026 01:34
…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]>
@Git-on-my-level
Git-on-my-level merged commit a9da3e0 into main Aug 18, 2026
44 checks passed
@Git-on-my-level
Git-on-my-level deleted the ci/firestore-index-reconcile-automation branch August 18, 2026 05:50
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