Repository navigation
Description
GET /v3/memories has been answering 503 "Canonical memory unavailable" in prod since the canonical scan shipped on 2026-08-12 (efba1a0, "fix: finish combined proactive QA hardening"). The canonical list scan asks Firestore for an index that has never been declared, so every page-1 read fails at query planning.
Evidence (prod, based-hardware)
gcloud logging read severity>=ERROR over the last 24h: 915 of a 1000-record sample are this one traceback.
File "/app/utils/memory/memory_service.py", line 1105, in _ensure_slots
raw_slots, stream_exhausted = read_canonical_scan_page(
File "/app/utils/memory/canonical_memory_adapter.py", line 623, in read_canonical_scan_page
snapshots = list(query.limit(bounded_limit).stream())
google.api_core.exceptions.FailedPrecondition: 400 The query requires an index.
The remediation link in that error decodes to exactly:
memory_items COLLECTION — updated_at DESCENDING, __name__ ASCENDING.
memory_service.py:1116 maps that exception to HTTPException(503, "Canonical memory unavailable"), so users of GET /v3/memories (routers/memories.py:513) get a 503, not a degraded list.
Root cause
read_canonical_scan_page orders updated_at DESC, __name__ ASC (canonical_memory_adapter.py:612). That tie-break direction is deliberate and correct — MemoryService.keyset_sort_key is (-updated_at_us, memory_id) (memory_service.py:1597), so the whole service's public order is updated_at DESC with ascending document id. The emitted-keyset monotonicity filter (memory_service.py:1153) and the canonical/historical merge (:1725) both depend on the Firestore scan matching that order. Flipping __name__ to DESC would be the wrong fix.
The index is missing because the registry believes Firestore provides it automatically:
# backend/database/firestore_index_registry.py:332
# Firestore manages the single-field updated_at index (plus automatic __name__
# tie-break) itself — this spec records the serving query contract only.Firestore's automatic single-field indexes serve field ASC, __name__ ASC and field DESC, __name__ DESC only. field DESC, __name__ ASC is a different index that is never built automatically. INDEX_REQUIREMENTS (:600) drops any spec with one non-__name__ field from the manifest, so four specs silently never reach firestore.indexes.json:
| spec | index | live in prod? |
|---|---|---|
memory_items_universal_list_scan |
memory_items updated_at DESC, __name__ ASC |
missing — this outage |
memories_universal_list_scan_updated_at |
memories updated_at DESC, __name__ ASC |
missing |
memories_universal_list_scan_created_at |
memories created_at DESC, __name__ ASC |
missing |
memory_review_queue_by_status_id |
memory_review_queue status ASC, __name__ DESC |
missing |
Verified against gcloud firestore indexes composite list --project based-hardware (89 indexes): none of the four exist.
test_firestore_index_config.py:30 encodes the same wrong assumption ("rejected at deploy time as redundant"), which is why no test caught it.
The assumption is wrong — measured, not argued
I created the exact index in based-hardware-dev and Firestore accepted it (it is not rejected as redundant), then A/B'd the real serving query:
# index CREATING
FAILED_PRECONDITION based-hardware-dev: 400 ... That index is currently building and cannot be used yet
# index READY
OK based-hardware-dev: query planned and ran
# prod control, index still absent
FAILED_PRECONDITION based-hardware: 400 The query requires an index.
Firestore itself matched my created index to the query — confirming both the shape and that it is not automatic.
Fix
Narrow the manifest predicate to what Firestore actually rejects: a single ordered field is automatic only when __name__ tie-breaks in the same direction. Patch (registry + regenerated firestore.indexes.json + the two tests), 4 files / +122 / -13, is ready and green:
backend/tests/unit/test_firestore_indexes.py,test_firestore_index_config.py,test_reconcile_firestore_indexes.py— 34 passedbackend/tests/unit/test_firestore_query_contract.py— 26 passedbackend/scripts/generate_firestore_indexes.pyverify — clean; adds exactly the 4 indexes above, removes none
Why this is not a drive-by PR — sequencing needs a human
firestore_readiness runs reconcile_firestore_indexes.py --check-only in both gcp_backend.yml and gcp_backend_auto_dev.yml. Merging the manifest change before the indexes exist blocks backend deploys (prod and auto-dev) until the create-only migration runs. The correct order is:
- Apply the four indexes (
Reconcile Firestore Indexes→prod→APPLY_FIRESTORE_INDEXES). This alone stops the 503s — the serving code needs no change. - Then merge the registry/manifest patch so the declaration matches the deployed schema and the regression tests hold.
That workflow is workflow_dispatch with an explicit confirmation string and the prod environment requires reviewers — deliberately a human-approved writer — and AGENTS.md puts schema migrations in the explicit-sign-off bucket. So this is filed rather than pushed.
Follow-ups
validate_account_deletion_dispatch_configuration-style gap: nothing asserts a declared serving query is actually servable. A startup or readiness probe that plans eachQUERY_SPECSentry once would have caught this on the deploy that shipped it.- Separate live error, same subsystem, 29 occurrences/24h:
ValueError: canonical memory extraction returned evidence without a unique source binding(process_conversation.py:918) escaping_run_enrichment.
🤖 filed by the hourly desktop bug watchdog
Activity
aryanorastar commentedon Aug 16, 2026
Opened #11687 with the registry predicate fix + regenerated
firestore.indexes.json+ regression tests (61 unit passed locally).Per the sequencing in this issue: APPLY the four indexes in prod before merging the PR, otherwise backend deploy readiness fails closed. Happy to adjust the PR if APPLY needs a different shape.
Git-on-my-level commentedon Aug 17, 2026
Additional customer path from the 2026-08-17 prod 5xx surge
Read-only prod check on
based-hardware, Cloud Runbackendrevisionbackend-memon0815/ commit6316415534fffc4636efdab224a49a3638cf046f(100% traffic).The 03:12–03:28Z watchdog tick (342 backend HTTP ≥500s) was mostly
DELETE /v1/conversations/{id}?cascade=true→ 503 from Dart/Flutter (268 of 345 sampled 5xxs; prior tick 02:56–03:12 had 303 DELETE 503s). SameFailedPrecondition: query requires an indexonmemory_itemsupdated_at DESC+__name__ ASCviaread_canonical_scan_page/_ensure_slots.On this serving SHA, cascade delete calls
retraction_can_be_skipped→source_retraction_is_a_noop, which caniter_all_livethe historical/canonical scan when deciding whether retract is a no-op. That is the same opposite-direction__name__scan class this issue already describes forGET /v3/memories. Endpoint difference does not change the repair: APPLY the four indexes still stops these 503s.Not claiming this issue owns the concurrent retract 500s in the same window (
RuntimeError: canonical conversation replacement conflicted repeatedly). Those are a separate CAS/idempotency class and will be filed separately.No uid / conversation ids / payloads retained.
Git-on-my-level commentedon Aug 17, 2026
Follow-up for the same window's DELETE 500 CAS/retract class (not this index): #11726
fix(backend): declare opposite-direction Firestore list-scan indexes (#…
fix(backend): declare opposite-direction Firestore list-scan indexes (#…
kodjima33 commentedon Aug 17, 2026
Ops remediation applied — the outage is over, the registry gap is not.
The missing serving index was created directly in prod at 2026-08-17T21:39Z and reached
READYat 21:44:07Z:Exactly the shape this issue decoded from the remediation link, and Firestore accepted it (not rejected as redundant), confirming the "automatic single-field index covers it" assumption in
firestore_index_registry.py:332is wrong.Live effect,
severity>=ERRORonbased-hardware:The query requires an indexGET /v3/memoriesstopped 503ing. The three other specs in the table above (memoriesupdated_at DESC,memoriescreated_at DESC,memory_review_queuestatus ASC/__name__DESC) produced no prod errors in the last 10h, so I left them alone.Still needed: this index now exists only as a hand-created live index and is absent from
firestore.indexes.json, which is theFC-undeclared-serving-query-indexfailure class itself. The registry fix (_query_spec_index_requirementsdropping specs with one non-__name__field) is open in #11687 and #11731 — one of those still has to land, or the next environment rebuilt from the manifest breaks the same way.🤖 hourly desktop bug watchdog
fix(backend): declare opposite-direction Firestore list-scan indexes …
Merge upstream/main (+92) — clean auto-merge + 1 conflict resolved on…
ci(firestore): auto-queue the index migration a merged manifest alrea…
SCA-374: degrade memories first-page 503s by type, not detail string (#…