Skip to content

fix(backend): declare opposite-direction Firestore list-scan indexes + converge cascade-retract CAS (#11684, #11726) - #11731

Merged
Git-on-my-level merged 3 commits into
mainfrom
sca-316-scan-index-cas-fix
Aug 18, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
sca-316-scan-index-cas-fix

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

What changed and why

Two production 5xx classes from the 2026-08-17 incident window (watchdog 75afe342f6f8, serving SHA 6316415 = merged #11627), fixed in two independent commits:

  1. Missing opposite-direction Firestore list-scan indexes → 503 (GET /v3/memories 503s in prod: the canonical scan orders updated_at DESC + __name__ ASC, an index Firestore never builds automatically and the registry never declares #11684). Serving queries order updated_at DESC, __name__ ASC (read_canonical_scan_page, plus the historical dual-stream scans and the review-queue status scan). Firestore automatic single-field indexes only cover field+__name__ in the same direction, so these need real composites — but _query_spec_index_requirements() dropped every spec with ≤1 non-__name__ field. Prod answered FailedPrecondition: The query requires an index, mapped to 503 Canonical memory unavailable / Historical memory unavailable on GET /v3/memories and the cascade-delete skip-guard scan. Fix: the predicate now declares exactly the opposite-direction pairs and regenerates the manifest with the four missing indexes (memory_items updated_at DESC+__name__ ASC; memories updated_at DESC+__name__ ASC; memories created_at DESC+__name__ ASC; memory_review_queue status ASC+__name__ DESC). Same-direction singles and array-contains pairs stay out (deploy rejects those as redundant).

  2. Cascade-retract CAS exhaustion → 500 (Concurrent cascade conversation deletes 500: same-uid retract races the canonical memory-control CAS #11726). Concurrent same-uid canonical writes all bump the one account-global memory_state/apply_control document. replace_conversation_sourced_memories' three immediate CAS attempts exhausted under that contention and raised an unhandled RuntimeError → DELETE /v1/conversations/{id}?cascade=true returned 500 while the Flutter client retried one conversation up to 12× and kept the storm fed. A repeat delete whose committed receipt went stale (another conversation's replacement advanced source_generation) livelocked on source replacement operation already exists the same way. Fix on the retract entry only (cascade delete + merge; the extraction replace path keeps its existing contract): bounded backoff retry (5 rounds, 0.05→0.5s), and after each conflict an epoch-guarded empty-cohort check — the same double-read control fence the replacement loop uses — returns the committed-empty result when a peer already retracted the source. Exhaustion raises typed ConversationReplacementConflictError (a RuntimeError subclass, so existing callers are unchanged), which delete_conversation maps to a retryable 503 before anything is deleted: the fix(backend): unbreak conversation merge and cascade delete behind the canonical fence #11627 never-orphan-live-memories fence holds, and a retried delete is idempotent (receipt replay / already-retracted short-circuit).

Closes #11684
Closes #11726

Relationship to open work

Merge sequencing (required)

firestore_readiness runs reconcile_firestore_indexes.py --check-only on backend deploys and fails closed until every manifest index is READY. Merge only after a human runs Reconcile Firestore Indexes → prod → APPLY_FIRESTORE_INDEXES (dev first is fine) — that APPLY alone stops the 503s even before this PR merges. Split-merging (declaration after APPLY lands separately) is a later human decision; nobody should run APPLY from this PR.

How it was verified

  • pytest tests/unit/test_firestore_index_config.py tests/unit/test_firestore_indexes.py tests/unit/test_reconcile_firestore_indexes.py tests/unit/test_firestore_query_contract.py → 62 passed (was 61 on the wrong predicate; the renamed same-direction test no longer codifies the bug and the new opposite-direction declaration test pins all four indexes).
  • python3 backend/scripts/generate_firestore_indexes.py --write then read-mode → firestore.indexes.json matches the Firestore index registry; diff adds exactly the 4 entries (+56 lines, same shape as fix(backend): declare opposite-direction Firestore list-scan indexes (#11684) #11687).
  • python3 backend/scripts/firestore_query_coverage.py --check-ratchet → exit 0 (coverage keys on query signatures; QUERY_SPECS unchanged → no baseline drift).
  • pytest tests/unit/test_cascade_retract_convergence.py tests/unit/test_delete_conversation_cascade_retraction_fence.py → 7 passed: injected ConversationSourceReplacementConflict rounds converge with bounded backoff; repeat retract with a stale receipt returns already-retracted instead of livelocking; exhausted conflicts with live items still raise (conversation + memories intact, fix(backend): unbreak conversation merge and cascade delete behind the canonical fence #11627 fence); route maps the typed conflict to 503 before any delete.
  • Affected memory suites: pytest tests/unit/test_ws_i_hardening.py tests/unit/test_ws_j_delete_privacy.py tests/unit/test_memory_apply_store.py tests/unit/test_memory_replace_policy.py tests/unit/test_merge_conversations_canonical_delete.py tests/unit/test_merge_skips_retraction_without_canonical_memories.py tests/unit/test_universal_memory_service.py tests/unit/test_atomicity_lifecycle_regressions.py → 173 passed.
  • Scan-read/fake-contract: pytest tests/unit/test_bounded_firestore_list_reads.py tests/unit/test_firestore_fake_contract.py → 12 passed.
  • scripts/pr-preflight --suggest → INV-MEM-1 required; failure-class protocol honored below.

Not verified here: live Firestore behavior (no APPLY, no prod/dev writes — the four indexes must be provisioned by a human via the workflow above).

Tests

  • Index half regression: backend/tests/unit/test_firestore_index_config.py::test_firestore_config_declares_opposite_direction_universal_list_scans (fails on main's manifest) and the renamed same-direction test (fails if the predicate over-declares).
  • CAS half regression: backend/tests/unit/test_cascade_retract_convergence.py (three behavioral tests: convergence under injected conflicts, stale-receipt idempotency, fail-closed exhaustion) + test_delete_conversation_cascade_retraction_fence.py::test_exhausted_replacement_conflict_maps_to_retryable_503_before_any_delete.

Product invariants affected

INV-MEM-1

Failure class (fixes)

Failure-Class: FC-undeclared-serving-query-index

(That class covers the index half exactly — a serving query's composite index missing from the registry manifest. The CAS half has no existing class in the registry; it is a candidate for a new class — "account-global CAS exhaustion surfaced as an unhandled 500 on a retryable, idempotent operation" — to be registered separately per the transition-narrative protocol, not inline in this fix PR.)

Line-Count-Exception: backend/routers/conversations.py | 1515 -> 1527 | retryable-503 mapping for the cascade-retract conflict (#11726) is a few lines inside the existing delete route; splitting the router is out of scope for an incident fix
Line-Count-Exception: backend/utils/memory/canonical_memory_adapter.py | 2388 -> 2491 | retract convergence loop + epoch-guarded completion check + typed conflict error live with the CAS loop they wrap (#11726); extraction into a new module would split the replace/retract boundary mid-incident

Residual risk

  • The 503-after-exhaustion path is still a 5xx by design — but only after 5 backoff rounds and a proven-non-empty source, with nothing deleted and a safe client retry; the incident's unbounded 12×-retry 500 loop is gone (converges or fails closed).
  • The already-retracted short-circuit trusts the same double-read fence the replacement loop uses; it cannot skip a retract that still has live items (live items → keep retrying → raise).
  • Multi-instance Cloud Run: the backoff converges cross-instance via the control CAS itself; there is no cross-instance lock (deliberately — the smallest shape Concurrent cascade conversation deletes 500: same-uid retract races the canonical memory-control CAS #11726 sanctioned).

Review in cubic

@Git-on-my-level
Git-on-my-level force-pushed the sca-316-scan-index-cas-fix branch from c501d33 to 4685b0c Compare August 17, 2026 09:16
Git-on-my-level and others added 3 commits August 17, 2026 17:40
…11684)

The registry dropped every single-field+__name__ spec from the composite
manifest, but Firestore automatic indexes only cover field+__name__ in the
same direction. updated_at DESC + __name__ ASC (and status ASC +
__name__ DESC) are real composites; prod FailedPrecondition 400 'The query
requires an index' surfaced as 503 Canonical memory unavailable.

Narrow the predicate: opposite-direction __name__ tie-breaks are declared;
same-direction singles and array-contains pairs stay out. Regenerates
firestore.indexes.json with the four missing indexes (memory_items
updated_at, memories updated_at/created_at, memory_review_queue status).

Absorbs and supersedes #11687 (conflicting against current main; predicate
re-expressed on the refactored _query_spec_index_requirements()).

Merge only after the four indexes are APPLYed in prod via
'Reconcile Firestore Indexes' — firestore_readiness --check-only fails
closed until they are READY.

Co-authored-by: multica-agent <[email protected]>
…#11726)

Concurrent same-uid canonical writes — parallel cascade deletes,
extractions, merges — all bump the one account-global
memory_state/apply_control document. The three immediate attempts in
replace_conversation_sourced_memories exhausted under that contention and
raised an unhandled RuntimeError, so DELETE
/v1/conversations/{id}?cascade=true returned 500 while the Flutter client
retried one conversation up to 12x and kept the storm fed. A repeat delete
whose committed receipt went stale after another conversation's
replacement advanced source_generation livelocked on 'source replacement
operation already exists' the same way.

Retraction now converges on the retract entry (cascade delete + merge
path only; extraction keeps its existing contract):

- each conflict round re-checks, under the same double-read control fence
  the replacement loop uses, whether the source is already empty — a peer
  worker's committed retraction or a stale repeat receipt returns the
  committed-empty result instead of fighting the CAS;
- bounded backoff (0.05→0.5s, five rounds) between retries;
- exhaustion raises typed ConversationReplacementConflictError (a
  RuntimeError subclass, so existing callers are unchanged), which
  delete_conversation maps to a retryable 503 — nothing has been deleted
  at that point, so the #11627 never-orphan-live-memories fence holds and
  a retried delete is idempotent.

Behavioral tests: injected control-change conflicts converge; repeat
retract with a stale receipt returns already-retracted; exhausted
conflicts with live items fail closed with the conversation intact;
route maps the typed conflict to 503 before any delete.

Co-authored-by: multica-agent <[email protected]>
…conflict import

The #11726 commit replaced the retraction_scope import with the new
canonical_memory_adapter import, but delete_conversation still calls
retraction_can_be_skipped — every cascade delete would have raised
NameError → 500, the same class this PR fixes.

- routers/conversations.py: restore
  'from utils.memory.retraction_scope import retraction_can_be_skipped'
  alongside the new import.
- The three fresh-router-loader suites
  (test_conversation_events_bounds, test_conversations_date_range_validation,
  test_conversation_search_date_validation) stub utils.memory as a fake
  package, so the router's new canonical_memory_adapter import needs a
  registered stub exposing ConversationReplacementConflictError as a real
  RuntimeError subclass. This was the CI 'Backend unit suite' failure.

Verification (BACKEND_UNIT_TEST_FILE_LIST through backend/test.sh):
- The three failing files: 39 passed (was ModuleNotFoundError).
- test_cascade_retract_convergence + fence tests: 7 passed.
- test_calendar_autolink + topic_route fresh loaders: 4 passed.
@Git-on-my-level
Git-on-my-level force-pushed the sca-316-scan-index-cas-fix branch from 4685b0c to 5d11789 Compare August 17, 2026 10:47
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor run summary (2026-08-17):

  • Hygiene / product-file-line-count-ratchet failure resolved. The PR body declared backend/routers/conversations.py | 1515 -> 1526, but the third commit ("restore dropped retraction-scope import") took the file to 1527, leaving the declaration stale. Updated the Line-Count-Exception to the actual 1515 -> 1527 (reason unchanged). Verified locally against the ratchet script with the synthetic merge before editing: old body reproduced the exact CI failure; corrected body passes. The canonical_memory_adapter.py | 2388 -> 2491 declaration was already accurate.
  • Rebased branch pushed. The monitor-rebased branch (3 PR commits re-applied onto current origin/main @ 81bcd25c, patch-ids verified identical) was force-pushed to sca-316-scan-index-cas-fix (4685b0c → 5d11789). No code changes.
  • CI on the new head: 26 pass / 13 skip / 0 fail, including the previously failing Hygiene check. No review threads open.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incident fix for both #11684 (opposite-direction list-scan indexes) and #11726 (cascade-retract CAS convergence), well covered by tests; merge is gated on a human running Reconcile Firestore Indexes -> prod APPLY first

@Git-on-my-level
Git-on-my-level merged commit 33cf19d into main Aug 18, 2026
43 checks passed
@Git-on-my-level
Git-on-my-level deleted the sca-316-scan-index-cas-fix branch August 18, 2026 01:10
Git-on-my-level added a commit that referenced this pull request Aug 18, 2026
…dy approved (#11794)

## 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 #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.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/11794?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
pull Bot pushed a commit to codingwatching/omi that referenced this pull request Aug 18, 2026
…ing to

`gcp_firestore_indexes.yml` was `workflow_dispatch:` only, so nothing applied a
merged manifest. BasedHardware#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants