Repository navigation
perf(firestore): narrow finalization candidate queries behind WQ13 lever - #23614
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c3c724afa3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| FINALIZATION_STALE_IN_PROGRESS_QUERY.build( | ||
| client.collection_group(CONVERSATIONS_COLLECTION), | ||
| {'status': 'in_progress', 'finished_before': finished_before}, | ||
| field_filter_factory=FieldFilter, | ||
| ) | ||
| .order_by('finished_at') |
There was a problem hiding this comment.
Preserve the admission clock when narrowing recovery candidates
When finjob_candidate_queries is enabled for the optional self-heal sweep, this filter can exclude conversations that the existing admission predicate accepts. recovery_admission_refusal() uses lifecycle_clocks.speech_clock(), which selects last_speech_at for the lifecycle-v2 serving cohort and parses legacy timestamp representations; it does not simply compare the stored finished_at. For example, a conversation with speech three hours ago but a finished_at refreshed by a later empty heartbeat was recoverable through the status-only sweep and now disappears from its candidate window. Preserve a discovery path for rows admitted by the effective speech clock rather than assuming this timestamp predicate is equivalent.
Useful? React with 👍 / 👎.
…hort can exist Round-2 review finding (exec-worry-wrap-differ-dirt-fault-wolf): upstream e756385 clocks recovery admission by speech_clock (last_speech_at or finished_at) for v2-serving uids, and v2 serving suppresses legacy finished_at writes, so a raw finished_at pushdown would drop rows whose staleness lives only in last_speech_at. This status-only scan is their only finished_at-agnostic catch-all, so the candidate shape is now withheld whenever cohort_configured(LIFECYCLE_V2_MODE) is true (serve mode or a configured shadow cohort). Dormant shadow (documented default) and off keep the pushdown: shadow_or_serve would be permanently true under the default shadow and render the lever inert. Tests: pushdown withheld under serve/shadow-cohort-percent/shadow-cohort- digests; active under off and dormant shadow. Targeted shard 509 passed (test_finjob_candidate_queries, test_selfheal_sweep, test_firestore_query_shapes, test_firestore_index_oracle, test_firestore_indexes, test_reconcile_firestore_indexes, test_selfheal_recovery).
…st_index_window to 100 (#23646) ## Summary Firestore reads loop config: enable the WQ13 `finjob_candidate_queries` lever at 5% and graduate `memory_list_index_window` 25 → 100 in one literal (18 keys, generated with `avo/firestore-reads/set_levers.py`, REPLACE-mode, byte-identical at all declaration sites). - `finjob_candidate_queries`: 0 → 5. The WQ13 rework (#23614, 91ac171) replaces the `conversation_finalization_jobs` per-tick full-collection candidate re-scans with predicate-equivalent narrow queries behind this default-off lever. The code is serving everywhere since tonight's trains (Cloud Run 528f97f 23:17Z, listen 86a15ac 22:30Z, pusher fca00e4 00:24Z; all contain 91ac171) and all three composite indexes it needs are READY live (CICAgJiVqpoK, CICAgJjH44cK, CICAgPjgiJoK). Why now: the three finjob candidate scans are the top Firestore read caller — ~61M reads/h fleet-wide in the 22–23Z hour (snapshot 2026-10-26T00-40Z.json; 29.0M/h already at 17–18Z pre-serve), concentrated on backend-sync and backend-sync-backfill. `queue_age_sample_budget` and `singleton_loops` at 100 since 23:17Z did not collapse them; the re-scan amplifier is the code path this lever narrows. - `memory_list_index_window`: 25 → 100. verify SUPPORTED at 25 since 2026-10-18 (no FALSIFIED/UNSAFE tick); graduation follows the loop runbook ramp5 rule and the c2fs ranked plan (item 5, bundle with the WQ13 enable). Config only; no code paths change. Off-path for both levers is the current served behavior (`finjob_candidate_queries` 0 = byte-identical scans; 25 was already SUPPORTED). ## Product invariants affected - INV-MEM-4 — config-only rollout of default-off code-path levers; every lever reverts at 0 with no data-path or authority change. - INV-DATA-1 — value-only edit of the existing `FIRESTORE_READ_LEVERS` key; no routing or ownership change. ## Test plan - `backend/tests/unit/test_render_backend_runtime_env.py` + `backend/tests/unit/test_verify_pusher_config_references.py` via `backend/test.sh` with `BACKEND_UNIT_TEST_FILE_LIST` (local shard green on this branch before push). - Literal verified byte-identical at all declaration sites; regenerated `runtime_env.yaml`, flag registry, and both pinned contract tests. - Post-merge watch: verify.py per-lever gates + backend-sync/backend-sync-backfill 5xx rates hourly; any UNSAFE/FALSIFIED lever flags off via config PR. ## Rollout 1. Train order **listen → pusher → Cloud Run** (FIRESTORE_READ_LEVERS order; the Cloud Run candidate check compares GKE env against main's runtime_env). Handoff to the two-lane lead via bus after merge; the ramp5 clock starts at the served revision carrying this literal. 2. `finjob_candidate_queries` follows the 5 → 25 → 100 ladder with soaks between steps (3h soak + verify PASS ×2 per runbook); ramp5 gates decide each step. memory_list_index_window rides the same literal at 100. 3. D+2 absolute readout per lever vs a fresh post-serve baseline; 0 for any FALSIFIED/UNSAFE lever.
…st_index_window to 100 Firestore reads loop config PR (18-key FIRESTORE_READ_LEVERS literal, generated with avo/firestore-reads/set_levers.py, REPLACE-mode, byte-identical at all declaration sites): - finjob_candidate_queries 0 -> 5: first enable of the WQ13 rework from BasedHardware#23614. Code serves on all services (Cloud Run 528f97f 23:17Z, listen 86a15ac, pusher fca00e4); the three composite indexes are READY (CICAgJiVqpoK, CICAgJjH44cK, CICAgPjgiJoK). Pre-enable evidence: finjob candidate scans ~61M reads/h fleet-wide at 22-23Z (snapshot 2026-10-26T00-40Z.json), the top Firestore read caller; queue_age_sample_budget and singleton_loops at 100 since 23:17Z did not collapse them. - memory_list_index_window 25 -> 100: verify SUPPORTED at 25 since 2026-10-18; graduation per runbook ramp5 rule and the c2fs ranked plan (bundle with the WQ13 enable). Config only; off-path is the current served behavior for both levers.
Summary
Firestore reads loop WQ13: rework the
conversation_finalization_jobsreconcile candidate queries, which re-scannedusers/conversationson every job tick. Predicate-equivalent rewrites replace the full candidate scans (inequality/staleness pushdown) so each tick reads only candidate pages instead of re-collecting the collection.Product invariants affected
Line-count exception
Line-Count-Exception: backend/database/conversation_finalization_jobs.py | 2976 -> 3040 | WQ13 adds lever-gated candidate filters while preserving main's content-due scan and admission fences; the gate withholds the pushdown while a lifecycle-v2 serve cohort can exist.
Line-Count-Exception: backend/database/firestore_index_registry.py | 2210 -> 2247 | Registers the three WQ13 candidate-query composite index shapes, including the conversations collection-group index.
Test plan
omi_firestore_billed_reads_by_caller_totalbefore/after any enable; lever stays 0 until measured.Rollout