Skip to content

margin-20: config right-sizing (Cloud Run, GKE floors, Firestore levers, idle T4s) - #24596

Merged
Git-on-my-level merged 5 commits into
mainfrom
lane/m20config
Nov 4, 2026
Merged

Git-on-my-level merged 5 commits into
mainfrom
lane/m20config

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Reduces verified production capacity floors, two Cloud Run memory limits, and Firestore reads through existing levers. Shared Cloud Run GMP collection moves to 60s. This is a config-only PR with existing contract pins updated; no product-code, merge, deployment, or production write is included. The lead owns qualification and rollout.

Config readbacks used ro-prod on 2026-11-04 ~10:43–10:55Z; caller coverage was rechecked at 11:25Z. Source was checked against main; this branch incorporates main's zero-replica T4 fallback. Seven-day Cloud Monitoring application-memory data covers 2026-10-28T10:41Z–2026-11-04T10:40Z, with every API page fetched, application and collector containers separated. Percentiles/maxima below are histogram bucket upper bounds, not averages disguised as maxima.

Item Live before New source value Measured evidence $/day estimate Rollback Deploy target
Memory index window 0 on four Cloud Run services plus listen/pusher memory_list_index_window=100 Scoped backend-family caller 6.60M/day (notifications-job excluded; coverage rechecked 11:25Z); ledger's prior measured reduction was only 1.2M/day (WEAK), not a correctness rollback ~0.6, unvalidated forecast Set key back to 0 Listen Helm → pusher Helm → backend Cloud Run train
Backend Cloud Run memory 8Gi, CPU 2/concurrency 20 4Gi 7d app-memory p95 ≤1.312GiB / max ≤1.710GiB, 62,839 observations 5–7, unvalidated forecast 8Gi in deploy/staging source Backend Cloud Run train
Backfill Cloud Run 3Gi / concurrency 6; maxScale live 16 2Gi / concurrency 10; cap unchanged 7d app-memory p95 ≤0.882GiB / max ≤1.149GiB, 121,226 observations ~2–4 memory-only; additional packing saving unqualified 3Gi / concurrency 6 in deploy/staging source Backend Cloud Run train
Listen floor HPA 20–60, 31 pods; CPU request 1 HPA 12–60; CPU request retained Live/source floor agrees; current exact-container CPU 0.162–0.997 cores, 24h per-pod p95 reaches 1.088, so CPU trim is excluded 0–6, off-peak only minReplicas 20 Helm prod-omi-backend-listen
Pusher floor HPA 12–40, 23 pods HPA 8–40 Live/source agrees; no required pod anti-affinity or topology-spread constraint in live/rendered template; existing eligible pool has ten nodes 0–4, off-peak only minReplicas 12 Helm prod-omi-pusher
Batch worker floor HPA min 6/max 12, running 12 replicaCount=4 AND autoscaling.minReplicas=4, max 12 Live/source floor agrees; day demand pins at max; retain scale-out metrics and OD placement, plus main's zero-replica T4 fallback 0–10, night only; zero immediate daytime saving Restore both floor values to 6 Helm prod-omi-batch-pipeline-worker via diarizer/worker train
Shared Cloud Run GMP interval Backend shared profile 30s; sync family already 60s Shared profile 60s; existing regex/sample limits retained Serving backend collector's OMI_GMP_RUN_MONITORING_CONFIG matches checked-in 30s profile; distinct sync profile already 60s Unknown: halves this profile's samples, not all GMP spend 30s + redeploy shared-profile consumers Backend Cloud Run train; desktop separately when its owner rolls it

Estimates are hypotheses from the scouts' billing-calibrated rates and measured caller volumes, not realized savings or proof of 20% margin. Floor savings depend on overnight demand and node autoscaling; no overlapping whole-node/packing savings are added. Existing output models and paid/trial feature admission are unchanged.

Rollout and deploy trap

Do not deploy this PR from the review lane. The rollout lead must roll listen → pusher → Cloud Run so cross-service candidate admission sees matching Firestore literals. Keep serving immutable image tags for chart-only rolls. The worker chart is a separate train.

Known trap: cloud-run-deploy-resets-maxscale. Save/read back the lead's ops env/scale before the train and restore untouched overrides using the existing procedure. The Redis guard owns backfill maxScale (live service/revision 16, bounds 8–40); this PR does not edit it. Sync maxScale remains 40. The Cloud Tasks dispatch budget keeps its conservative six slots per capped instance / ceiling 90; this PR does not raise arrival limits. Verify each traffic-serving revision, not just the service template, after deployment.

Existing drift is explicitly not resolved by this PR: Cloud Run serves people_scan_dedupe=0 and finjob_candidate_queries=0 while source carries 5 for both. Lead must preserve/reconcile those pre-existing pending ramps. Monthly-reader scope is retained: sync 100/100 for usage_month_cache/usage_month_total, other three Cloud Run services and GKE 0/0. Dev, jobs, and desktop Firestore literals are not changed.

Before rollout, the lead should reconcile the existing operator runbooks with the proposed targets: backend/docs/runbooks/batch-vendor-routing-capacity.md still instructs a 6/12 floor, and backend/docs/runbooks/cloud-run-metrics-ingestion.md still describes the shared 30s profile. Their dated live/audit observations remain historical evidence; the proposed source targets are 4/12 and 60s, with rollback to 6 and 30s. Detailed review follow-ups are in ops.md; this source PR stays config-only.

Post-deploy read back actual values and identities, watch OOM/5xx, socket/queue health and background p95 delay (authority threshold: no more than 15 minutes worse). Use the margin meter for realized run-rate; revert the relevant commit if a controlled signal breaches its gate.

Items skipped after verification

Item Reason / evidence Lead follow-up
tombstone_negative_cache absent→100 Cost mechanism refutes the scout: every hit replaces one tombstone lookup with one mandatory durable-token lookup; misses/ineligible tokens add a read Keep absent/off; no verified Firestore read saving
legal_hold_fence_cache absent→100 Every use adds a token read; valid cache hits reduce two authority reads to one, but misses/ineligible cases use three. Savings require eligible cache-hit share above 50%, which is unmeasured Keep absent/off until that crossover is qualified
people_scan_dedupe 5→100 Live Cloud Run 0 vs source 5; skip per live/source rule Reconcile serving 5% rollout before another ramp
usage_month_cache 0→100 Ledger records repeated 5xx guard flag-offs, including 2026-10-31T22:25Z, #24194; retain the existing sync-only exception Cache owner must exonerate before expanding readers
Sync memory 6→4Gi 7d p95 ≤1.006GiB, max bucket 3.316–3.785GiB; proposed limit leaves only ~5% over that upper bound Keep 6Gi pending stronger peak qualification
Integration memory 4→3Gi 7d p95 ≤1.312GiB, max bucket 1.952–2.228GiB; cannot prove max below required 2.2GiB Keep 4Gi
Listen CPU 1→750m 24h exact-container p95 reaches 1.088 cores, contradicting scout's 180–670m snapshot as a fleet bound Keep CPU 1
VAD replica/CPU conversion Live HPA min 1 vs repo 2; skip on drift rule. 6h GPU mean 0%, 24h max 99% Reconcile Helm ownership before retiring/converting
Diarizer-batch co-location Each pod requests GPU 1; live node allocatable GPU 1. 24h GPU maxima live 92% / batch 100%; 7d memory maxima 4.035/2.677GiB, so proposed 2Gi batch request is below observed peak Requires separately qualified GPU-sharing/capacity work
GMP OperatorConfig keep-list Actual object is add-on-owned gmp-public/config, filter {}; no repo declaration Ops list below; exporter prune intentionally excluded
Loki gateway access log off Repo already has verboseLogging: false, but live nginx access log is unconditional; skip on drift rule. Installed chart 6.33.0 has no nginxConfig.accessLog key Reconcile live Helm values; do not add an unwired key
Four small-service minScale cuts All four live minScale 1; none has a repo-owned scale declaration. Typesense pair are Firebase-extension managed; desktop workflow inherits its scale; JP is asia-northeast1 Ops-only follow-up in ops.md
Episode incremental cap No pure env knob. Same-source counters show 6,310 calls/hour now, 6,908 four hours earlier, 7,371 at yesterday's same hour: the claimed new 150× surge is unsupported Investigation details below; no product-code change

Code and ledger verification

Existing levers are consulted on main: backend/database/legal_holds.py:540–550 → privacy_negative_cache.decide; backend/database/conversation_tombstones.py:15–26; backend/database/memories.py:458 and backend/utils/memory/memory_service.py:1515; skipped levers at backend/database/person_aliases.py:252 and backend/database/user_usage.py:609. All are in KNOWN_LEVERS. backend/database/privacy_negative_cache.py:18–24 validates the durable token on every reuse. Neither negative-cache key has a recorded correctness rollback, but their read economics do not qualify them as verified cuts: privacy_negative_cache.py:18–24 always calls reference.get through privacy_check_metrics.py:104–120. Tombstones start with one lookup; legal holds start with two. Both keys remain absent/off. Memory-window FLAG_OFF was FALSIFIED savings grading on 10-27; the ledger's WEAK 1.2M/day reduction sets the conservative estimate here. The old people implementation had ineffective scope and was rewritten; that does not prove the new 5% cohort is live on Cloud Run.

VAD caller inventory: backend/utils/sync/pipeline.py:986, backend/routers/speech_profile.py:132 → backend/utils/stt/vad.py:302, maintenance script backend/scripts/stt/j_apply_vad_to_speech_profiles.py:30; chat uses strict local VAD at backend/utils/chat.py:160. The async hosted helper has no in-tree caller. Hosted transport at backend/utils/stt/vad.py:150,276 is bypassed when STT_GPU_FLEET_OFF=true, verified on prod Cloud Run/listen/pusher. Streaming/batch strict VAD is local. The HTTP image can select CPU (backend/modal/vad_modal.py:15,28), but no CPU conversion or callerless claim is qualified by this PR.

Episode investigation: same-source in-cluster sum(increase(llm_gateway_requests_total{lane_id="omi:auto:episode-incremental",phase="terminal"}[1h])) at ~10:55Z and offsets 4h/24h gives the counts above (~151k/day now vs ~177k/day yesterday at that hour). GMP has no gateway request series; Cloud Run moment counters cover only a small portion of the fleet, so source/coverage mismatch is a plausible explanation for 1.1k/day, not a proven reconstruction of the earlier query. backend/config/episodes.py:179–195 hardcodes 60s/180s rate limits. backend/utils/episodes/service.py:939–960 applies pause/recovery guards and chooses notes_free for composer-owned closed episodes; backend/utils/episodes/composer.py:813–852 already implements that suppression. backend/utils/episodes/incremental.py:349–388 can add one validator repair call. Changing these constants or broader admission/quality switches would be product work.

Verification

  • Through /Users/dazheng/workspace/omi/bin/omi-heavy: final Firestore/renderer/drift/two-lane/pusher-reference/privacy-safety suites: 241 passed.
  • Final chart/sizing/GMP/HPA replay suites (including main's T4 fallback): 240 passed.
  • test_cross_service_deploy_contract: 23 passed, 3 optional historical replays skipped.
  • Required hermetic backend/scripts/pre-deploy-check.sh: 357 passed on the final reduced scope.
  • test_fsr_wq5_index_window.py: 28 passed, covering cursor boundaries, hidden rows and bounded reads.
  • Final scope check: only memory_list_index_window changes, on exactly six prod hosts; dev/jobs/desktop and every other lever remain unchanged.
  • Helm lint passed for prod listen, pusher, and batch worker. make preflight and PR-body validation passed (56 selected checks). The installed full pre-push hook passed on the final head, including selected backend units and typechecking (0 errors). GOOGLE_APPLICATION_CREDENTIALS and every CLOUDSDK_* variable were removed before push; no skip flags were used.

Detailed local readbacks, scripts, test logs, and the lead's ops list: /Volumes/Ephemeral/scratch/planscost-handoff/m20config/ (ops.md, evidence/). No credentials or generated evidence are committed.

Product invariants affected

  • INV-MEM-4 — the existing read-window lever changes read reuse only; canonical promotion/write admission remains under its existing authority.

Failure class (fixes)

No fix: commits; this PR changes configuration and updates existing contract pins.

Set memory_list_index_window=100 only on prod Cloud Run/listen/pusher. Preserve monthly-reader scopes and all other levers. Token-validated negative caches stay absent: tombstone has no read saving, and legal-hold needs a qualified eligible-hit share above 50 percent.

Rollback: restore memory_list_index_window=0 on the same six targets; roll listen, then pusher, then Cloud Run.
Backend memory 8Gi to 4Gi; backfill memory 3Gi to 2Gi and concurrency 6 to 10. Match staging shape; preserve dev sizing and the Redis-owned maxScale.

Rollback: backend memory 8Gi; backfill memory 3Gi and concurrency 6 in deploy flags and staging shape.
Listen minReplicas 20 to 12, pusher 12 to 8. Retain listen CPU request 1 and all current scale-out metrics/ceilings; actual 24h listen CPU p95 reaches 1.09 cores.

Rollback: restore listen minReplicas=20 and pusher minReplicas=12 and reroll the corresponding Helm releases.
Set replicaCount and autoscaling.minReplicas together from 6 to 4. Retain the 12-worker ceiling, scale-out metrics and on-demand pool. No daytime saving is assumed while demand pins the HPA at 12.

Rollback: restore both replicaCount and autoscaling.minReplicas to 6 and reroll prod-omi-batch-pipeline-worker.
Match the already-live sync interval: shared profile 30s to 60s, with existing keep-lists and sample limits intact.

Rollback: restore interval 30s and redeploy services using the shared RunMonitoring profile.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 18 files

Confidence score: 3/5

  • action.yml raises production worker concurrency without updating the backfill dispatch budget, so Cloud Tasks may still cap throughput at the old allowance. Update the queue-cap contract and ops value to match.
  • The production chart lowers the worker floor to 4, but the capacity runbook still tells operators to keep it at 6. Update the runbook’s bounds, checklist, and rollback guidance.
  • cloud_run_gmp_sidecar.yaml changes the shared scrape interval to 60s, while the rollout runbook still assumes 30s for backend and desktop. Update its cadence, freshness, and cost guidance.
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=".github/actions/sync-backfill-lifecycle/action.yml">

<violation number="1" location=".github/actions/sync-backfill-lifecycle/action.yml:242">
P2: This raises production worker concurrency to 10 without keeping the backfill dispatch budget in sync. Update the queue-cap contract/ops value to use the new concurrency, otherwise Cloud Tasks can continue limiting throughput to the old six-per-instance sizing and delay queued backfills.</violation>
</file>

<file name="backend/charts/batch-pipeline-worker/prod_omi_batch-pipeline-worker_values.yaml">

<violation number="1" location="backend/charts/batch-pipeline-worker/prod_omi_batch-pipeline-worker_values.yaml:16">
P2: This chart lowers the production floor to 4, but the capacity runbook still declares min 6 as current and instructs operators to keep both values at 6. Update the runbook’s current bounds, checklist, and rollback guidance with this change, or keep the source floor at 6; otherwise Helm rollouts and incident procedures give contradictory capacity instructions.</violation>
</file>

<file name="backend/deploy/cloud_run_gmp_sidecar.yaml">

<violation number="1" location="backend/deploy/cloud_run_gmp_sidecar.yaml:12">
P3: This shared profile now scrapes every 60s, but the rollout runbook still describes backend and desktop as 30s. Update those cadence, freshness, and cost references so operators do not use a stale monitoring window.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

--max-instances=${{ steps.live-max-scale.outputs.max_scale }}
--max=${{ steps.live-max-scale.outputs.max_scale }}
--concurrency=6
--concurrency=${{ inputs.project_id == 'based-hardware' && '10' || '6' }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This raises production worker concurrency to 10 without keeping the backfill dispatch budget in sync. Update the queue-cap contract/ops value to use the new concurrency, otherwise Cloud Tasks can continue limiting throughput to the old six-per-instance sizing and delay queued backfills.

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 .github/actions/sync-backfill-lifecycle/action.yml, line 242:

<comment>This raises production worker concurrency to 10 without keeping the backfill dispatch budget in sync. Update the queue-cap contract/ops value to use the new concurrency, otherwise Cloud Tasks can continue limiting throughput to the old six-per-instance sizing and delay queued backfills.</comment>

<file context>
@@ -237,9 +239,9 @@ runs:
           --max-instances=${{ steps.live-max-scale.outputs.max_scale }}
           --max=${{ steps.live-max-scale.outputs.max_scale }}
-          --concurrency=6
+          --concurrency=${{ inputs.project_id == 'based-hardware' && '10' || '6' }}
           --cpu=2
-          --memory=${{ inputs.project_id == 'based-hardware' && '3Gi' || '8Gi' }}
</file context>

# margin-20: lower the off-peak warm floor from 6 to 4; day demand still scales
# to max 12. replicaCount and autoscaling.minReplicas are one floor: change both.
# Rollback: restore both to 6. OD-first placement and scale-out signals stay intact.
replicaCount: 4

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This chart lowers the production floor to 4, but the capacity runbook still declares min 6 as current and instructs operators to keep both values at 6. Update the runbook’s current bounds, checklist, and rollback guidance with this change, or keep the source floor at 6; otherwise Helm rollouts and incident procedures give contradictory capacity instructions.

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/charts/batch-pipeline-worker/prod_omi_batch-pipeline-worker_values.yaml, line 16:

<comment>This chart lowers the production floor to 4, but the capacity runbook still declares min 6 as current and instructs operators to keep both values at 6. Update the runbook’s current bounds, checklist, and rollback guidance with this change, or keep the source floor at 6; otherwise Helm rollouts and incident procedures give contradictory capacity instructions.</comment>

<file context>
@@ -10,15 +10,13 @@ dataPlaneProject: based-hardware
+# margin-20: lower the off-peak warm floor from 6 to 4; day demand still scales
+# to max 12. replicaCount and autoscaling.minReplicas are one floor: change both.
+# Rollback: restore both to 6. OD-first placement and scale-out signals stay intact.
+replicaCount: 4
 autoscaling:
   enabled: true
</file context>

path: /metrics
interval: 30s
# margin-20: halve shared-profile ingestion; rollback 30s.
interval: 60s

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This shared profile now scrapes every 60s, but the rollout runbook still describes backend and desktop as 30s. Update those cadence, freshness, and cost references so operators do not use a stale monitoring window.

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/cloud_run_gmp_sidecar.yaml, line 12:

<comment>This shared profile now scrapes every 60s, but the rollout runbook still describes backend and desktop as 30s. Update those cadence, freshness, and cost references so operators do not use a stale monitoring window.</comment>

<file context>
@@ -8,7 +8,8 @@ spec:
       path: /metrics
-      interval: 30s
+      # margin-20: halve shared-profile ingestion; rollback 30s.
+      interval: 60s
       timeout: 10s
       metricRelabeling:
</file context>

@Git-on-my-level
Git-on-my-level merged commit df8d613 into main Nov 4, 2026
71 of 72 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/m20config branch November 4, 2026 12:48
Git-on-my-level added a commit that referenced this pull request Nov 4, 2026
…oors, backfill concurrency, memory lever) (#24601)

Reverts the parts of #24596 that Luna blocked, keeping the cleared Cloud Run
backend 8->4Gi and GMP 60s changes:
- listen minReplicas back to 20, pusher back to 12 (P1: scale-in and the roll
  can drop live sockets without the qualified admission drain)
- batch-pipeline-worker replicaCount/minReplicas back to 6 (P1: capacity runbook)
- backfill keeps 2Gi but concurrency back to 6 (P2: 2Gi qualified only at 6)
- FIRESTORE_READ_LEVERS memory_list_index_window back to 0 everywhere (P2: no
  cohort readout); listen/pusher env identical to pre-#24596

Co-authored-by: Claude Opus 5.5 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Nov 4, 2026
…; memory_list_index_window 25 (#24639)

## What

Config only, one batched lever change:

| Key | Change | Why |
|---|---|---|
| `FSR_SUBSCRIPTION_TTL_SECONDS` | 60 -> 55 (all services) |
cl2-replay's verified privacy replay (1,049 faulted transitions,
2026-11-04 20:12Z) found that, with both invalidations lost, the Redis
`EX 60` subscription/BYOK entry is still served at exactly +60.000s: 37
mismatches at 0s margin. 55s gives 0 with 5s margin. |
| `action_items_ttl120` | 0 -> 5 | Ordinary lever from #24624: the
version-bumped action-item page cache reuses pages for at least 120s
instead of the deployed 30s. |
| `memory_list_index_window` | 0 -> 25 | Back to the cohort that soaked
48h clean (#23536). The #24596/#24601 revert objected to the 0->100
jump, not the lever. |
| `backend/docs/runbooks/external-list-reads.md` | wording | States the
live 5% polling-cache cohort from #24623 (Luna r1 minor on #24623). |

Luna r1 removed `lifecycle_record_pending_head` from this change: it
cohorts on a single namespace key, so 5% would be off on every replica.
A follow-up keys it per replica.

This also satisfies lead2's enforce requirement for #24622
(`1104-b059ba`): the subscription TTL becomes 55s. The new privacy
caches already use a strict `< 60.000s` bound.

## Rollout

David's 2026-11-04 policy for ordinary read levers: 5% for 1-2h with the
firestore-reads 5xx/latency guards, then 100% the same day in a
follow-up. Rollback: set any key back to its previous value.

## Verification

- `pytest tests/unit/test_render_backend_runtime_env.py
tests/unit/test_verify_pusher_config_references.py
tests/unit/test_firestore_read_levers.py
tests/unit/test_backend_runtime_env_validator.py`: 294 passed.
- `pytest tests/unit/test_fsr_s4_caches.py`: passes (TTL ceiling 60
unchanged; 55 is within it).
- Local push gate ran with `BACKEND_UNIT_FILE_BUDGET_SECONDS=900` (host
load ~50); CI keeps its own 300s budget.

## Product invariants affected

- INV-MEM-4 (path match on `backend/deploy/runtime_env.yaml` only; no
memory promotion behavior changes)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
kriegcloud pushed a commit to kriegcloud/omi that referenced this pull request Nov 5, 2026
…ing_head 5, memory_list_index_window 0 -> 25

Ordinary read levers under David's 2026-11-04 policy (5% for 1-2h, then 100):
- action_items_ttl120 / lifecycle_record_pending_head (code BasedHardware#24624) start at 5%.
- memory_list_index_window returns to 25, where it soaked 48h clean before the
  BasedHardware#24596/BasedHardware#24601 revert; that revert objected to the 0->100 jump, not the lever.
Rollback: set any key back to 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant