Repository navigation
sync: owner-generation fencing for people_scan_dedupe (lever stays 0) - #23733
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: 8d2fbb7acd
ℹ️ 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".
| # Capture BEFORE the scan, never after: a write during a fill | ||
| # must retire that fill on the next hit. Hits cost one lookup. | ||
| try: | ||
| people_generation = read_people_generation(db_client, uid) |
There was a problem hiding this comment.
Read the generation outside the memo lock
When people_scan_dedupe is enabled and a sync attempt is cancelled while an executor worker is performing this Firestore read, the worker retains memo.lock until the RPC completes. The async coordinator then exits people_scan_attempt(), whose synchronous finalizer acquires the same lock, blocking the entire event loop—including health checks and unrelated requests—for the remaining RPC/retry duration. Cancellation does not stop the running executor worker. A reproduction using the actual memo functions delayed a 10 ms event-loop timer by 400 ms until the simulated read completed. Move the network read outside the lock and revalidate the memo state after reacquiring it.
AGENTS.md reference: backend/AGENTS.md:L260-L262
Useful? React with 👍 / 👎.
Use getattr defaults for the optional collection/owner shape check so references lacking id or parent metadata take the non-People path. Real users/<uid>/people deletions still stage the generation bump atomically. Fix the fake-reference AttributeError affecting: - test_delete_conversation_cascade.py - test_conversation_smart_merge_flatten.py - test_dev_api_conversations_poison.py - test_batch_pipeline_runtime.py Validation: all five requested files, including test_firestore_read_levers.py, pass in separate pytest processes (171 tests); test_fsr_people_generation.py adds 13 passes. Real SDK reference checks preserve the People Increment(1). The combined command has four poison-suite Redis failures from shared-process import contamination, also reproduced with the origin/main delete helper.
… 5% (#23797) ## Summary Firestore read config train: disable `memory_list_index_window` (100→0) and `batch_privacy_memoize` (100→0), and start `people_scan_dedupe` at **5%** after writer fencing #23733. The prior read loop graded the first two levers flat/WEAK or FALSIFIED; turning them off is not a measured dollar saving. No source query, authority, transcription, speaker, price, Free benefit, or audio-retention behavior is changed here. Every declaration is a complete 19-key replacement JSON literal. `finjob_candidate_queries` stays at 5. All four production Cloud Run service overrides now carry the same three changes as listen/pusher; they previously masked them. ## Monthly-total enable/epoch split — explicit, no scope expansion | Surface | usage_month_total | FSR_USAGE_MONTH_TOTAL_EPOCH | | --- | --- | --- | | Prod backend, backend-sync, backend-sync-backfill, backend-integration | **100** | **c2fs_20261026_r1** | | Base, listen/pusher (dev and prod), jobs, desktop backend, all dev services | **0** | **v1** | This preserves the existing qualified Cloud Run reader scope. The inherited PR accidentally copied the Cloud Run 100 literal into previously disabled surfaces while retaining v1. That expansion is removed. Disabled readers cannot initialize/re-stamp ready totals. Epochs are not made globally identical by enabling unqualified readers. Declarations: `backend/deploy/runtime_env/_base.yaml`, `prod.overlay.yaml`, four listen/pusher chart values; generated runtime manifest and registry remain synchronized. The regression test checks complete literals, effective Cloud Run rendering, both chart environments, and the enable/epoch split. ## Product invariants affected - INV-MEM-4 — keep privacy/deletion authority checks unchanged; people dedupe uses the writer-generation fences in #23733 and has a 0% kill switch. - INV-DATA-1 — existing configuration keys and data planes; no routing or ownership change. ## Verification - Focused suite through `backend/test.sh`, `BACKEND_UNIT_TEST_FILE_LIST` naming `test_render_backend_runtime_env.py` and `test_verify_pusher_config_references.py`, `BACKEND_PYTEST_WORKERS=4`, under nice / omi-heavy. **119 passed** on the final repair (91 renderer/scope + 28 pusher binding tests). - `make preflight`: **44 passed**; normal pre-push gates passed, including both-environment runtime validation and type checking (0 errors). Final pushed head: `52661d092a9c07ff5454f627aa0268037edc6b85`; **60 terminal green checks, 0 pending/failed/cancelled**, independently checked at 10:50Z on 10-27; all 12 workflow runs completed successfully. - Luna's first round found a stale linked monthly-total runbook and a missing-declaration skip in the new test. Both are corrected; same-session delta returned **SHIP**. Review execs: `exec-corn-celery-front-snack-genuine-quiz` and `exec-cement-normal-thank-shoe-live-magnet`. - No production reads, writes, applies, merges, or deploys needed for this repair. Config rendering is the measured layer; no live-product acceptance or realized savings claimed. ## Lead-owned ship/ramp plan 1. After the batch entry/soak ends (~11:30Z on 10-27) and lead admission, ship **listen → pusher → Cloud Run**. Read back actual serving artifacts plus complete per-surface literal/epoch before each next step. All changes remain source-only until the lead ships them. 2. Keep people at **5**. Start its clock only after the last relevant surface serves the config. Hold **≥3 hours and two clean evaluator ticks**; require no privacy/deletion violations, speaker/transcript/Free-benefit changes, 5xx or live-p95 regression. Lead expands people to **100** with complete literals on the same surfaces, targeted by **10-28 12:00Z**; record a blocker if gates fail. Kill switch: people→0 everywhere applicable, preserving all other keys and the monthly split. 3. Additional monthly-total scope is a **separate qualification**. By **10-28 12:00Z**, lead attests every actual writer/revision/job/operator path, drains old writers, then aligns new readers to `c2fs_20261026_r1` while still at 0 before considering 5. Otherwise record the qualification blocker and leave them off. After **two hours** with zero synthetic equivalence mismatches and no accounting/Free allowance, contention, 5xx or p95 regression, lead may expand the qualified scope to 100 by **10-29 12:00Z**. Never enable a v1 reader against shared production totals. This PR does not enact that expansion. 4. Monthly-total rollback: readers→0, maintenance stays on. If an old writer runs, keep readers off until all writers qualify and choose a **new common epoch** before re-enabling. See `backend/docs/monthly-usage-totals.md`. 5. Compare absolute caller reads and replacement reads/writes/seed scans against 10-24/25; confirm **D+1 billing export** before booking net dollars. Realized savings from this repair: **$0**. Lead picks up URL, exact head, MERGE READY state and evidence from `data/run-2026-10-12-subscription-overhaul/reports/fsown-owner-1027.md`; no lead-bus post. Merge/deploy/apply remain with the Infra Rollout Coordinator.
…t-step) (#23837) ## Summary Firestore read config train: disable `memory_list_index_window` (100→0) and `batch_privacy_memoize` (100→0), and start `people_scan_dedupe` at **5%** after writer fencing #23733. The prior read loop graded the first two levers flat/WEAK or FALSIFIED; turning them off is not a measured dollar saving. No source query, authority, transcription, speaker, price, Free benefit, or audio-retention behavior is changed here. Every declaration is a complete 19-key replacement JSON literal. `finjob_candidate_queries` stays at 5. All four production Cloud Run service overrides now carry the same three changes as listen/pusher; they previously masked them. ## Monthly-total enable/epoch split — explicit, no scope expansion | Surface | usage_month_total | FSR_USAGE_MONTH_TOTAL_EPOCH | | --- | --- | --- | | Prod backend, backend-sync, backend-sync-backfill, backend-integration | **100** | **c2fs_20261026_r1** | | Base, listen/pusher (dev and prod), jobs, desktop backend, all dev services | **0** | **v1** | This preserves the existing qualified Cloud Run reader scope. The inherited PR accidentally copied the Cloud Run 100 literal into previously disabled surfaces while retaining v1. That expansion is removed. Disabled readers cannot initialize/re-stamp ready totals. Epochs are not made globally identical by enabling unqualified readers. Declarations: `backend/deploy/runtime_env/_base.yaml`, `prod.overlay.yaml`, four listen/pusher chart values; generated runtime manifest and registry remain synchronized. The regression test checks complete literals, effective Cloud Run rendering, both chart environments, and the enable/epoch split. ## Product invariants affected - INV-MEM-4 — keep privacy/deletion authority checks unchanged; people dedupe uses the writer-generation fences in #23733 and has a 0% kill switch. - INV-DATA-1 — existing configuration keys and data planes; no routing or ownership change. ## Verification - Focused suite through `backend/test.sh`, `BACKEND_UNIT_TEST_FILE_LIST` naming `test_render_backend_runtime_env.py` and `test_verify_pusher_config_references.py`, `BACKEND_PYTEST_WORKERS=4`, under nice / omi-heavy. **119 passed** on the final repair (91 renderer/scope + 28 pusher binding tests). - `make preflight`: **44 passed**; normal pre-push gates passed, including both-environment runtime validation and type checking (0 errors). Final pushed head: `52661d092a9c07ff5454f627aa0268037edc6b85`; **60 terminal green checks, 0 pending/failed/cancelled**, independently checked at 10:50Z on 10-27; all 12 workflow runs completed successfully. - Luna's first round found a stale linked monthly-total runbook and a missing-declaration skip in the new test. Both are corrected; same-session delta returned **SHIP**. Review execs: `exec-corn-celery-front-snack-genuine-quiz` and `exec-cement-normal-thank-shoe-live-magnet`. - No production reads, writes, applies, merges, or deploys needed for this repair. Config rendering is the measured layer; no live-product acceptance or realized savings claimed. ## Lead-owned ship/ramp plan 1. After the batch entry/soak ends (~11:30Z on 10-27) and lead admission, ship **listen → pusher → Cloud Run**. Read back actual serving artifacts plus complete per-surface literal/epoch before each next step. All changes remain source-only until the lead ships them. 2. Keep people at **5**. Start its clock only after the last relevant surface serves the config. Hold **≥3 hours and two clean evaluator ticks**; require no privacy/deletion violations, speaker/transcript/Free-benefit changes, 5xx or live-p95 regression. Lead expands people to **100** with complete literals on the same surfaces, targeted by **10-28 12:00Z**; record a blocker if gates fail. Kill switch: people→0 everywhere applicable, preserving all other keys and the monthly split. 3. Additional monthly-total scope is a **separate qualification**. By **10-28 12:00Z**, lead attests every actual writer/revision/job/operator path, drains old writers, then aligns new readers to `c2fs_20261026_r1` while still at 0 before considering 5. Otherwise record the qualification blocker and leave them off. After **two hours** with zero synthetic equivalence mismatches and no accounting/Free allowance, contention, 5xx or p95 regression, lead may expand the qualified scope to 100 by **10-29 12:00Z**. Never enable a v1 reader against shared production totals. This PR does not enact that expansion. 4. Monthly-total rollback: readers→0, maintenance stays on. If an old writer runs, keep readers off until all writers qualify and choose a **new common epoch** before re-enabling. See `backend/docs/monthly-usage-totals.md`. 5. Compare absolute caller reads and replacement reads/writes/seed scans against 10-24/25; confirm **D+1 billing export** before booking net dollars. Realized savings from this repair: **$0**. Lead picks up URL, exact head, MERGE READY state and evidence from `data/run-2026-10-12-subscription-overhaul/reports/fsown-owner-1027.md`; no lead-bus post. Merge/deploy/apply remain with the Infra Rollout Coordinator. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/23837?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="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/23837?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F23837&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
…0%) (#23939) ## Summary Firestore read lever config — flag off `people_scan_dedupe` 100 -> 0. Single-key delta on the served 19-key literal (verified live on backend-62c645a-40804413803-1 at 2026-10-29T0xZ under ro-prod); every other key byte-identical, including the `usage_month_total` split (0 base / 100 Cloud Run-only, epochs unchanged). Reason: `people_scan_dedupe` is FALSIFIED at 100% and the falsification is real, not a baseline artifact: - verify.py graded it FALSIFIED on 4 consecutive ticks (00Z-03Z, 2026-10-29): share 0.0484 -> 0.0359-0.0458, implied drop 1.4-6.6M/day vs need >= 7.5M/day (prediction 15M/day, levers.json). - Absolute needle check (`person_aliases:list_people`, snapshots 2026-10-28T00Z..04Z at lever 0 vs 2026-10-29T00Z..03Z at lever 100, same diurnal hours): 865k->1043k, 741k->829k, 659k->1094k, 577k->903k reads/h — the needle is 12-66% HIGHER at 100% than at 0% on the same hours. 12h-smoothed now-band ~1.07M/h (~25.7M/day) vs the pre-enable band ~0.55-0.65M/h (~13-16M/day): no saving; growth is exogenous (fleet/batch-pipeline growth, fast_ratio 0.7198, fleet gate PASS). - Mechanism note: the shipped WQ20 scope (#23733) wired the `known_spellings._people_spellings` memo only; the `find_person_by_name` miss-fallback full scan and the sync-side `list_people` callers were deliberately out of scope (WQ20 sol report), so the 15M/day prediction is unreachable by the shipped code path. All other levers on this literal graded SUPPORTED/INCONCLUSIVE by verify 2026-10-29T03:00:07Z (fleet gate PASS, give_back empty, coverage clean). Flagging people off restores overall verify PASS for the restored cohort. ## Product invariants affected - INV-MEM-4 — people/privacy authority checks unchanged; lever-off restores the legacy un-memoized scan path (safe default, previously serving before 2026-10-28). - INV-DATA-1 — existing configuration keys and data planes; no routing or ownership change. ## Verification - `set_levers.py` REPLACE-mode from the live-served 19-key literal (gcloud revision describe backend-62c645a-40804413803-1, ro-prod) with the single delta `people_scan_dedupe: 100 -> 0`; `prod.overlay.yaml` hand-patched to keep the `usage_month_total` Cloud Run-only 100 override (set_levers does not touch overlays); `compose_runtime_env.py` + `render_feature_flag_registry.py` re-run. - Diff audit: 44 literal lines changed, every one differs ONLY in `people_scan_dedupe` (100->0); key count 19 everywhere; `people_scan_dedupe:100` count 0 across all 11 touched files; `usage_month_total` split preserved (11x0 base/charts + 4x100 prod.overlay). - Contract tests: 119/119 pass on the branch (`test_render_backend_runtime_env.py` + `test_verify_pusher_config_references.py`, lane venv). - Full CI: running on this head. ## Lead-owned ship plan Deploy needed: listen -> pusher -> Cloud Run (train order per RUNBOOK). Flag-off is a safety-neutral cost revert (lever off = legacy path, previously the serving state before 2026-10-28); URGENT only in the sense that verify stays FAIL until served. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/23939?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="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/23939?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F23939&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
Single-key delta on the served 19-key FIRESTORE_READ_LEVERS literal: people_scan_dedupe 100 -> 0. verify.py FALSIFIED x4 ticks (00Z-03Z 10-29, share 0.0484 -> 0.0359-0.0458, implied drop 1.4-6.6M/day vs need 7.5M/day); absolute needle check at same diurnal hours shows person_aliases:list_people 12-66% HIGHER at 100% than at 0% (lever scope shipped in BasedHardware#23733 covers only known_spellings; sync-side list_people callers unwired). usage_month_total split (0 base / 100 Cloud Run-only) preserved; 119/119 contract tests pass. Loop: avo/firestore-reads (firestore-reads loop, WQ29).
Summary
Make
people_scan_dedupeusable for sync spelling hints without cross-request staleness. Every People mutation atomically increments an owner generation document; each cached hint read validates that document once. Fill snapshots capture the generation before scanning, and metadata recreation is fenced by document update time.Wire the sync attempt opener and
known_spellings._people_spellingsonly. Keep vocabulary and authority lookups live. Keep the lever at 0; no rollout/config/deploy change.Writer audit includes CRUD, speech samples/profiles, pinning, learning/jobs, auto-enrollment, assignment evidence, chat and Review undo/redo, backfill, and recursive account deletion. Existing accounts without metadata remain live until their next People mutation initializes the generation. Generation maintenance adds one atomic write per People mutation even while reuse is off.
Validation
WQ20 fix r2: the failed-Undo canary retry exposed
target.parent.idin the new generic Undo generation check. The strict fixture lacks collection.id; the swallowed failure wasAttributeErrorat the undo stage, with no People generation document created. Carry the validated journal collection with the Undo row instead. The canary test and fixture remain unchanged; cleanup round-trip coverage now asserts exact People generation increments and no non-People bumps.R2 preflight:
make preflightandscripts/pr-preflight --pr-body-file body.mdeach passed all 38 selected checks; draft metadata passed all 4 checks.R2 regression: 749 passed across all 39
test_dream_*.pyfiles plustest_fsr_people_scan_dedupe.py,test_fsr_scope_opener.py, andtest_fsr_people_generation.py(42 isolated files; no skips/deselections). Canary: 12; other Dream: 665; scan dedupe: 39; scope opener: 20; generation writers: 13. SeeWQ20-fix-r2.mdfor mechanism and commands.Review: zcode glm-5.3 VERDICT SAFE, no P1/P2 (exec-leopard-title-logic-blur-merge-profit, 2026-10-26); writer-fence audit of all 23 write sites, reader-admission and cost checks independently verified; reviewer re-ran 91 core + 142 regression + 9 import-lightness via backend/.venv. P3s accepted: generation .get() under memo lock (latency nit), +1 write per People mutation while lever is 0 (standing cost until a separate measured enablement PR), same-uid People transaction serialization (Firestore retry absorbs).
Worktree-local Python 3.11 environment installed with
make setup.Full
make preflight: 38 checks passed; no check exceptions or skips.Core selected suite: 91 passed; existing chat-emulator suite: 4 passed.
Targeted
backend/test.shruns cover attempt opener/retry/cancellation, generation and cross-context invalidation, off-path reads, and all touched writer families.Local loopback Firestore emulator: 31 checks pass, including external writers, concurrent increments, failed atomic commits, and metadata recreation.
Counted reads: ten 100-document hint scans cost 1,000 reads off and 110 on, including generation lookups.
Product invariants affected
none
Failure class
Failure-Class: none
This is a new guarded optimization behind an existing default-off lever. The prior unsafe wiring attempt was closed without production rollout; this change supplies its required concurrency contract and regression proofs.
R2 fixes an internal journal/fixture API dependency exposed by the existing canary regression; no generation or memo leak was reproduced. Failure-Class: none remains applicable.