CLUE-588: reconcile firestore.indexes.json with deployed production indexes - #2931
Conversation
…ndexes The committed indexes had drifted from what is deployed to the production Firestore project. Add back the indexes/field-override that exist in production but were missing from the file: the `documents` index, the `summaries` index (numAiAgreements + vector 1536), and the `comments/uid` CONTAINS field override. The `messages` index remains, so the file is now a superset of production and deploying it only creates `messages`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## master #2931 +/- ##
===========================================
- Coverage 85.86% 69.30% -16.56%
===========================================
Files 957 952 -5
Lines 54527 54503 -24
Branches 14357 14355 -2
===========================================
- Hits 46822 37776 -9046
- Misses 7687 16693 +9006
- Partials 18 34 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
collaborative-learning
|
||||||||||||||||||||||||||||
| Project |
collaborative-learning
|
| Branch Review |
CLUE-588-firestore-indexes
|
| Run status |
|
| Run duration | 03m 38s |
| Commit |
|
| Committer | Scott Cytacki |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
4
|
| View all changes introduced in this branch ↗︎ | |
|
This has been deployed to production already. It was necessary to get the messages index on production as part of the 7.3.0 release. This associated JIRA story is tagged for 7.4.0 because that is the tag that will contain these updated rules. |
dougmartin
left a comment
There was a problem hiding this comment.
Looks good 👍
The JSON is valid and schema-conformant, and both new queryScope: COLLECTION values are right: documents is a subcollection under {appMode}/{rootId}/documents accessed only via .collection(path) (never collectionGroup), and summaries is a genuine root-level collection (functions-v2/src/on-document-summarized.ts:101). Making the file a superset of production is strictly safer than the pre-PR state, and since it's already deployed there's nothing to un-do.
A few non-blocking notes (take or leave):
-
firestore.indexes.json(lines 17-30): thedocuments(unit, type) index has no supporting query in the repo, and wouldn't need a composite even if it did. The onlyunitfilters areshared/update-class-data-docs.ts:56-64(unit ==+context_id ==) andsrc/models/stores/sorted-documents.ts:124(unit in [...]); the onlytypefilter isscripts/find-documents-missing-metadata.ts:128(type not-in [...]). A two-equality query is served by single-field indexes via zigzag merge, so a composite only helps forwhere unit == X orderBy typeor a range ontype, neither of which exists. Since it'sCOLLECTION-scoped it's maintained for everydocumentssubcollection acrossauthed/*,demo/*,dev/*,qa/*,test/*. If the ad hoc investigation that prompted it is done, consider a follow-up to drop it from the file and from production; if it's meant to stay as a permanent analysis index, worth saying so somewhere durable so the next reconciliation doesn't delete it. -
firestore.indexes.json(lines 45-81): thesummariesvector index has no reader anywhere in the repo.functions-v2/src/on-document-summarized.tsis the only file that touchessummaries, and it does point reads/writes on a known doc id; there is no.collection("summaries")query and nofindNearestcall anywhere (FieldValue.vectorat line 112 is a write). AvectorConfigindex can only servefindNearest, so it's dead as far as this repo is concerned. The prefix set also looks off for a nearest-neighbor query, since Firestore requires equality on all prefix fields and this one includeskey(filtering to a single document, which defeats similarity search) andnumAiAgreements(an exact count). Worth confirming with whoever owns AI summaries what consumer this serves (likely an out-of-repo notebook or a console experiment) and recording that, rather than leaving "I'm pretty sure these are for the AI summary support" as the only justification. -
firestore.indexes.json(whole file),.firebaserc: this is now a superset of production but a subset of staging, andfirebase.jsonpoints both projects at this single file, so the failure mode this PR fixes for production is now the live state for staging. The next person deploying indexes to staging gets prompted to delete the experimental vector indexes you mention in the Notes. Either add the staging-only entries here too, or state explicitly in a repo doc that staging holds untracked experiments and index deploys there need index-by-index review. Related:.firebaserchas nodefaultalias, so a barefirebase deploy --only firestore:indexestargets whateverfirebase uselast selected. -
firestore.indexes.json(line 90): the stated rationale for thecomments/uidCONTAINS entry looks incorrect. The list-of-authors query isscripts/export-comment-tags.ts:514(collectionGroup("comments").where("uid", "in", uidBatch)), and Firestore runsinon a scalar field as a disjunction of equality lookups served by the ASCENDING COLLECTION_GROUP index already on line 91.uidis scalar (src/lib/firestore-schema.ts:42), every writer assigns a single string, andfirestore.rules:56-58enforcesstring(request.auth.token.platform_user_id) == request.resource.data.uid, which an array can never satisfy. There's noarray-containsonuidanywhere. The entry itself is correct and free: it restores Firestore's automatic array index that the CLUE-549 field override (af59f2ea) had inadvertently disabled by enumerating only three of the four default single-field indexes. Just worth fixing the description so a future reconciliation doesn't concludeuidis sometimes an array. -
package.json(lines 93-94),README.md(lines 82-95): there's nodeploy:firestore:indexesscript, which is why this used a rawfirebase deploy. Suggest adding"deploy:firestore:indexes": "firebase deploy --only firestore:indexes". Separately,README.md:92referencesnpm run deploy:firebase:rules, which doesn't exist (the real script isdeploy:database:rules). Nothing in.github/workflows/reads or validates this file, andgit logshows only 4 commits ever against it versus 20+ forfirestore.rules, so it's only touched when someone hits a missing-index error, which is how the drift accrued. A release-checklist step (or CI job) that diffsfirebase firestore:indexes --project productionagainst the committed file would catch the next one. -
firestore.indexes.json(lines 17-30, 45-81, 90): JSON allows no comments, so once this merges the reasoning for the back-filled entries lives only in the PR body, and two of the three are hedged ("I'm pretty sure", "I think this might have been"). A short "Firestore indexes" section indocs/firestore-schema.mdlisting each index, the query or script that needs it, and an owner for the ones with no in-repo reader would give the next reconciliation something better than "safe answer is keep it". -
firestore.indexes.json(lines 3-16, unchanged): while you're reconciling, the pre-existingdocsCOLLECTION_GROUP index appears orphaned. There's nocollection("docs")orcollectionGroup("docs")anywhere insrc/,functions-v1/src/,functions-v2/src/,scripts/, orshared/, andfirestore.ruleshas nomatchfordocsat all, so clients hit the catch-all deny. Looks like a legacy name superseded bydocuments. Out of scope to remove here (it would trigger a production delete), but worth confirming and filing a follow-up.
|
It is interesting that your AI thinks that the "the summaries vector index has no reader anywhere in the repo". My Claude found a reader via I'm going to just merge this as is. I agree with most of the points, but it was just a clean up after a CLUE release. I don't have the time to do more. |
Summary
The repo's
firestore.indexes.jsonhad drifted from what is actually deployed to the production Firestore project (collaborative-learning-ec215). Several indexes/field-overrides existed in production but were missing from the file, so deploying the file as-is would have attempted to delete live production indexes (including thesummariesvector index).This makes the file a superset of production: everything production has, plus the
messagesindex that was added tofirestore.indexes.jsonas part of an earlier PR. We needed to deploy thismessagesindex to production, so we made this superset to do so.This
firestore.indexes.jsonhas already been deployed to production as part of 7.3.0 release.Changes
Adds back the three production-only entries that were missing from the file:
documentsindex (unit, type): I added this so I could track down which types have units and which types don't.summariesindex (context_id, investigation, problem, unit, key, numAiAgreements +summaryEmbeddingvector 1536) : I'm pretty sure these are for the AI summary support.arrayConfig: CONTAINSentry on thecomments/uidfield override : I think this might have been added to support the comment tags report. I think this allows finding all comments by list of authors.The existing
docsandmessagesindexes are unchanged.Deploy process
Notes
There are more indexes on staging. We did not include them here. They seem to be experimental. There are a
summariesvector-only (1536 / 2048) indexes.🤖 Generated with Claude Code