Skip to content

fix(metrics): restore Firestore tier export and GKE service identity - #25079

Merged
Git-on-my-level merged 3 commits into
mainfrom
lane/fsattrib
Nov 11, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
lane/fsattrib

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Current head e339859141015a9ab6ba247529eef7d678dbd4fd: a merge of main (including #25083) into the earlier head 3521802cb0e40e12e05232c9676c8355423c92eb; the reviewed code is unchanged. CI at the current head: 37 passed, 21 skipped, 0 failed (shard 8 passed on rerun attempt 2).

Restore Firestore tier-counter export on Cloud Run sync and attach bounded service identity to GKE read metrics. The measured QUERY coverage residual remains unresolved.

Head: lane/fsattrib (3521802cb0e40e12e05232c9676c8355423c92eb).

Failure-Class: FC-metric-dropped-by-scrape-allowlist

Product invariants affected: none (telemetry only).

Root causes and investigation:

  • (a) QUERY undercount remains unresolved. backend/database/firestore_document_probe.py:878 wraps the SDK stream and :890 records each consumed snapshot once. Real SDK conversion tests cover stream/get, transaction.get(query), collection streams/groups, limit, limit_to_last, offset, async queries and batched gets with duplicate requested references. They pass against the main SDK and the batch-worker-pinned SDK. Class installation covers raw clients created later in an instrumented process (:1115, backend/database/_client.py:104); caller overflow folds labels rather than dropping amounts. Projections are counted, no product caller uses list_documents, and SDK get_all uses one batch RPC. The strongest remaining hypothesis is early termination / partial stream consumption: the server can bill results never consumed by the SDK caller. Concrete early breaks include backend/database/client_telemetry.py:66 and backend/database/conversations.py:3340. This is a coverage boundary, not a proven explanation of the fleet gap. The partial-stream test preserves laziness; no streams are drained. Aggregation index-entry costs remain estimates, and processes that never install the probe plus non-Python readers remain separate boundaries. No Explain RPC or read-behavior change.
  • (b) _record() increments tier and caller counters by the same amount (backend/database/firestore_document_probe.py:600, :608). Tier resolution catches errors and falls back to bounded unattributed (backend/database/firestore_tier_context.py:127). The confirmed loss is downstream: the sync keep regex at backend/deploy/cloud_run_gmp_sync.yaml:53 previously retained only caller/origin variants and dropped omi_firestore_billed_reads_total. Keep the base and both attribution variants. Also retain omi_read_cache_shadow_total: usage_month shadow samples execute on backend-sync/backend-integration. Raise the sync sample cap to 15000, matching the sidecar profile and its whole-scrape-drop rationale; the extra tier family needs headroom. Tests pin both caps and pass real exposition through both keep regexes, including shadow samples and missing/invalid tiers.
  • (c) DD_SERVICE names the JSON ledger (backend/database/firestore_document_probe.py:185), not Prometheus samples. Static service_name pod labels and GMP PodMonitoring targetLabels.fromPod now cover backend-listen, pusher, batch-pipeline-worker and record-seal-worker; existing in-cluster Prometheus jobs copy the same label. Dev/prod values retain their existing pattern. The sync-backfill-worker pilot also carries the label and GMP mapping for when it deploys (its chart has shared values, no stage overlays). The production seal worker is intentionally idle (backend/charts/batch-pipeline-worker/prod_omi_batch-pipeline-worker_values.yaml:136); its reader is constructed only when enabled (backend/utils/batch_pipeline/record_seal_worker.py:228). Both probe collectors are already registered in the private registry (:25). This explains absent lazy read series for the checked-in configuration; no serving deployment was inspected.

Review fixes and operational implications:

  • Keep the seal-repair and seal-sweeper CronJob pod service_name labels for logs only. These pods are not scraped and gain no metric export from this change. Alloy retains service_name (backend/charts/monitoring/alloy/prod_omi_k8s_monitoring_values.yml:29).
  • Guard optional batch-pipeline-worker podLabels with Helm with; renders accept null and empty-map overrides. Wire the attribution chart tests into the monitoring area of select_backend_unit_tests.py, with regression coverage, and skip Helm-dependent tests when shutil.which('helm') is absent.
  • Known conflict with open fix(record): producer custody token lease and heartbeat (option A), default off #25018: both edit the sync keep-regex line and the batch-pipeline-worker base-values anchor after enabled. Whichever lands second must resolve/rebase while retaining both the Firestore firestore_billed_reads(_by_(caller|origin))?_total alternation and fix(record): producer custody token lease and heartbeat (option A), default off #25018's record_token_late_append_total|record_token_lease_.*, as well as read_cache_shadow_total. This branch is not rebased onto unmerged fix(record): producer custody token lease and heartbeat (option A), default off #25018.
  • Dashboard legend change: the existing label_replace expressions at backend/charts/monitoring/dashboards/general/omi-core-features.json:2573 and backend/charts/monitoring/gmp-query-migration-inventory.json:2677 synthesize in-cluster only for an empty service_name. Once labels arrive, those legends become backend-listen / pusher. GKE read series are backend-listen / pusher / batch-pipeline-worker (and record-seal-worker when active), not backend; service_name="backend" selectors continue to cover only the Cloud Run service.
  • The batch-pipeline-worker Deployment uses Recreate. Changing its pod labels restarts all its pods together at the next chart rollout; cl2-deploy should schedule it. This PR does not deploy anything.

Expected effect: restore tier/caller export parity, expose existing sync cache-shadow samples and name GKE read series. No numerical reduction in the native-minus-by_caller unattributed share is claimed: QUERY coverage remains unresolved. No reads are added, removed or drained. Metric names, bounded tiers and caller limits remain; no uid label, runtime flag, credentials, .github change or deployment.

Validation through omi-heavy, offline (each file in its own pytest process):

  • cd backend && .venv/bin/python -m pytest <file> -q: test_firestore_attribution_export.py 42 passed, test_firestore_attribution_charts.py 11 passed, test_backend_unit_selector_output.py 4 passed, test_batch_pipeline_chart.py 101 passed, test_sync_worker_runtime.py 13 passed — 171 passed total.
  • With PATH=/usr/bin:/bin, the attribution chart suite reports 2 passed, 9 skipped, exercising the missing-Helm guard.
  • Prior probe/worker/repair-focused validation passed 467 tests; the probe plus SDK/export suites also passed 169 tests against the batch worker's pinned SDK. No dependencies changed.

make preflight and scripts/pr-preflight --pr-body-file /tmp/firestore-lead-m1/fsattrib-pr-body.md: 48 checks passed each on this head. The single prescribed push passed its bounded gate: 171 tests across all five changed test files, backend typecheck (0 errors, existing warnings), formatting and the shared PR contracts (48 passed). Current-head CI finished: all other applicable checks passed, including seven unit shards, slow guardrails, both gauntlets, hermetic backend E2E, static contracts, formatting, hygiene and metadata. The only red checks are unit shard 5 and its dependent unit-suite aggregate. The shard log confirms the known tests/unit/test_messaging_review_fixes.py:34 race: test_optional_load_failure_returns_plain_window[failure2] expects one fallback notice and receives two. #25083 has now merged separately; this branch does not contain that fix. No retry, unrelated messaging edit, history rewrite or second push was made. The complete PR changes 102 lines outside tests, below the 400-line cap. The known shard-5 messaging race is fixed separately by #25083; no unrelated messaging changes are included here. Rollback: revert this PR's commits to restore the prior scrape and pod-label configuration.

View guided diff Turn on auto-fix

🤖 Generated with Claude Code

Failure-Class: FC-metric-dropped-by-scrape-allowlist
Failure-Class: FC-metric-dropped-by-scrape-allowlist
Git-on-my-level added a commit that referenced this pull request Nov 11, 2026
… CI load (#25083)

The optional-load failure test can count two degraded fallbacks under CI
load: its intended summary-load exception plus a digest timeout. Both
reads are in-memory fakes, but the test still dispatches them through
real workers while `PREPARE_SECONDS=0.15` bounds both tasks. This
test-only change executes the fakes through a test-local async helper
and retains the assertion that exactly one degraded fallback is
produced. Production code, deadlines, and the separate timeout /
real-executor regressions are unchanged.

Current head: `7efee81725d9cfa31a72d7f663a0a21a5fe77800`.

The trigger is the deterministic LPT shard reshuffle when files are
added to the suite. Every test file runs in a separate pytest process,
so this is a pre-existing scheduling race rather than cross-file state
leakage. The CI trace contains `summary_load ValueError` followed by
`digest TimeoutError`, matching the `assert 2 == 1` failure. An isolated
diagnostic that delays only the digest worker by 200ms reproduces the
same failure before the change and passes afterward.

This independent fix unblocks #25077 and #25079. It adds no flags and
has no deploy or index prerequisite. Rollback is a normal revert of this
test-only commit.

Validation through `bin/omi-heavy`:

- The CI `backend/test.sh` runner, four workers and per-file process
isolation, passed 54 tests across `test_messaging_review_fixes.py`,
`test_shaped_context_prefetch_safety.py`, and
`test_shaped_chat_context.py`.
- All 11 messaging review tests pass with the diagnostic digest-worker
delay still injected.
- `OMI_PR_BODY_FILE=<body> make preflight` passed all 35 selected
checks.
- The same helper previously passed the exact 347-file shard-5 plan from
#25077's merge tree, with runner exit 0; that replay did not naturally
reproduce the messaging race on this host.

Commands from `backend/`:

```sh
~/workspace/omi-workspace/bin/omi-heavy run -- env BACKEND_UNIT_TEST_FILE_LIST=/tmp/firestore-lead-m1/msgflake-test-files.txt BACKEND_PYTEST_WORKERS=4 bash test.sh
~/workspace/omi-workspace/bin/omi-heavy run -- env PYTHONPATH=/tmp/firestore-lead-m1 .venv/bin/python -m pytest -p heldpoll_delayed_digest tests/unit/test_messaging_review_fixes.py -q
```

Only `backend/tests/unit/test_messaging_review_fixes.py` changes: 8
additions and 2 removals. The async helper and patches are scoped to
each parametrized invocation and restore automatically.

## Product invariants affected

none

Failure-Class: none

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/25083?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/25083?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F25083&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. -->
@Git-on-my-level
Git-on-my-level merged commit 4e9c704 into main Nov 11, 2026
71 of 73 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/fsattrib branch November 11, 2026 02:29
MichaelC001 pushed a commit to MichaelC001/omi that referenced this pull request Nov 11, 2026
… CI load

Both mocked reads still used real workers under the shared 150ms prepare
budget. A delayed digest worker emits a second degraded fallback alongside
the intended summary-load exception, making len(notices) == 1 race CI load.

Use a test-local async helper to execute the in-memory reads directly and
retain the single-fallback assertion. Separate deadline and real-executor
regressions keep their existing behavior. Production code is unchanged.

Backend files run in separate processes. New files reshuffle the LPT shard
schedule and expose this pre-existing timing race; they do not leak state.
This independent test-only fix unblocks BasedHardware#25077 and BasedHardware#25079.

Failure-Class: none
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