Skip to content

feat(observability): add bounded audio silence census - #25026

Closed
Git-on-my-level wants to merge 9 commits into
mainfrom
lane/silencecensus
Closed

Git-on-my-level wants to merge 9 commits into
mainfrom
lane/silencecensus

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

What / why

Add omi_audio_silence_census{state,source}, a read-only 24-hour census of unique users with:

  • app activity but no audio evidence;
  • app activity and audio evidence; or
  • audio evidence without app activity.

state is closed to app_active_no_audio, app_active_with_audio, audio_no_app_activity; source is closed to omi, desktop, other, for at most nine series. UIDs are held transiently for deduplication. The sampler fetches the complete record_upload_sessions map to test presence, so its keys and lease metadata also enter worker memory transiently; neither UIDs nor session metadata are labels or log text. A user's source is the latest observed source-bearing row. Batch jobs count as app and audio evidence; upload/received conversation stamps and recent sync_reprocess_outbox rows count as audio evidence.

The sampler rides the existing lifecycle observation in QueueMetrics._refresh on the batch/pusher metrics path, once per six hours per observer. No Cloud Run service, scheduler, account mutation, GCS listing, or unindexed collection-group scan is added.

Each run reads at most 300 indexed rows from each source. Full pages are partial. A shared five-second deadline bounds the sample; each Firestore RPC receives a timeout capped by the remaining time (at most ten seconds) and can leave a partial lower-bound sample. Candidate COUNT(1) existence aggregations fill only missing app/audio evidence. The hard 4,000-read budget includes returned documents, one unit per capped source-page query (its single index-entry batch or minimum empty-query charge), and each existence aggregation limited to one match. The sampler reserves these units before issuing queries and stops with partial=1 when the budget is exhausted. Unseen upload-session maps make no-audio classification impossible, so those users are omitted rather than reported as false silence. Under saturation, source attribution is also only for the latest source-bearing row actually read; users with no source-bearing row fold to other. omi_audio_silence_census_partial=1 marks all counts as lower bounds on source saturation, unclassifiable evidence, or budget exhaustion; read exceptions preserve prior values and freshness.

Product invariants

None. Observation only: no API, product behavior, audio custody, admission, repair, or user lifecycle mutation.

Tuning

  • Before: no audio silence census (new: 3 metric families, at most new: 9 census series plus partial/freshness).
  • Cadence: new: 21600 seconds per observer.
  • Input pages: new: 300 rows per source, three sources, indexed and key-name ordered.
  • Candidate evidence: new: COUNT(1) only when a source page could hide relevant stamps.
  • Read ceiling: new: 4000 accounted reads per observer run, including returned documents, each capped source-page query charge, and one-match COUNT(1) checks; the sampler reserves charges before reads and stops with partial=1. Zero-before-first-sample and exception paths retain no fabricated healthy value.
  • Firestore indexes: three generated declarations (collection-group 24h conversation window, received-audio lookup, and outbox owner window). The outbox owner index now starts with dormant == false, followed by uid and first_pending_at, matching the per-UID fallback query. The single-field outbox and batch-job windows are auto-served and are deliberately not declared. The composite indexes must be READY before deploying the emitter. No production access or index apply was performed.
  • Alerts/dashboards: no threshold added while a baseline is established. The metric is registered in metric-inventory.prod.json; the runbook query in lifecycle-alarms.md now excludes observations older than 12 hours before taking the replica max (two six-hour sampling cycles). Replica values aggregate with max, never sum, so pods do not multiply the census.

New states / exits

These are rolling observations, not persisted lifecycle phases:

  • app_active_no_audio: exits when batch-job, received-audio, upload-session, or outbox evidence appears, when app activity ages out, or when evidence becomes incomplete and the user is unclassified.
  • app_active_with_audio: exits when activity/audio evidence ages out; becomes audio_no_app_activity if only app activity ages out.
  • audio_no_app_activity: exits when conversation/batch activity appears or audio evidence ages out.

Disable/rollback exit: AUDIO_SILENCE_CENSUS_ENABLED=false stops subsequent reads and leaves previous observations to age out.

Verification

  • Final pre-push gate on acaff7390a671dbb213a2c1bbcc6109b99f516b9: bounded pre-push gate passed, including all 51 manifest checks, Firestore index guard, typecheck (0 errors), 1,992 backend unit tests, 7 real PromQL scenarios, and pinned formatting.
  • Targeted regression/query-shape selection: 679 passed. Coverage verifies dormant outbox rows do not restore audio evidence, active outbox index/query alignment, already-verified users survive deadline and read-budget stops, and no redundant fallback lookup is made for those users.
  • No production or remote development data was read. No emulator or live-service verification was run.

Tests

Coverage includes user deduplication, three-state/nine-series classification, latest-observed-source attribution, bounded candidate joins, unseen upload-session refusal, hard budget exhaustion, six-hour cadence, and false-kill-switch behavior. Firestore driver setup exercises prod/dev query shapes and candidate aggregation branches. The final regressions also cover dormant outbox rows, retained verified classifications at deadline/budget boundaries, and freshness filtering in the runbook query.

UI-Evidence

none -- backend change only.

Failure-Class

Failure-Class: none

Rollback

Set AUDIO_SILENCE_CENSUS_ENABLED=false. This stops future census reads without affecting capture, audio custody, admission, repair, or user data. Existing gauges age out; remove the emitter if immediate disappearance is required. Merge rollback does not provision indexes; any prebuilt additive indexes require the normal separate human cleanup decision.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T14:51:52.873723Z
We couldn’t complete this review. Comment @codex review to try again.
acaff73 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 42fc1fe2e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

self.record_pending.refresh(now, lambda: record_pending(store.client, store.namespace, now))
self.nojob.refresh(now, lambda: nojob(store.client, store.namespace))
if kill_switch('AUDIO_SILENCE_CENSUS_ENABLED', log=False):
self.audio_silence.refresh(now, lambda: audio_silence_sample(store.client, store.namespace, now))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep the census off the queue-metrics sampling critical path

When all three source pages saturate, this synchronous call can hold up the worker's queue-metrics sampler for longer than its freshness window. Exercising sample() with 300 distinct users per source produces 2,400 sequential aggregation RPCs; even 30 ms per RPC exceeds 60 seconds, and there is no overall deadline. backend/diarizer/batch_pipeline_runtime.py::supervise awaits this refresh before scheduling another sample, while backend/charts/batch-pipeline-worker/prometheus-adapter-rules.yaml rejects queue and sampler observations older than 60 seconds. Consequently, a saturated census can make autoscaling signals unavailable, particularly when replicas start together; the HTTP metrics caller also waits for the entire census. Run it independently of the queue sampler, or impose a short overall deadline that returns a partial observation.

AGENTS.md reference: backend/AGENTS.md:L275-L275

Useful? React with 👍 / 👎.

Comment on lines +163 to +165
client.collection('sync_reprocess_outbox')
.where(filter=FieldFilter('first_pending_at', '>=', after))
.where(filter=FieldFilter('first_pending_at', '<=', current))

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 Badge Exclude settled outbox receipts before sampling the page

When a first summary completes, FirestoreEnrichmentOutbox.ack() in backend/database/outbox_firestore.py retains a dormant receipt with uid=None and its original first_pending_at. This query includes those normal receipts, and remember(None) marks the entire census partial. A single recently settled receipt therefore prevents a complete observation even when every source fits within its page; 300 receipts can also consume the entire outbox page and hide actual user evidence. This is reproducible with one dormant receipt and no other rows: the sampler returns partial=True. Exclude settled receipts in the indexed source query rather than treating their intentionally cleared identifiers as incomplete evidence.

Useful? React with 👍 / 👎.

Firestore auto-serves same-direction field+__name__ single-field
composites, so the outbox and batch-job window declarations were
redundant and failed test_firestore_index_config. Collection-group
single-field scans are not auto-served, so the conversation window now
pages newest-first and declares the real opposite-direction composite.

Failure-Class: FC-redundant-single-field-composite-index

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d7df513509

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +87 to +88
its baseline; its runbook query is `max by (state, source)
(omi_audio_silence_census) and on() (omi_audio_silence_census_partial == 0)`.

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 Badge Filter partial observations before aggregating replicas

When one observer has a complete sample and another has a partial sample, this query still includes the partial observer's counts: max by (state, source) removes replica identity before and on() checks whether any observer reports partial == 0. Consequently, the documented complete-only query can return values from an incomplete observation. Match each census series to its own observer's partial marker before applying max by (state, source) so a complete replica cannot validate another replica's partial counts.

Useful? React with 👍 / 👎.

Omi Control Codex (Sol) and others added 7 commits November 14, 2026 10:25
…-luna/1e721eb6e5b5

# Conflicts:
#	.github/firestore-collection-budgets.json
#	backend/config/flag_budget.json
#	backend/config/policy/kill_switches.py
#	backend/tests/unit/test_flag_budget.py
#	backend/utils/batch_pipeline/metrics.py
#	config/deployment-setting-classification.json
#	config/feature-flags.yaml
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @Git-on-my-level 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

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