Repository navigation
fix(backend): restore monthly usage reads only for sync admission - #24210
Conversation
Enable the monthly cache and maintained totals on prod backend-sync only. Keep all other service literals and epochs pinned by the runtime contract. Failure-Class: FC-bounded-read-exceeds-request-budget
There was a problem hiding this comment.
2 issues found across 4 files
Confidence score: 4/5
prod.overlay.yamlenablesusage_month_totalfor every caller onbackend-sync, not just batch admission. Clarify the comment and PR title so they reflect the broader scope.- The comments for the other production services still say monthly reads are off, which is now inconsistent with the
backend-syncsetting. Update the affected service comments.
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/deploy/runtime_env/prod.overlay.yaml">
<violation number="1" location="backend/deploy/runtime_env/prod.overlay.yaml:841">
P2: The lever `usage_month_total` is process-wide on backend-sync, so this enables monthly-total reads for every caller, not only batch admission. The comment and PR title overstate the scope. Either narrow the comment to say the change applies to all backend-sync monthly-usage reads, or confirm that admission is the only caller reachable on that service.</violation>
<violation number="2" location="backend/deploy/runtime_env/prod.overlay.yaml:844">
P3: The remaining service blocks still claim monthly reads are off on all four prod Cloud Run services, but this change enables them on `backend-sync`. Update the comments in the backend, backend-sync-backfill, and backend-integration blocks to reflect the exception.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| # carries people=5, memory=0, privacy=0 (finjob=5). | ||
| # Lead train: listen -> pusher -> Cloud Run; do not enable additional monthly readers here. | ||
| FIRESTORE_READ_LEVERS: {value: '{"action_items_page":100,"backfill_task_reads":0,"batch_privacy_memoize":0,"candidates_page":100,"canonical_statuses_dedupe":100,"conversation_list_cursor":100,"deletion_marker_cache":100,"finjob_candidate_queries":0,"historical_scan_memo":0,"ledger_purge_coalesce":0,"mcp_conversation_cards_cache":100,"memory_list_index_window":0,"people_scan_dedupe":0,"queue_age_sample_budget":0,"request_read_dedupe":100,"serving_config_cache":100,"singleton_loops":0,"subscription_cache":100,"usage_month_cache":0,"usage_month_total":0}', category: rollout} | ||
| # Restore monthly usage reads only for compute admission on backend-sync (admitscope 2026-11-01). |
There was a problem hiding this comment.
P2: The lever usage_month_total is process-wide on backend-sync, so this enables monthly-total reads for every caller, not only batch admission. The comment and PR title overstate the scope. Either narrow the comment to say the change applies to all backend-sync monthly-usage reads, or confirm that admission is the only caller reachable on that service.
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/deploy/runtime_env/prod.overlay.yaml, line 841:
<comment>The lever `usage_month_total` is process-wide on backend-sync, so this enables monthly-total reads for every caller, not only batch admission. The comment and PR title overstate the scope. Either narrow the comment to say the change applies to all backend-sync monthly-usage reads, or confirm that admission is the only caller reachable on that service.</comment>
<file context>
@@ -838,12 +838,10 @@ overlay:
- # carries people=5, memory=0, privacy=0 (finjob=5).
- # Lead train: listen -> pusher -> Cloud Run; do not enable additional monthly readers here.
- FIRESTORE_READ_LEVERS: {value: '{"action_items_page":100,"backfill_task_reads":0,"batch_privacy_memoize":0,"candidates_page":100,"canonical_statuses_dedupe":100,"conversation_list_cursor":100,"deletion_marker_cache":100,"finjob_candidate_queries":0,"historical_scan_memo":0,"ledger_purge_coalesce":0,"mcp_conversation_cards_cache":100,"memory_list_index_window":0,"people_scan_dedupe":0,"queue_age_sample_budget":0,"request_read_dedupe":100,"serving_config_cache":100,"singleton_loops":0,"subscription_cache":100,"usage_month_cache":0,"usage_month_total":0}', category: rollout}
+ # Restore monthly usage reads only for compute admission on backend-sync (admitscope 2026-11-01).
+ # Writers maintain totals and cache invalidation while reader levers are off.
+ # Preserve the existing epoch and every other service/lever (#24194 guard).
</file context>
| # Restore monthly usage reads only for compute admission on backend-sync (admitscope 2026-11-01). | |
| # Restore monthly usage reads on backend-sync. The lever is process-wide and applies to all get_monthly_usage_stats callers on this service. |
| # Restore monthly usage reads only for compute admission on backend-sync (admitscope 2026-11-01). | ||
| # Writers maintain totals and cache invalidation while reader levers are off. | ||
| # Preserve the existing epoch and every other service/lever (#24194 guard). | ||
| FIRESTORE_READ_LEVERS: {value: '{"action_items_page":100,"backfill_task_reads":0,"batch_privacy_memoize":0,"candidates_page":100,"canonical_statuses_dedupe":100,"conversation_list_cursor":100,"deletion_marker_cache":100,"finjob_candidate_queries":0,"historical_scan_memo":0,"ledger_purge_coalesce":0,"mcp_conversation_cards_cache":100,"memory_list_index_window":0,"people_scan_dedupe":0,"queue_age_sample_budget":0,"request_read_dedupe":100,"serving_config_cache":100,"singleton_loops":0,"subscription_cache":100,"usage_month_cache":100,"usage_month_total":100}', category: rollout} |
There was a problem hiding this comment.
P3: The remaining service blocks still claim monthly reads are off on all four prod Cloud Run services, but this change enables them on backend-sync. Update the comments in the backend, backend-sync-backfill, and backend-integration blocks to reflect the exception.
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/deploy/runtime_env/prod.overlay.yaml, line 844:
<comment>The remaining service blocks still claim monthly reads are off on all four prod Cloud Run services, but this change enables them on `backend-sync`. Update the comments in the backend, backend-sync-backfill, and backend-integration blocks to reflect the exception.</comment>
<file context>
@@ -838,12 +838,10 @@ overlay:
+ # Restore monthly usage reads only for compute admission on backend-sync (admitscope 2026-11-01).
+ # Writers maintain totals and cache invalidation while reader levers are off.
+ # Preserve the existing epoch and every other service/lever (#24194 guard).
+ FIRESTORE_READ_LEVERS: {value: '{"action_items_page":100,"backfill_task_reads":0,"batch_privacy_memoize":0,"candidates_page":100,"canonical_statuses_dedupe":100,"conversation_list_cursor":100,"deletion_marker_cache":100,"finjob_candidate_queries":0,"historical_scan_memo":0,"ledger_purge_coalesce":0,"mcp_conversation_cards_cache":100,"memory_list_index_window":0,"people_scan_dedupe":0,"queue_age_sample_budget":0,"request_read_dedupe":100,"serving_config_cache":100,"singleton_loops":0,"subscription_cache":100,"usage_month_cache":100,"usage_month_total":100}', category: rollout}
FSR_USAGE_MONTH_TOTAL_EPOCH: {value: c2fs_20261026_r1, category: rollout}
# Batch ladder 2026-10-29 (lead ruling 12:15Z): pin shadow 25 so a Cloud Run deploy
</file context>
…eep #24210 backend-sync usage_month exception) (#24238) ## Summary Firestore reads loop **restoration config** (guard cohort re-enable): five `FIRESTORE_READ_LEVERS` values 0 → **100**, everything else byte-identical to main. This is the exoneration follow-up to #24194 (guard flag-off, WQ31/WQ32). - Discriminating experiment result (levers at 0 since #24207/#24210 served ~04:44Z 2026-11-01): backend-sync 5xx stayed **flat-to-higher** at 0.0041–0.0044 (1522–1639 err/h, ticks 05Z/06Z/07Z) vs 0.0035–0.0036 at levers 100 and ref 0.0014 — per the loop's own rule, the flagged cohort is **EXONERATED** (exogenous). The lead's independent RCAs agree (`admitscope-2026-11-01.md` §5 "After the flag-off, 5xx rose, so per the runbook's own discriminating rule the flagged cohort is exonerated"; `syncwall-2026-11-01.md` attributes the 5xx mass to deliberate nonterminal_ack + legacy file retries). - Restored to 100: `singleton_loops`, `backfill_task_reads`, `historical_scan_memo`, `ledger_purge_coalesce`, `queue_age_sample_budget`. Measured give-back at 0 (cohort-union of needle callers, snapshot 2026-11-01T05Z/07Z vs pre-flag-off 10-31T19Z/21Z): ~29–44M reads/day ≈ **$14–21/day**; at 0 the flag-off also re-added the batch-admission latency class documented in admitscope. - **Kept at #24210 scope on purpose (lead instruction 6be508/5bd7df/c38004):** `usage_month_cache` / `usage_month_total` stay 0 everywhere except the `cloud_run/backend-sync` exception (100/100, `FSR_USAGE_MONTH_TOTAL_EPOCH` unchanged). The GKE charts keep the Cloud Run-only `usage_month_total` split (GKE = 0). `finjob_candidate_queries` stays 0 (its own 02Z UNSAFE gate; callers ~0). `batch_privacy_memoize`, `memory_list_index_window`, `people_scan_dedupe` stay 0 (graded WEAK/FALSIFIED). Config only, generated with `avo/firestore-reads/set_levers.py` + the prod.overlay inline sites (5 keys only); audited at 19 literal sites: the 5 restored keys = 100 everywhere, `usage_month_cache`/`usage_month_total` = 0 everywhere except the backend-sync Cloud Run site. Regenerated `runtime_env.yaml` + flag registry; the two pinned contract tests updated (119/119 pass on the lane venv). Per the lead: **this PR is NOT to be merged by the loop** — it is staged for the single off-peak lead train before 13:00Z. ## Product invariants affected - INV-MEM-4 — config-only lever rollout; no data-path, promotion or authority change; every restored lever reverts to flag-off behavior at 0. - INV-DATA-1 — no routing or ownership change; value-only edit of the existing `FIRESTORE_READ_LEVERS` key. ## Test plan - `backend/tests/unit/test_render_backend_runtime_env.py` + `backend/tests/unit/test_verify_pusher_config_references.py`: 119/119 pass on the lane venv. - Literal audit: 19 sites JSON-parsed; 5 restored keys = 100 at every site; umc/umt = 0 everywhere except `prod.overlay` backend-sync (100/100, #24210 exception preserved); finjob/bpm/mliw/people = 0 at every site. ## Rollout 1. Lead-owned single off-peak train before 13:00Z, order **listen → pusher → cloud-run** (FIRESTORE_READ_LEVERS order). The loop does not merge, dispatch, or approve anything here. 2. Post-train: tick verify continues; ramp-clock/grade bookkeeping per runbook; re-baseline after serve. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/24238?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/24238?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F24238&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. -->
…eep BasedHardware#24210 backend-sync usage_month exception) Discrimination verdict at full cohort-off (BasedHardware#24207+BasedHardware#24210 served ~04:44Z): backend-sync 5xx flat-to-higher 0.0041-0.0044 (1522-1639/h, 05Z-07Z ticks) vs 0.0035-0.0036 at 100 and ref 0.0014 -> cohort EXONERATED per runbook rule; agrees with lead RCA admitscope-2026-11-01 s5 + syncwall-2026-11-01. Restored to 100: singleton_loops, backfill_task_reads, historical_scan_memo, ledger_purge_coalesce, queue_age_sample_budget. Give-back at 0 measured ~29-44M reads/day (~$14-21/day, snapshot union 11-01T05/07Z vs 10-31T19/21Z). Kept: usage_month_cache/usage_month_total at BasedHardware#24210 scope (backend-sync CR site 100/100 only; GKE umt stays 0 per CR-only split) per lead instruction; finjob_candidate_queries 0 (own 02Z gate); bpm/mliw/people 0 (graded). Config-only via set_levers.py + prod.overlay inline sites; 19 literal sites audited; contract tests updated; 119/119 pass (lane venv). NOT merged by the loop: staged for the lead's single off-peak train before 13:00Z.
…/ledger_purge 100->0 (backend-sync 5xx 0.0134 vs ref 0.0073) (#24348) # Firestore reads loop guard flag-off — 2026-11-02 (singleton/backfill/historical/ledger_purge 100→0) ## Summary Firestore reads loop **URGENT guard flag-off** (autonomous, loop RUNBOOK step 1): four `FIRESTORE_READ_LEVERS` values 100 → **0**, everything else byte-identical to main. Response to verify tick 2026-11-02T05:00:20Z FAIL (pending-actions `flag_off`: singleton_loops, usage_month_cache, backfill_task_reads, historical_scan_memo, ledger_purge_coalesce). - Breach: backend-sync 5xx 3652/271872 = **0.0134** (audio-merge excluded in both windows) vs ref (prev-week same window, excl audio-merge) 1805/248696 = **0.0073**. Hourly trajectory: 0.0041 (22Z) → 0.0048 (23Z–00Z; restoration #24238 served 23:52Z) → 0.0062 (01Z) → 0.0082 (02Z) → 0.0078 (03Z) → 0.0076 (04Z) → **0.0134 (05Z)**. Evidence is ambiguous (smooth multi-hour rise, no clean step at the serve hour), so per the runbook ("flag off on breach anyway when the evidence is ambiguous") the flag-off proceeds as the discriminating experiment: rate falls at 0 → restoration cohort implicated (stays 0); rate stays >ref at 0 → exogenous again (#23739 / lead RCA e54718 precedent), restoration re-planned with the lead. - Flagged off everywhere (base ×11 sites, four Cloud Run overlay sites, listen/pusher dev+prod charts): `singleton_loops`, `backfill_task_reads`, `historical_scan_memo`, `ledger_purge_coalesce` 100 → 0. `usage_month_cache` base stays 0 (it was already 0 off the #24210 exception scope). - **Kept on purpose: `prod.overlay` backend-sync `usage_month_cache`/`usage_month_total` = 100** — the #24210 compute-admission exception. Admission calls backend-sync `/authorize-compute` with a 5-second client timeout; zeroing these re-breaks admission (admission stage mean ~5.1s, unevaluated deferrals ~3.7/s — the exact incident #24210 fixed under lead ruling dde240). The 05Z tick's `usage_month_cache` UNSAFE carries the shared service-scope why (WQ30 precedent: same-why proves service-scope), and `usage_month_total` was not flagged at all. If post-flag-off discrimination implicates umc specifically, zeroing the exception is #24210's documented rollback (admission impact accepted; lead decides). - `queue_age_sample_budget` stays 100 (not flagged; its needle callers read ~0 since the budget lever — readout 402.5M → 0.0M/day). All other keys unchanged. Config only, generated with `avo/firestore-reads/set_levers.py` (replace-mode, complete 20-key literal) plus the four prod.overlay inline sites hand-patched (flagged keys only) and the third pinned `expected` dict in `test_firestore_train_preserves_monthly_reader_scope_and_cloud_run_overrides` updated (set_levers' regexes do not cover it). Stale #24194-era comment blocks refreshed to the current scope. Regenerated `runtime_env.yaml` + feature-flag registry. ## Product invariants affected - INV-MEM-4 — config-only lever rollout; no data-path, promotion or authority change; every flagged lever reverts to flag-off behavior at 0; the #24210 admission exception is unchanged (epoch c2fs_20261026_r1 preserved). - INV-DATA-1 — no routing or ownership change; value-only edit of the existing `FIRESTORE_READ_LEVERS` key. ## Test plan - `backend/tests/unit/test_render_backend_runtime_env.py` + `backend/tests/unit/test_verify_pusher_config_references.py`: **119/119 pass** on the lane venv (`backend/.venv` freshly synced from pylock.macos.toml via `make setup-backend`). - Literal audit: 26 deploy value sites JSON-parsed — the 4 flagged keys = 0 at every site; `usage_month_cache`/ `usage_month_total` = 100 only at the prod.overlay + rendered backend-sync exception; `queue_age_sample_budget` = 100 everywhere; finjob/bpm/mliw/people = 0 everywhere. ## Rollout 1. **URGENT**: lead-owned train, order **listen → pusher → cloud-run** (FIRESTORE_READ_LEVERS order). The loop does not dispatch deploys or approve gates. 2. Post-serve: hourly tick verify runs the discrimination (2 clean ticks at 0 → cohort implicated, stays 0; flat >ref → exogenous, restoration re-plan with the lead). Re-baseline after the served revision changes. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/24348?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/24348?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F24348&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. -->
…/ledger_purge 100->0 (backend-sync 5xx 0.0134 vs ref 0.0073, 05Z tick; BasedHardware#24210 admission exception kept)
… (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. -->
Problem and change
Batch compute admission calls the backend-sync authorize-compute route with a 5-second client timeout. Disabling both monthly-usage read levers made each lease aggregate hourly usage again. The admitscope 2026-11-01 report measured admission stage mean around 5.1s and unevaluated deferrals around 3.7/s; these are prior aggregate measurements, not measurements from this PR.
Restore
usage_month_cacheandusage_month_totalfrom 0 to 100 only on prod Cloud Run backend-sync. Every other lever value, including the other five guard-flagged levers andfinjob_candidate_queries=0, remains byte-identical. PreserveFSR_USAGE_MONTH_TOTAL_EPOCH=c2fs_20261026_r1. Listen, pusher, backend, backfill, integration, jobs, desktop and dev env are unchanged. Re-render runtime_env and the feature-flag registry.The existing contract test pinned one literal everywhere. Lead ruling dde240 explicitly authorizes one named prod/backend-sync exception, exactly these two keys; the test continues to pin all other services and epochs. No worker, admission, retry, workflow or data changes. Lead owns merge and deploy.
Allowance and cache safety
Totals continued to be maintained while reads were off.
backend/database/monthly_usage_totals.py:queue_incrementandqueue_invalidationdo not consult the lever. Ordinary and once-only writers indatabase/user_usage.py:431-455write hourly source plus monthly increments in one fenced transaction; absolute overwrites invalidatereadyin the same commit (:501-526).database/batch_pipeline_projection.py:_commit_usageincrements the monthly total alongside the hourly source and once/partial-completion receipt. The admin reset tool also invalidates totals atomically (scripts/admin/reset_transcription_usage.py:649-669).lever_enabled('usage_month_total', ...)gates onlyread_monthly_totals._epoch()is unchanged;_readyrequires ready/schema/epoch and valid numeric/day data. Unready or mismatched totals rebuild transactionally from hourly source, with concurrent writers conflicting on the same monthly doc; rebuild/read failures fall back to the original query. Therefore the off interval itself does not make totals stale or undercount. This source trace is not a fresh serving-artifact qualification: perbackend/docs/monthly-usage-totals.md, an old-writer rollback would require requalification and a new epoch before enabling readers. Lead must preserve the existing qualified writer fleet when deploying this restoration.Cache invalidations continued while reads were off.
database/fsr_read_cache.py:writingruns independently oflever_enabled, advances generations before/after writes and fences publication across concurrent writes.cache_writerwraps ordinary/once/absolute writers and user deletion; batch full/partial projection and admin reset usewriting('usage_month_cache', ...). The maximum TTL is 60s, anchored before the source read; disabling reads for hours cannot leave a live pre-disable payload. Redis failure falls back to source reads; invalidation failure retains the existing bounded-staleness behavior.Cache alone is not proven to fit 5s. With eight repeated-owner leases and a warm memo, eight scans can collapse to one miss plus seven hits, but eight distinct owners/cold variants can still require eight scans. Admitscope estimates serial
8 x (2 transactions + 1 scan)at 3-6s+; it supplies no cache-only hit ratio or scan-time split. Its measured pre-off ~1.0-1.2s route mean had both levers enabled. Restore both because maintenance is independent of read gating; do not claim cache-only latency is established.Serving scope and other readers
ComputeClientconstructs/v2/batch-pipeline/authorize-compute; prod worker chartworker.apiUrltargets backend-sync. All four Cloud Run services run the shared main app with the defaultallrole, andapp_roles.pymounts this router for API/workers, so they can expose the route; the configured production worker caller targets backend-sync. The backfill and integration overlay blocks are independent, not YAML aliases, and are unchanged. No cloud reads or production account data were needed for this source/config trace.These levers wrap both
get_monthly_usage_statsandget_monthly_usage_stats_since. Other callers on this same app include subscription/funded allowance checks (including sync-jobs), usage/plan APIs (routers/users.py,routers/storefront.py), support usage checks andget_current_user_usage. They receive the same authoritative statistics through the restored cache/totals path. Separate fundedread_monthclosed-bucket/session and shadow readers are unaffected.Validation
bin/omi-heavy run -- nice -n 19 env BACKEND_PYTEST_WORKERS=4 BACKEND_UNIT_TEST_FILE_LIST=<four-file-list> bash backend/test.sh: 333 passed, file-isolated (runtime renderer 91, runtime validator 24, cache 148, monthly totals 70).bin/omi-heavy run -- nice -n 19 ... bash backend/scripts/pre-deploy-check.sh: hermetic dev/prod runtime/workflow/source-admission checks and 355 tests passed.backend/.venv/bin/python3 backend/deploy/compose_runtime_env.pyand... scripts/render_feature_flag_registry.py: regenerated artifacts; scope comparison verifies exactly one runtime literal changes and exactly the two 0-to-100 keys, with every other runtime value identical.bin/omi-heavy run -- nice -n 19 scripts/pr-preflight --pr-body-file <body>: full selected PR preflight passed, including runtime image source closure. Metadata preflight initially requested INV-MEM-4; the body now includes it.Deploy, rollback and acceptance
Deploy needed: lead-owned Cloud Run backend-sync env/image train only; no listen/pusher or GPU worker roll required by this diff. Rollback: set these two keys back to 0 only on backend-sync and re-render/deploy, preserving all other keys and the epoch.
After 15-30 minutes serving, require
admission_unevaluated_deferred < 0.3/s, admission stage mean <2s,admission_policy_deferredreturning and completed/leased increasing (admitscope target >=0.5). Also inspect cold rebuild/fallback rates and usage correctness. Record release identity and traffic before interpreting metrics.Product invariants affected
INV-DATA-1: same production data plane and atomic accounting; only read optimization selection changes.
INV-MEM-4: canonical memory authority flags and all non-monthly levers remain unchanged.
Failure-Class: FC-bounded-read-exceeds-request-budget
The serial per-lease monthly scans exceed the caller budget; this config restores the existing bounded read path. Deadline/partial-receipt hardening is a separate lead-owned plan.