Repository navigation
perf(people): reuse generation-fenced scans at name and sync callers - #24422
Conversation
There was a problem hiding this comment.
6 issues found across 16 files
Confidence score: 2/5
get_or_create_person_by_namecreates a People document without bumping the generation, so cached scans can miss the new person. Add the generation increment to the transaction.people-generation-writers.jsonis out of sync with the reviewed sources, so the writer-audit test fails on every run. Regenerate the inventory fingerprints from the reviewed HEAD.- The writer audit can miss generation helpers called through aliases, collection constants or references, and it omits
user_data_deletion.purge_user_subtree. Improve the detection and include the purge writer so these invalidation paths are covered. person_aliases.pyfalls back to live rows for missing or malformed generation heads without recording the shared fallback event. Record the fallback for bothNoneheads and exceptions.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/docs/people-generation-writers.json">
<violation number="1" location="backend/docs/people-generation-writers.json:2">
P1: This inventory does not match the sources it is intended to audit, so the new writer-audit test fails on every run. Regenerate all fingerprints from the reviewed HEAD (for example with `people_generation_inventory.py --write`) and commit the resulting values.</violation>
<violation number="2" location="backend/docs/people-generation-writers.json:7">
P1: `get_or_create_person_by_name` is listed as audited, but its transaction creates a People document without bumping the generation; cached scans can miss that person during the attempt. Add the generation increment to the same transaction before retaining this scope.</violation>
</file>
<file name="backend/docs/runbooks/people-scan-reuse.md">
<violation number="1" location="backend/docs/runbooks/people-scan-reuse.md:28">
P2: The writer audit omits `user_data_deletion.purge_user_subtree`, even though account purge directly deletes the People generation head after deleting the People subtree. Add this owner and document the delete-as-invalidation exception so future audits do not miss the account-erasure path.</violation>
</file>
<file name="backend/scripts/people_generation_inventory.py">
<violation number="1" location="backend/scripts/people_generation_inventory.py:18">
P2: The prefilter only recognizes literal People collection calls or helper text, so writers using a collection constant or reference can evade the audit entirely. Replace this text gate with structural AST detection or scan all Python sources.</violation>
<violation number="2" location="backend/scripts/people_generation_inventory.py:25">
P2: This audit misses generation helpers called through import aliases: `_name` sees `bump` or `persist`, not `bump_people_generation` or `write_person`, and omits the containing writer unless it also contains a literal `collection('people')` call. Resolve imported helper aliases when classifying calls so aliased writers cannot bypass the committed enumeration.</violation>
</file>
<file name="backend/database/person_aliases.py">
<violation number="1" location="backend/database/person_aliases.py:293">
P2: Missing or malformed generation heads fall back to live rows here without emitting the shared fallback event. Add one `record_fallback` path covering both exceptions and `None` heads so rollout telemetry reports all guard-unavailable fallbacks consistently.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| @@ -0,0 +1,77 @@ | |||
| { | |||
There was a problem hiding this comment.
P1: This inventory does not match the sources it is intended to audit, so the new writer-audit test fails on every run. Regenerate all fingerprints from the reviewed HEAD (for example with people_generation_inventory.py --write) and commit the resulting values.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/docs/people-generation-writers.json, line 2:
<comment>This inventory does not match the sources it is intended to audit, so the new writer-audit test fails on every run. Regenerate all fingerprints from the reviewed HEAD (for example with `people_generation_inventory.py --write`) and commit the resulting values.</comment>
<file context>
@@ -0,0 +1,77 @@
+{
+ "backend/database/_client.py:delete_collection_recursive": "020f43fc0e4d148051db3469545adc5b04a13653c4daa3a0acf57f3501f6f0b9",
+ "backend/database/chat_edits.py:apply_update": "f2f307cfbf62e2659abf3e553ec2de1558795a82300b1b197291f56daab58c22",
+ "backend/database/chat_edits.py:apply_update.apply": "171d40fbe346a445bbc179bf6457c61921c8c8fa434574e26c8cd0e3838e5c05",
</file context>
| "backend/database/chat_edits.py:apply_update.apply": "171d40fbe346a445bbc179bf6457c61921c8c8fa434574e26c8cd0e3838e5c05", | ||
| "backend/database/chat_edits.py:restore": "3d29685851e3593a39ab72464329655b39b8eeb546b067897ebb384ad4fadeb8", | ||
| "backend/database/chat_edits.py:restore.apply": "5fdf32961bb04b56021e0565a3657205cc2fd2baad47e78e8dc578900f5814e9", | ||
| "backend/database/people.py:get_or_create_person_by_name": "9442ad8742e2320e7b97953c867fe07e18bafbb83f3bccb0dc4d6b1167c72569", |
There was a problem hiding this comment.
P1: get_or_create_person_by_name is listed as audited, but its transaction creates a People document without bumping the generation; cached scans can miss that person during the attempt. Add the generation increment to the same transaction before retaining this scope.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/docs/people-generation-writers.json, line 7:
<comment>`get_or_create_person_by_name` is listed as audited, but its transaction creates a People document without bumping the generation; cached scans can miss that person during the attempt. Add the generation increment to the same transaction before retaining this scope.</comment>
<file context>
@@ -0,0 +1,77 @@
+ "backend/database/chat_edits.py:apply_update.apply": "171d40fbe346a445bbc179bf6457c61921c8c8fa434574e26c8cd0e3838e5c05",
+ "backend/database/chat_edits.py:restore": "3d29685851e3593a39ab72464329655b39b8eeb546b067897ebb384ad4fadeb8",
+ "backend/database/chat_edits.py:restore.apply": "5fdf32961bb04b56021e0565a3657205cc2fd2baad47e78e8dc578900f5814e9",
+ "backend/database/people.py:get_or_create_person_by_name": "9442ad8742e2320e7b97953c867fe07e18bafbb83f3bccb0dc4d6b1167c72569",
+ "backend/database/people.py:set_person_pinned": "07a61bab61f1f89eaa38d4ca25136449d84450f9371f7ee1d47bad2cabc043f6",
+ "backend/database/people.py:set_person_pinned.apply": "1875c7948f3489fed4f29e1db4b49d3205fad2f103bddcf993fcbe00258dd664",
</file context>
| | `speaker_learning_jobs`, `speaker_auto_enroll` | job completion and enrollment | | ||
| | `speaker_assignment_effects` | assignment effects | | ||
| | `review_changes`, `chat_edits` | apply and restore | | ||
| | `_client` | recursive People deletion batches; account purge deletes generation last | |
There was a problem hiding this comment.
P2: The writer audit omits user_data_deletion.purge_user_subtree, even though account purge directly deletes the People generation head after deleting the People subtree. Add this owner and document the delete-as-invalidation exception so future audits do not miss the account-erasure path.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/docs/runbooks/people-scan-reuse.md, line 28:
<comment>The writer audit omits `user_data_deletion.purge_user_subtree`, even though account purge directly deletes the People generation head after deleting the People subtree. Add this owner and document the delete-as-invalidation exception so future audits do not miss the account-erasure path.</comment>
<file context>
@@ -0,0 +1,62 @@
+| `speaker_learning_jobs`, `speaker_auto_enroll` | job completion and enrollment |
+| `speaker_assignment_effects` | assignment effects |
+| `review_changes`, `chat_edits` | apply and restore |
+| `_client` | recursive People deletion batches; account purge deletes generation last |
+| `utils/person_evidence_backfill` | evidence repair |
+
</file context>
|
|
||
| def _name(call): | ||
| function = call.func | ||
| return function.id if isinstance(function, ast.Name) else getattr(function, 'attr', '') |
There was a problem hiding this comment.
P2: This audit misses generation helpers called through import aliases: _name sees bump or persist, not bump_people_generation or write_person, and omits the containing writer unless it also contains a literal collection('people') call. Resolve imported helper aliases when classifying calls so aliased writers cannot bypass the committed enumeration.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/scripts/people_generation_inventory.py, line 25:
<comment>This audit misses generation helpers called through import aliases: `_name` sees `bump` or `persist`, not `bump_people_generation` or `write_person`, and omits the containing writer unless it also contains a literal `collection('people')` call. Resolve imported helper aliases when classifying calls so aliased writers cannot bypass the committed enumeration.</comment>
<file context>
@@ -0,0 +1,90 @@
+
+def _name(call):
+ function = call.func
+ return function.id if isinstance(function, ast.Name) else getattr(function, 'attr', '')
+
+
</file context>
| pass | ||
| memo.clear() | ||
| generation = memo.generation | ||
| if people_generation is None: |
There was a problem hiding this comment.
P2: Missing or malformed generation heads fall back to live rows here without emitting the shared fallback event. Add one record_fallback path covering both exceptions and None heads so rollout telemetry reports all guard-unavailable fallbacks consistently.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/database/person_aliases.py, line 293:
<comment>Missing or malformed generation heads fall back to live rows here without emitting the shared fallback event. Add one `record_fallback` path covering both exceptions and `None` heads so rollout telemetry reports all guard-unavailable fallbacks consistently.</comment>
<file context>
@@ -264,15 +283,28 @@ def list_people(
pass
memo.clear()
generation = memo.generation
+ if people_generation is None:
+ # Uninitialized/failed heads never permit reuse. Keep
+ # reading People live, but avoid another paid probe
</file context>
| ROOT = Path(__file__).resolve().parents[2] | ||
| INVENTORY = 'backend/docs/people-generation-writers.json' | ||
| HELPERS = frozenset({'bump_people_generation', 'write_person', 'read_people_generation', 'generation_ref'}) | ||
| TOKENS = re.compile( |
There was a problem hiding this comment.
P2: The prefilter only recognizes literal People collection calls or helper text, so writers using a collection constant or reference can evade the audit entirely. Replace this text gate with structural AST detection or scan all Python sources.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/scripts/people_generation_inventory.py, line 18:
<comment>The prefilter only recognizes literal People collection calls or helper text, so writers using a collection constant or reference can evade the audit entirely. Replace this text gate with structural AST detection or scan all Python sources.</comment>
<file context>
@@ -0,0 +1,90 @@
+ROOT = Path(__file__).resolve().parents[2]
+INVENTORY = 'backend/docs/people-generation-writers.json'
+HELPERS = frozenset({'bump_people_generation', 'write_person', 'read_people_generation', 'generation_ref'})
+TOKENS = re.compile(
+ r"collection\s*\(\s*(['\"])people\1|bump_people_generation|write_person|read_people_generation|generation_ref"
+)
</file context>
|
Luna R2 is SHIP at 44da6bb. Rebuttal to the optional fixture-signature tightening: the separate |
…libration (#24426) Add `omi_delivery_outcome_total{kind,outcome}` at durable summary terminals, sync callback returns and action-item export boundaries. Labels use only the fixed kinds `summary|sync|action_item_export` and outcomes `delivered|no_op|deferred|failed`; unknown values are rejected before creating metric children. Outcomes use the shared closed enum and reason-label adapter without adding debt or allowlist exceptions. Summary observations emit after the existing transaction commits, once across retries, without changing existing first-summary receipts or business state. An open summary obligation is deferred; deliberately waived short-clip debt stays no-op. Sync holds, absent/redirected/open targets and fences are deferred; discarded results remain no-ops even if old summary text is retained. Deferred/locked processing results cannot become delivered. Export counters observe each public result without changing return values or provider calls; a device enqueue is deferred. The counters measure attempts, including retries, rather than unique deliveries. Helpers keep the existing oversized owner files from growing. The no-op alarm remains **unarmed**. Infracost records serving release identities, traffic and visible counters, then collects seven full clean days per kind and service after all serving traffic runs the new code. Only then may a separate monitoring change propose a minimum-volume six-hour no-op ratio threshold from the baseline. First baseline progress decision is due within three days of deploy; it cannot shorten the seven-day hold. No alert rule or production action is part of this PR. Both GMP keep-lists retain delivery/People counters, all existing metric families, `omi_firestore_billed_reads_by_*` and `omi_fsr_leader_lease_total`. The inventory refresh uses ro-prod aggregate metric names, keeps observed names distinct from declarations and preserves admission holds and legacy debt. No production account data is read. Metrics ship on; lead-owned rollback is a later code-revert train. No savings are booked for this instrumentation. Validation: 1,086 unique unit cases passed across 20 selected files over the implementation. After R1's two classification findings, all 113 focused debt/transaction/sync/parity cases and 29 hermetic E2E cases passed again. Integration with the merged B/C main line then passed 241 combined unit cases, 29 E2E cases and monitoring lint. The label-contract/audio selection passed all 149 cases (36 delivery, 19 enum contract, 94 audio-outbox); the old CI worker's nonzero audio status did not reproduce locally. Targeted types report zero errors. All tests ran through `bin/omi-heavy run -- nice -n 19`; units use `backend/test.sh`, explicit file lists and four workers. Tests cover committed-only emission through retries, debt preparation/waivers, discard precedence, deferred/locked results, bounded labels, canonical/legacy parity, export results and both GMP profiles. Malformed observations preserve business results. The oversized owners retain their exact original line counts (4652 and 3965), with no exception. Main through `1708dc7859b0` (including merged #24413/#24422) is integrated. The three GMP/inventory conflicts were resolved from the full incoming main configuration, preserving every existing family and admission/legacy-debt metadata. The fresh aggregate inventory contains 2,280 observed names and 17 declarations. Final CI and delta review remain required. ## Product invariants affected none Initiative: unit-economics ANX: card:ic-reads-1102
… (post-#24422 re-pin) (#24504) ## What FIRESTORE_READ_LEVERS config-only change on top of #24455's 22-key manifest: - `people_scan_dedupe` 0 -> 5: the #24422 rewrite has served dark since 2026-11-03T02:49Z. Its pre-ramp base is re-pinned from a post-dark-deploy snapshot as the PR asked (`baseline-2026-11-03T12Z-post24422.json`: list_people 261,561/h + read_people_generation 0 rows in top_1h ~= 6.28M/day at 1hx24; the old ~15.1M/day pin predates the dark deploy). - `finjob_candidate_queries` 0 -> 5: flagged off 2026-11-01 during the exogenous `/v2/sync-jobs/run` + `/v2/sync-local-files` 5xx waves. Both routes are now named guard exclusions until 2026-11-09 (workspace main fb748d571f7 + 852e2fb0cb3, lead rulings bus 01:18Z and b33168 03:55Z), the guard flag_off has been quiet since 09Z, and verify 2026-11-03T12Z is PASS. Everything else is byte-identical to the origin/main manifest, including `bpp_generation_memo:100` and `sync_snapshot_resolve_cache:5` and the #24210 backend-sync `usage_month_cache`/`usage_month_total`=100 exception. ## Product invariants affected - INV-FSR-LEVERS (REPLACE-mode literal rule respected; both keys already in KNOWN_LEVERS; default-off sites unchanged) - INV-MEM-4: not affected. The changed deploy manifest is a locked path, but only the Firestore read lever map changes; memory intake and promotion routes are untouched. Failure-Class: none ## Verification - `set_levers.py` REPLACE-mode with the full 22-key literal; `compose_runtime_env.py` and `render_feature_flag_registry.py` regenerated outputs; diff audit shows only the two keys changed across all literal sites (the #24210 backend-sync exception preserved). - Contract tests on the lane venv: 119/119 pass (`test_render_backend_runtime_env.py` incl. the `test_firestore_train_preserves_monthly_reader_scope_and_cloud_run_overrides` expected-literal updated to the new values; `test_verify_pusher_config_references.py`). #24210 backend-sync `usage_month_cache`/`usage_month_total`=100 override site preserved (rendered line 3401). - Firestore reads loop verify 2026-11-03T12Z PASS (no lever UNSAFE/FALSIFIED). ## Lead-owned ship plan Deploy needed: listen -> pusher -> Cloud Run (+ desktop-backend + jobs ride runtime_env) — FIRESTORE_READ_LEVERS train order per the two-lane split. Config rides the next routine trains; no new train requested. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/24504?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/24504?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F24504&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. -->
Wire the existing attempt-local People generation guard to the actual
find_person_by_namemiss fallback and sync context reader.vocabulary._sourcesstays live. Only raw rows may be reused; each sync call still resolves entitlement and projects current learning state. Mutation/authority reads and generation changes retire snapshots. Missing or unavailable heads always use live rows and avoid repeated paid head probes within that attempt.Repeated the WQ20 writer enumeration before changing callers, and pinned the reviewed People/generation scopes so a new writer or removal of a generation bump fails the audit test. The strict writer and loopback emulator contracts remain the atomicity proof; fingerprints alone are not one. Added bounded, closed-label dark repeat telemetry and retained both GMP cost-grade families.
The lever remains 0. The earlier slice was FALSIFIED and its baseline must not be reused. Infracost must include
people_generation:read_people_generationalongsideperson_aliases:list_peoplein the grade, then re-pin this item's own absolute pre-ramp reads/day after dark deployment. Production repeat rate is unmeasured. The synthetic five-call name-fallback fixture measures four repeats (80%) and one full scan; the sync fixture also requires five entitlement/learning passes. The separate 100-row fixture includes paid generation reads. These are modeled contracts, not production savings; $4–8/day remains estimated.Ramp owner: infracost. After the new baseline, use a separate config PR for 5%, require two verify ticks PASS, then 100% only with lower absolute reads/day and clean 5xx/latency guards. First decision within three days of deploy. Rollback: lever 0. No production writes, account-data reads, privacy-cache implementation or shared verifier edits.
Validation: 999 unit cases across 13 files passed their assertions. The one new cold-import CPU overrun was corrected by loading the dependency in fixture setup, and all 46 cases in that file then passed the unchanged guard. After rebasing onto main, all 63 writer/memo/GMP cases passed again, as did 23 targeted hermetic E2E cases and 31 loopback Firestore emulator checks with main's privacy write fence installed. CI then exposed an old taught-speaker fixture that accepted only uid; it now accepts the supported memoize keyword. All 16 cases in that file pass locally, including the unchanged CPU guard. Targeted types report zero errors. Tests ran through
bin/omi-heavy run -- nice -n 19; unit selections usebackend/test.sh, four workers and explicit file lists. The GMP conflict resolution retained the entire main keep-list and added only the People family. Seebackend/docs/runbooks/people-scan-reuse.mdfor the writer enumeration and ramp prerequisites. These are local contract layers, not production measurements.Product invariants affected
none
Initiative: unit-economics
ANX: card:ic-reads-1102