Repository navigation
fix(observability): the finalization backlog panel said 25,000; the real number was 414 - #12211
Merged
Merged
Conversation
… and version-control the board The "Finalization jobs by status" panel read `sum by (status) (listen_finalization_jobs)` and showed a 25,000-job backlog. The real number was 414. `listen_finalization_jobs` is one global Firestore-derived value that every backend-listen replica republishes, so `sum()` multiplies it by the replica count — 21 today. It is worse than a constant factor while the fleet runs mixed images: 9 pods report from the projection shards and 12 report a direct Firestore count, so the sum blended two different answers to the same question. Verified: `max by (status)` returns queued=408, matching a Firestore aggregation count of the collection exactly. The panel also stacked `dead_letter` — a cumulative all-time terminal total that only ever rises, and the source of ~19k of the phantom 25k — on top of the live backlog, so a flat queue read as a growing crisis. Changes to the capture-pipeline row: - "Finalization jobs by status" -> "Unfinished finalization jobs": `max by (status)`, nonterminal statuses only, unstacked. Its description states the max-not-sum rule and the pre-2026-07-25 projection undercount. - "Dead letters" -> "Finalization gave up (dead letters)". The query was already correct (a range increase on the counter); the description was not. It claimed each dead letter is a conversation the user never got. Measured over 14d, only ~15% of dead letters actually discard a conversation — the discard is guarded on the conversation still being in `processing` — and there is no metric for that subset yet. - The retries series legend now says it only ever rises on the Cloud Tasks lane. `LISTEN_FINALIZATION_RETRIES_TOTAL` is not incremented by inline pusher retries, so a flat line there is not evidence of health, which is exactly what the panel's "retries rising before dead letters is the early warning" note implied it was. - New "How finalizations settle (30m)": success vs stale (fenced) vs failure. The mix was not visible anywhere, and `failure` going non-zero is the signal that captures are being given up on. - "Oldest unfinished job" keeps its query; its description now names the aggregation rule. Exported to `dashboards/general/omi-core-features.json` so the board stops being Grafana-DB-only. Applied to prod as version 8. Co-Authored-By: Claude Opus 5 <[email protected]>
…n they claim to
`listen_finalization_oldest_nonterminal_age_seconds` read 0 while 408
finalization jobs sat unfinished, the oldest for 36 days. It was computed by
paging `reconcile_after_at <= now` and taking the max `created_at` of an
arbitrary 100 rows. Two defects in one query:
- `reconcile_after_at` is deleted outright on the BYOK resume path
(`_resume_blocked_byok_job_txn`) and the BYOK retry path
(`_mark_finalization_retryable_txn`), by design — the credential-free Cloud
Tasks reconciler must never replay a BYOK job. Every such job was therefore
invisible to the gauge. In prod, all 408 currently-queued jobs are
`requires_byok=true` with no `reconcile_after_at`, so the gauge could only
ever read 0 for the exact population it exists to report.
- `.limit(100)` with no ordering returns an arbitrary page, so even for rows it
could see it reported the oldest of a sample, not the oldest.
Ask `status` directly instead: one ordered single-document read per nonterminal
status, via a registered query spec and its composite index. Cost stays bounded
and independent of terminal history — the property the projection fan-in was
built for is preserved.
Also make the second trap explicit in the metric HELP text. These three gauges
report one global Firestore-derived quantity and every replica republishes it,
so `sum()` multiplies the true value by the replica count. A prod dashboard was
doing exactly that and reading 25k jobs where there were 414; while the fleet
runs mixed images it also mixes two different answers. And `dead_letter` inside
`listen_finalization_jobs` is a cumulative all-time total, not a backlog.
Verified against prod: `max by (status) (listen_finalization_jobs{status=~
"queued|leased|blocked_byok"})` returns queued=408, matching a Firestore
aggregation count of the collection exactly.
Co-Authored-By: Claude Opus 5 <[email protected]>
…ter unit test routers/conversations.py picked up `from utils.integration_telemetry import emit_posthog_event` (Conversation Summary Shared telemetry on delivered share emails), landed on main same-day as this branch. That import broke collection of test_conversation_search_date_validation.py: the test file replaces `utils` with an _AutoMockModule package (same reasoning already documented for utils.journey_metrics_contract), so any real submodule under `utils` that isn't explicitly stubbed raises ModuleNotFoundError at import time. Add the missing stub entry, matching the existing pattern. Pre-existing on origin/main, unrelated to this PR's finalization-backlog changes; fixing it here because it was failing the Backend unit suite check on this PR. Co-Authored-By: Claude Opus 5 <[email protected]>
Git-on-my-level
added a commit
that referenced
this pull request
Aug 31, 2026
…12446) ## Why this change On 2026-08-30 a voice-capture outage left `capture_finalization` success at **0% for hours** while every existing critical stayed Normal: listen ready=5, listen WS≈325, pusher WS≈326, LB traffic flowing, 5xx rps=0. The existing criticals only watch zero LB traffic, zero ready pods, WS < 10, and 5xx rates. The rules that did read user outcomes (`omi-journey-*-fail`, #11991) are **warning-class**, and the [Omi Core Features dashboard](https://monitor.omi.me/d/omi-core-features/omi-core-features) that plots these SLIs is visualization-only — panel thresholds, zero alert rules. **Dashboard ≠ alert**: the signal existed, nothing paged on it. Incident fingerprint (last 1h at peak): `omi_journey_terminal_total{journey="capture_finalization"}` success=0, failure≈360, stale≈290; accepted≈750; oldest unfinished finalization job ≈ 5.9 days; dead letters ≈ 2.5k/24h. ## What was added Six `severity: critical` rules in the `Resilience` group (split source `backend/charts/monitoring/alerts/resilience.json`, mirrored into the combined `backend/charts/monitoring/alert-rules.json`), plus one rule change. Every rule links the Core Features panel that plots its own signal. | Metric / SLI | Existing rule (git = live mirror) | False-negative class this incident hit | New / changed UID | noDataState | Traffic gate | |---|---|---|---|---|---| | `capture_finalization` success share | `omi-journey-capture-fail` (warning, #11991; reads `listen_finalization_durable_jobs` deltas) | warning-class — ticket lane, no page; incident kept it out of the paging path | `omi-journey-capture-success-critical` | `NoData` | ≥ 20 accepted / 30m | | accepted-without-terminal (accepted vs settled) | `omi-capture-finalization-dead-emission` (warning; fires only on **zero** terminal movement) | incident had *flowing* failure/stale terminals, so the zero-terminal condition never applied at page class | `omi-journey-capture-settle-gap` | `NoData` | ≥ 100 accepted / 1h | | `listen_finalization_dead_letter_total` | **missing** (dashboard panel only) | ~2.5k dead letters/day with zero alerts reading it | `omi-capture-dead-letter-surge` | `Alerting` | none — each dead letter is a lost capture (> 50/1h) | | `listen_finalization_oldest_nonterminal_age_seconds` | **missing** (backlog panel from #12211 only) | oldest job aged to 5.9 days with zero alerts reading it | `omi-capture-oldest-nonterminal` | `Alerting` | none — queue age is traffic-independent (> 3600s) | | `pusher_session` success share | `omi-journey-pusher-fail` (warning) | warning-class only | `omi-journey-pusher-success-critical` | `NoData` | ≥ 20 accepted / 30m | | `chat_response` success share | `omi-journey-chat-fail` (warning; unfirable for its whole life before the Cloud Run bridge) | warning-class + counter historically absent from Prometheus | `omi-journey-chat-success-critical` | `NoData` | ≥ 20 accepted / 30m | | journey counter liveness | `omi-journey-signal-dead` covered only `pusher_session\|capture_finalization`; `chat_response` exempt | a dead chat counter would silently disarm every chat alert (the exact 2026-08-19 hole) | `omi-journey-signal-dead` **changed** — adds a `chat_response` arm | `Alerting` | chat arm gated on `llm_gateway_requests_total{lane_id="omi:auto:chat-agent"} > 20/1h` | ### PromQL Success-rate rules pair numerator and denominator from the same emitter (`omi_journey_terminal_total` for one `journey`), gated on that journey's accepted counter (example: capture): ```promql # A — gate sum(increase(omi_journey_accepted_total{journey="capture_finalization"}[30m])) # B — success share (a total terminal stall with real traffic reads 0 and pages) sum(increase(omi_journey_terminal_total{journey="capture_finalization",outcome="success"}[30m])) / clamp_min(sum(increase(omi_journey_terminal_total{journey="capture_finalization",outcome=~"success|failure"}[30m])), 1) # C — $A >= 20 && $B < 0.90, for 10m ``` Settle gap (accepted minus all terminal outcomes, 1h): `$A >= 100 && $B > 50`, for 15m. Oldest job: `max(listen_finalization_oldest_nonterminal_age_seconds) > 3600`, for 15m. Dead letters: `sum(increase(listen_finalization_dead_letter_total[1h])) > 50`, for 15m. Liveness chat arm (added to `omi-journey-signal-dead`): ```promql or (sum by (journey) (increase(omi_journey_accepted_total{journey="chat_response"}[1h])) < bool 1) * on() group_left() (sum(increase(llm_gateway_requests_total{lane_id="omi:auto:chat-agent"}[1h])) > bool 20) ``` ### noData semantics - Success-rate and gap rules: `NoData` (the documented `traffic_gated_journey` class) — missing series are visible as NoData, never healthy; counter death pages via `omi-journey-signal-dead` and `omi-journey-scrape-missing`. - Queue rules (`oldest-nonterminal`, `dead-letter`): `Alerting` — both series are unlabeled and zero-initialized on every backend-listen replica, so absence during real traffic means the emitter or its scrape is gone. Documented as `finalization_queue_health` in `expected-targets.prod.yaml`. ### Threshold calibration (documented in `backend/docs/runbooks/real-traffic-journeys.md`) - 0.90 paging floor vs the dashboard's 95/99 display thresholds; the incident sat at 0%. - ≥ 20 accepted/30m gate (same floor the existing warning rules use); the incident ran ~375 accepted/30m. - Gap > 50/h at ≥ 100 accepted/h: the incident left ~100/h accepted-but-never-settled; healthy in-flight work settles in minutes. - Oldest job > 1h: healthy drain is minutes; incident oldest was ~5.9 days. - Dead letters > 50/h: incident ran ~104/h (2.5k/day). - Chat liveness gate > 20/h sits above the chat-agent lane's measured p05 (min 9, p01 15, p05 23, median 55 req/h over 7 prod days), so quiet hours do not page. These are incident-calibrated initial values; replay them against production history when importing (the repo has no live Prometheus access from a PR-checkout environment). ## Live vs git reconciliation - Live Grafana (issue-verified 2026-08-30 ~23:30 UTC): **68 unified rules**; git before this PR: **80**. The 12-rule delta is recently merged rules not yet imported (Firestore #12193/#12201/#12241, cloud-run ingestion #11998/#12146, etc.) — the documented apply path is a maintainer import of `alert-rules.json`; no CI writes Grafana, and this PR follows that path (no API writes). - The pre-incident journey rules (from #11991, merged 2026-08-22) predate the outage window; their gap was severity class, not presence. - Metric label sets were discovered from the emitter contract, not guessed: `utils/metrics.py`, `utils/observability/journeys.py` (`journey` ∈ {`chat_response`, `pusher_session`, `capture_finalization`}; `outcome` ∈ {`success`, `failure`, `cancelled`, `stale`}), `services/conversation_finalization.py` (unlabeled dead-letter counter, unlabeled oldest-age gauge, `state`-labeled durable gauge), and the closed vocabulary in `backend/docs/runbooks/real-traffic-journeys.md`. Direct live Prometheus/Grafana queries were not available from this environment (auth required); the `chat_response` ingestion path is evidenced by #12146's measured live prod scrape (~28MB, 52,662 `omi_*` series). ## Tests Extended `test_monitoring_alert_rule_contract.py`: - `LIVENESS_EXEMPT_JOURNEYS` is now empty — the `chat_response` exemption's own deletion clause fired once the Cloud Run bridge was verified live; `test_every_alerted_journey_is_covered_by_the_liveness_rule` now enforces chat coverage instead. - New: `test_page_class_journey_rules_cover_the_capture_outage_fingerprint` (severity, component, noData, `for` window, receiver, exact math gates), `test_page_class_success_rules_pair_numerator_and_denominator_from_one_emitter`, `test_finalization_queue_rules_read_the_replicated_series_correctly` (max-aggregation for the replicated gauge). ## Verification ```bash cd backend && .venv/bin/python -m pytest \ tests/unit/test_journey_observability.py \ tests/unit/test_monitoring_alert_rule_contract.py \ tests/unit/test_monitoring_dashboard_absence_contract.py \ tests/unit/test_monitoring_telemetry_contract.py -q # 63 passed (the exact set scripts/select_backend_unit_tests.py selects for these changed files) make preflight # PR preflight passed: 11 checks in 28.55s ``` Closes SCA-379 <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/12446?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="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The dashboard said 25,000. The real number was 414.
The "Capture pipeline" row of the Omi Core Features board (prod Grafana,
monitor.omi.me) showed a finalization backlog of ~25k jobs climbing steadily. Investigating it turned up three independent defects: two in the metrics themselves and one in the panel that reads them.1.
sum()on a global gauge (panel)listen_finalization_jobsis one global Firestore-derived value that every backend-listen replica republishes. The panel readsum by (status) (listen_finalization_jobs), which multiplies the true value by the replica count.Measured against prod Prometheus:
A Firestore aggregation count of
conversation_finalization_jobsreturns queued=408, leased=2, blocked_byok=0, dead_letter=1185 —maxis exact,sumis off by 17x.It is worse than a constant factor right now: 12 of the 21 pods (
velma-canary,parakeet) run a July-18 image that computes the gauge with a direct Firestore.count(), while the other 9 read the projection shards whose generation starts 2026-07-25 and is not backfilled. The two populations report 1185 vs 493 for the same quantity, so the sum was blending two different answers to the same question.The repo's own checked-in board already does this correctly —
resilience-fallbacks.jsonusesmax by (state) (listen_finalization_durable_jobs). The Omi Core Features board was Grafana-DB-only and never got that treatment.2. Stacking a cumulative counter on a live backlog (panel)
dead_letterinsidelisten_finalization_jobsis only ever incremented — no code path decrements it, and job rows are never deleted (712,832completedrows are still in the collection). It is an all-time terminal total, and it was ~19k of the phantom 25k. Stacked underqueued, a flat backlog read as a growing crisis.3.
listen_finalization_oldest_nonterminal_age_secondsread 0 while 408 jobs sat unfinished for up to 36 days (metric)The gauge paged
reconcile_after_at <= nowand took the maxcreated_atof an arbitrary 100 rows. Two defects in one query:reconcile_after_atis deleted outright on the BYOK resume path (_resume_blocked_byok_job_txn) and the BYOK retry path (_mark_finalization_retryable_txn) — by design, so the credential-free Cloud Tasks reconciler never replays a BYOK job. In prod, all 408 currently-queued jobs arerequires_byok=truewith noreconcile_after_at, so the gauge was structurally incapable of seeing the exact population it exists to report. It could only ever read 0..limit(100)with no ordering returns an arbitrary page, so even for rows it could see it reported the oldest of a sample, not the oldest.This is the same failure shape as the 2026-08-20 macOS chat outage: a signal that is green because it cannot represent the failure.
What this changes
Metrics (
backend/)get_finalization_job_summaryasksstatusdirectly — one ordered single-document read per nonterminal status, through a registered query spec (FINALIZATION_OLDEST_NONTERMINAL_QUERY) and its composite index. Cost stays bounded and independent of terminal history, which is the property the projection fan-in was built for.sum()trap is now stated in the HELP text of all three replicated gauges, so it is visible in Grafana's own metric browser, along with the fact thatdead_letteris cumulative.Dashboard (
backend/charts/monitoring/dashboards/general/omi-core-features.json, new)max by (status), nonterminal statuses only, unstacked. Description states the max-not-sum rule and the pre-2026-07-25 projection undercount.increaseon the counter); the description was not. It claimed each dead letter is a conversation the user never got — measured over 14d, only ~15% of dead letters actually discard a conversation, because the discard is guarded on the conversation still being inprocessing.LISTEN_FINALIZATION_RETRIES_TOTALis not incremented by inline pusher retries, so a flat line there is not evidence of health — which is exactly what the panel's "retries rising before dead letters is the early warning" note implied it was.failuregoing non-zero is the signal that captures are being given up on.What this does NOT do
It does not fix the 408 stranded BYOK jobs — it only makes them visible. That leak (they are invisible to both the Cloud Tasks worker and the reconciler once the live pusher session ends) is a separate change.
Verification
max by (status) (listen_finalization_jobs{status=~"queued|leased|blocked_byok"})returnsqueued=408, leased=2..6, blocked_byok=0, matching a Firestore aggregation count of the collection exactly.backend/test-preflight.sh: 18 passed, 0 failed. Targeted suites green:test_conversation_finalization_jobs.py,test_firestore_query_contract.py,test_journey_observability.py,test_monitoring_telemetry_contract.py(115 passed).backend/test.sh(918 files): 4 files fail in this local environment —test_optional_audio_codecs,test_share_email,test_atomicity_lifecycle_regressions,test_backend_runtime_env_validator. These same 4 fail identically on a pristineorigin/mainin the same worktree, so they are pre-existing/environment-dependent, not caused by this change. CI is the authority.Line-Count-Exception: backend/database/conversation_finalization_jobs.py | 1735 -> 1754 | The replacement age query is a per-status ordered read (9 lines vs the 3-line unordered page) plus the comment recording why the old
reconcile_after_atpage could never see BYOK jobs. Splitting this 1735-line file is real work that belongs in its own change, not smuggled into an observability fix.🤖 Generated with Claude Code
Failure class
Failure-Class: FC-alert-never-provably-fired
Both defects are that contract: an expression that is silently wrong for how the metric is actually exposed reads as healthy. The panel's
sum()was wrong for a gauge every replica republishes; the age gauge'sreconcile_after_atfilter was wrong for a population defined by not carrying that field, and returned 0, which is indistinguishable from healthy. Prevention applied as the class prescribes: every expression in this change was run against the real prod series and reconciled against a Firestore aggregation count before it shipped.The metric-side half — a health signal derived from a bookkeeping field that the unhealthy population is defined by not carrying — is arguably its own class, but a new definition requires a non-empty
evidence_prs, which this PR cannot supply before it exists. Worth defining in a follow-up with this PR as the evidence.