Repository navigation
feat(pipeline): operator ledger census, stuck gauges and explain read (C2) - #25084
Merged
Git-on-my-level merged 11 commits intoNov 11, 2026
Merged
Git-on-my-level merged 11 commits into
Git-on-my-level merged 11 commits into
Conversation
… (C2) Add an owner-scoped, aggregate-only census over the C1 in-flight ledger and a one-conversation explain read, both behind the batch worker service-OIDC gate. The census reuses the C1 census_window helper, joins each row to its conversation row for the product home_step.classify predicate, and returns exact stage counts, stuck-past-deadline counts, the Home-visible share on the real-speech denominator, per-end-type counts and Kaplan-Meier p50/p90. It never returns a uid, conversation id, title, transcript or audio path. Publish bounded-label stuck gauges and add three alert rules: stuck rows, a stale census sample and a stale gate receipt. A missing sample is Alerting, never a healthy zero. The C1 read helper gains an opt-in include_key (default off) so the census can join the conversation row; the C1 privacy test is unchanged. The census fails closed on a schema mismatch or a truncated window. Failure-Class: FC-state-deadline-without-reader-exit
…gate The async-blocker gate reads a sync helper imported from a database module as a blocking DB call. The gauges are pure in-memory Prometheus sets, so move them to utils/conversations/pipeline_ledger_metrics.py. No behavior change. Failure-Class: FC-state-deadline-without-reader-exit
The gate's metric is the exact fleet share against the sampled fleet census, so the census reads the ledger's admitted_at collection-group window (the index the C1 PR retained for the global aggregate) instead of one owner. The owner id is read from the document path only to join the conversation row and is never returned. explain stays owner-scoped. Register the new query driver. Failure-Class: FC-state-deadline-without-reader-exit
…pe key Pyright rejects a private cross-module _epoch and an Any end-type key. Define a local epoch helper and coerce the bounded end-type key to str. No behavior change. Failure-Class: FC-state-deadline-without-reader-exit
Add a public epoch alias to the C1 ledger read surface and use it from the census, keeping the changed non-test line count under the cap. No behavior change. Failure-Class: FC-state-deadline-without-reader-exit
- read the fleet window through a documented C1 iter_global_window helper - project conversation reads to a field mask and reduce the transcript to a bool - count each row once in the real-speech denominator - count only terminal rows in the end-type unknown share - report per-end-type p50/p90 and the ledger retention start - report coverage from an exact conversation-created count - reject non-finite windows and slashes in explain inputs; audit the owner hash - fix the gate-receipt alert tier/audience/mute and the stuck no-data state
…nventory The lifecycle field-site ratchet flags the new read-only coverage status, and the GMP shadow inventory must include the three pipeline-ledger alert rules.
Coverage divided ledger rows admitted in the window by conversations created in it, two different cohorts. A row admitted here but created before the window inflated the numerator, and a conversation created at the window edge had no time to be admitted, deflating it. Both sides now count conversations created in the settled window (the last 300s held back), and the residual is reported as excluded_admits/unmatched_creates. The end-to-Home quantiles fell back to admitted_at when end_at was missing while still reporting clock_start=end_at. Rows without end_at are now excluded from the quantiles and counted as clock_fallback_count (per row and per end type) instead of being measured on a hidden basis.
The census coverage payload gained cohort_admits, excluded_admits, settle_seconds and unmatched_creates when coverage moved to a single created-in-window cohort. The lifecycle field-site declaration still listed the old sibling set, so the undeclared/stale guard failed on database/pipeline_ledger_census.py. Declare the actual payload fields; no production code changes.
# Conflicts: # backend/charts/monitoring/alert-rules.json # backend/charts/monitoring/gmp-query-migration-inventory.json
Picks up BasedHardware#25108 (notes prompt version bump) which fixes the main-wide notes prompt-pin test failure.
Git-on-my-level
added a commit
that referenced
this pull request
Nov 11, 2026
…25055) (#25070) ## What changed and why Head: `672d873b5aa2322b1e47a112e5e57fe412e5d1e4` Replacement for #25055 (which replaced #25028) on current `origin/main` `7ebd8450b6e023474cfe3275cf3446b28f3a710f`, carrying the reviewed attention-expiry patch plus the independent-review FIX-FIRST corrections at `Earlier head:` `e1c309b3e047cbfb15933fb0d2246af8829cd459`. Supersedes #25055 because that PR is at its two-push limit and its exact head carries two independent-review FIX-FIRST findings. This replacement starts a fresh branch from current main, carries the same reviewed commits, and fixes both findings: - **Scan bound (finding `77a43d`).** `list_items` no longer streams a user's whole active attention collection. Each query is bounded to `SCAN_LIMIT = 500` documents, and an optional `start_after` cursor lets a caller start from a known document. Expiry transactions therefore run only inside a bounded scan. - **Zero limit (finding `34c935`).** `list_items(limit=0)` (and any non-positive limit) returns an empty list before iterating or appending, instead of returning one item. - **Scan cursor (finding `3d2d9d`).** A full read now pages internally on the last **scanned** document, not the last returned one, so filtering (resolved or expired rows) cannot repeat a window or omit later items. The 500-row query bound and the non-positive-limit early return are unchanged. Carried non-merge commits from the reviewed head: - `329a8b8fa5d` — expiry predicate and initial tests. - `3e0e6f98de1` — transaction fencing, tests, config, registry and documentation. - `7d75d6a5980` — pusher literal config snapshot. The carried patch is otherwise behavior-identical: attention expiry, banked/completed/live-debt guards, and the flag registry. No new product behavior beyond the two fixes. No `.github/`, UI, credentials/IAM, production data/config, or model changes. ### Test-only follow-up (push 3) `1252bca525de` is a test-only assertion under the driver's third-push allowance. The 620-item pagination regression previously ended its first 500-row page on an item that was returned, so a cursor based on the last *returned* item would have passed it too. The test now resolves the last document of the first page and asserts the second page's `start_after` is that document, protecting the last-scanned cursor in `processing_attention._scan_pages`. No product code changed. ### Firestore client seam (Codex P1 `4529060103`, lead2 `f66b9e`) `672d873b5aa2` fixes the review finding that the new expiry path used the legacy module-level `db` proxy, contrary to `backend/AGENTS.md`. `items_ref`, `_scan_pages`, and `list_items` now resolve `get_firestore_client()` at call time and expose an optional keyword-only `firestore_client` parameter; the bounded scan, the conversation/claim reads, and the expiry transaction use that single resolved client. The new expiry tests inject `firestore_client` instead of monkeypatching `store.db` (the module fixture now supplies the same fake client through `get_firestore_client` so the unconverted claim/finish helpers and HTTP route keep working). `db` remains only in the unconverted claim/finish helpers and `pending_conversations`. Pagination, cursor, and expiry-predicate behavior are unchanged; the delta is 15 non-test changed lines in one file plus the test seam. Merge-main resolutions under `1c606e` are unchanged from `71aff3e888f4e`. ### Merge-main resolutions (lead2 `1c606e`) This head is a merge-main resolution under lead2 `1c606e`. `71aff3e888f4e` merges current `origin/main` (`a73632ce0ec9`, which carries C2's operator-ledger census read from #25084) into the branch. Six files conflicted, all additive on both sides and resolved by keeping both: `config/feature-flags.yaml`, `backend/tests/unit/test_verify_pusher_config_references.py`, and all four `backend/charts` listen/pusher values (this PR's `PROCESSING_ATTENTION_NON_RETRYABLE_EXPIRY_ENABLED` and main's `SYNC_RECORD_COVERAGE_WAIT_MEMO`), plus `backend/config/flag_budget.json`, where `count` is reconciled to **271**, equal to the 271 names on the merged head. `backend/tests/support/firestore_query_driver_registry.py` auto-merged and was then checked against both parents: this PR's attention cursor entries (`list_items` with `start_after`, `_scan_pages` covered-by) and C2's census entries (`pipeline_ledger.iter_global_window`, `pipeline_ledger.retention_start`, `pipeline_ledger_census._capture_creates`, `pipeline_ledger_census.census`) are both preserved, and the delta against `origin/main` is exactly this PR's patch (19 files). No product behavior changed; the reviewed patch is unchanged. `Earlier head:` `5ad54d2f0d8f2` merged `origin/main` (`8fa2cbd36487b`, the main-wide notes prompt-pin fix from #25108); that merge was clean and `flag_budget.count` was 270 there. `Earlier head:` `bf6efab1c7bf6` merged `origin/main` (`8659de6ee98d9`, which carries the main-wide messaging flake fix from #25018) into the branch, so the previously red messaging check ran against the fix. Five files conflicted: `config/feature-flags.yaml` and both `backend/charts/backend-listen` listen values (additive env/flag entries on each side, kept both), `backend/config/flag_budget.json` (`count` reconciled to 270, equal to the 270 names on the merged head), and `backend/docs/pending-work.md` (narrative paragraphs from both sides merged, keeping the `HOME_STEP_PROJECTION` text and the bounded-attention text). No product behavior changed; the reviewed patch is unchanged. `Earlier head:` `047de1b18fb7` merged the prior `origin/main` (`75dc53a81df7`) under the same ruling; its only conflict was `config/feature-flags.yaml`. ## Product invariants affected - INV-MEM-4: the runtime change only adds attention expiry configuration; canonical memory consolidation and promotion authority retain their existing configuration. Attention expiry is distinct from Short-term memory disposition. ## Tuning and rollback - `PROCESSING_ATTENTION_NON_RETRYABLE_EXPIRY_ENABLED`: default on. Setting the declared value to `false` and recomposing runtime configuration disables new expiry writes. All backend services and matching listen/pusher charts carry the binding. - `NON_RETRYABLE_ITEM_TTL`: seven days from `created_at`, exclusively for `recovery_structure_unavailable` after retry reconciliation. - `SCAN_LIMIT`: 500 active attention documents examined per query; a full read pages internally on the last scanned document. - Bundle kill switch: `HOME_STEP_PROJECTION` (existing, default on). Turning it off is the L4 rollback. - Rollback is the flag off; no data migration. Expiry is terminal: already-expired documents remain inactive after disabling the switch, and no automatic data restoration is claimed. - L4 success metric: **no processing rows on past days**. ## Verification Fresh checks of head `672d873b5aa2` on m5 through `/Users/dazheng/workspace/omi/bin/omi-heavy run -- ...`, with GCP credential environment variables unset and worktree-local Python 3.11 dependencies: - Attention/pending-work set (13 files, including `test_batch_pipeline_scheduler.py`): **360 passed** across the 13 files run; `test_pending_work.py` alone: **76 passed**, including the strengthened 620-item pagination regression and all expiry tests, now with `firestore_client` injection. - Full query-shape battery `test_firestore_query_shapes.py` (now covering both driver sets): **572 passed**. - Flag budget: **24 passed** (`flag_budget.count` 271 equals the 271 names on the merged head). `test_verify_pusher_config_references.py`: **31 passed**. Runtime-env validator: **206 passed**. Notes prompt-version node `test_llm_input_prompt_version.py`: **6 passed** (including `test_prompt_sources_match_the_pinned_digest[notes]`). Combined five-file run: **839 passed**. - Normal full pre-push hook: **PASS**, 0 failures. - The new cursor assertion was confirmed load-bearing: mutating `_scan_pages` to advance on the second-to-last page item fails it with `[None, 'item-0498'] != [None, 'item-0499']`. Evidence is hermetic; real Firestore contention/SDK retries and deployed behavior are not claimed. ## UI evidence UI-Evidence: none -- backend-only expiry on existing API reads; no client or UI change. ## Failure class Failure-Class: FC-stale-selection-used-as-write-authority
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.
C2: operator ledger census, stuck gauges and explain read
Failure-Class: FC-state-deadline-without-reader-exit
Base and head
75dc53a81df78643cf74c7638350fecc9082ebfc(origin/mainat branch creation; still the merge base).5b4969d40427accbf5f36f0407b85427389ce204(merge oforigin/main8fa2cbd36487b171bf63c98201a8240d38f31b37into85f491a617f1b10106b82b493818ceb35b94b9b5).lane/pipeline-c2-census.1c606e: the two JSON conflicts (alert-rules.json,gmp-query-migration-inventory.json) keep both sides — main's record-token-lease rules plus this PR's three ledger rules,query_consumers271 + 2 + 3 = 276 — with no change to the reviewed behavior.5b4969d40427) picks up#25108(8fa2cbd36487, notes prompt version bump) which fixes the main-wide notes prompt-pin failure. Clean merge, no conflicts; the reviewed patch is unchanged (18 files, +1417 / -4 vsorigin/main).What this is
The C1 in-flight ledger is now readable by an operator-only, aggregate-only
census, plus a one-conversation explain read.
GET /v2/pipeline-ledger/census?start=<epoch>&end=<epoch>reads the ledger'sadmitted_atcollection-group window (the index the C1 PR retained for theglobal aggregate), joins each row to its conversation row for the product
home_step.classifypredicate, and returns exact counts by stage,stuck-past-deadline counts, the Home-visible share on the real-speech
denominator, per-end-type counts and Kaplan-Meier p50/p90, coverage and the
ledger retention start. It never returns a uid, conversation id, title,
transcript or audio path.
GET /v2/pipeline-ledger/explain/{conversation_id}?uid=<owner>returns oneoperator-supplied conversation's ledger transition list. It is an operator
capability (the service-OIDC gate authenticates the invoker SA, not an
individual owner); the owner is an explicit required binding and the audit log
records only a hash of it.
PIPELINE_LEDGER_CENSUS_AUDIENCEandPIPELINE_LEDGER_CENSUS_INVOKER_SA.Unset env means the service is not a census target.
omi_pipeline_ledger_stuck_rows,_stuck_users,_oldest_stuck_age_seconds,_new_stuck_per_hour,_unknown_end_type_share,_refreshed_at_seconds.receipt. A missing sample is
Alerting, never a healthy zero. Thegate-receipt rule is agent-tier (muted for humans), not a page.
The C1 read helper gains one field in its projection (
schema_version) so thecensus can fail closed on a mismatch, plus a documented fleet-global
iter_global_windowand a boundedretention_start. The C1 write path, stagetable and transition rules are unchanged. The Home classifier is the product
home_step.classify; this PR does not fork it.Review resolution (C2 pre-reviews)
Correctness P0:
retention.earliest_admitted_atfrom a bounded global-min read(
pipeline_ledger.retention_start), and the gate compares that to the windowstart. The window's own minimum is no longer the test. The
pass.jsonfixturenow carries a retention start the producer can emit.
Correctness P1:
known real speech, or unknown.
has_speech=True+speech_basis='unknown'counts once.
end_types;unknown_sharedivides byterminal_rows.generated_atisunavailable(UNKNOWN), never fresh.
_num;a missing or
nullvalue is UNKNOWN, never aTypeError.clock_unknown_count / rows > 0.01is PENDING.coveragefrom an exactconversation-created count; the gate enforces
>= 0.995,> 1is a schemamismatch, a small denominator is PENDING, and a missing block is
UNKNOWN coverage_unknown.field. This remains a G3 item for the seal-ramp source, not a C2 claim.
lookback; a different window is
PENDING census_window_mismatch, never PASS.pipeline_ledger.iter_global_window, the documented fleet-global exception.helper.
end_types[type]carriesp50_seconds,p90_secondsand their statuses.ledger-freshness check; the fixture uses the real
ledger_updated_at: nullshape.
declared in the inventory. The textfile is still written by the workspace
gate; wiring it into the prod scrape is a separate ops step.
Custody P1:
generated_atage(
--census-max-age, default 5400s) as well asvalid_until.source.fixture: trueand afixture run refuses to write
--textfile.get_conversation_raw_snapshot(..., field_paths=CONVERSATION_FIELDS)andreduces
transcript_segmentsto a boolean immediately.owner is an explicit required binding, and the log records a hash of the uid.
C2 delta review (fix 2)
coverage.ratiodivided ledger rows admitted in thewindow by conversations created in it, two different cohorts. Both sides now
count conversations created in the settled window
(
COVERAGE_SETTLE_SECONDS = 300), so a row admitted here but created beforethe window no longer inflates the numerator and a conversation created at the
edge has time to be admitted. The residual is reported as
excluded_admitsand
unmatched_creates, never folded into the ratio;basisisconversations_created_in_window.admitted_atwhenend_atwas missing while still reportingclock_start: end_at. Rows withoutend_atare now excluded from thequantiles and counted as
clock_fallback_count(aggregate and per end type);clock_basisisend_at_only.Tests P0 (CI red at the reviewed head):
omi-pipeline-ledger-gate-receipt-staleis nowaudience: agentwithmute_time_intervals: ["omi-tier-silent"]and warning timing._gaugedeclaration pattern is recognized forpipeline_ledger_metrics.py, and the two workspace-emitted gate metrics areallowlisted as external emitters.
or vector(0)and usesnoDataState: Alerting.P2 fixed because trivial: non-finite windows return 422;
uid/conversation_idreject
/; agcloudfailure returns UNKNOWN instead of a traceback;omi_pipeline_ledger_gate_verdictis declared in the metric inventory.Gate contract
The workspace gate runner (
infra/metrics/pipeline-census/gate.py, separateworkspace PR) calls this endpoint, reads the independent sampled Home census and
the C3 canary receipt, and emits one versioned receipt plus a terminal
GATE_*line. PASS only when every required source is fresh, exact and inside threshold;
PENDING,STALE,UNKNOWNandNO_WORKare never PASS. Exit codes matchfleet_gate.sh(0 PASS, 1 FAIL, 2 NO_WORK, 3 PENDING);UNKNOWNprintsGATE_FAIL unknownand exits 1 forramp_controller.py.The metric is: gate output under 1 hour old; agrees with the sampled census
inside its interval for the same window. The receipt carries
schema_version: 1,receipt_id,generated_at,fresh_at,ramp,lookback,source,verdict,reasons,warnings,data_freshness,coverage,home_visible,stuck,new_stuck_per_hour,latency,end_types,canary,sampled_censusandredaction.Size
git diff --numstat 75dc53a81df78643cf74c7638350fecc9082ebfc..HEADoutsidebackend/tests/**:726 changed non-test lines (724 additions, 2 deletions). This fix batch
(
3f1baced51c3..HEAD) is 50 changed lines inbackend/database/pipeline_ledger_census.py(44 additions, 6 deletions), underthe 60-line delta cap. Tests are separate and not counted.
Fix 3 (
95500ea64e26..165fb6815b89) changes 0 non-test lines: it updatesonly the lifecycle field-site declaration in
backend/tests/support/lifecycle_writer_inventory.py(4 added lines) so thedeclared census coverage siblings match the actual payload
(
cohort_admits,excluded_admits,settle_seconds,unmatched_creates).The guard test is unchanged.
Tests
Run with GCP credentials unset, through
bin/omi-heavy run --:test_lifecycle_state_table_writers.py::test_no_undeclared_or_stale_lifecycle_field_builder[database/pipeline_ledger_census.py]:1 passed.
test_pipeline_ledger_census.py,test_pipeline_ledger_routes.py,test_pipeline_ledger_metrics.py,test_pipeline_ledger.py,test_lifecycle_state_table_writers.py,test_firestore_query_shapes.py,test_route_policy_inventory.py,test_route_policy_preflight.py:2411 passed.
.github/scripts/run-pre-push.sh): passed; thebounded gate passed and CI remains the full test authority.
Merge-main resolution (
5b4969d40427) re-ran, with GCP credentials unsetthrough
bin/omi-heavy run --:test_llm_input_prompt_version.py::test_prompt_sources_match_the_pinned_digest[notes]:1 passed (fixed on main by
#25108).test_app_roles_route_census.py:83 passed.
test_firestore_query_shapes.py): 572 passed.test_route_policy_inventory.py,test_route_policy_preflight.py,test_monitoring_alert_rule_contract.py,test_monitoring_alert_backtest.py,test_provision_monitoring_alerts.py):168 passed.
backend unit tests passed).
Rollback
Remove the two routes and the three alert rules. The ledger write path is
unchanged; no flag, no deploy, no data migration.
Not in this PR
omi_pipeline_ledger_admit_total; theendpoint reports an exact conversation-created count with
basis: conversations_created_in_windowuntil the C1a2 live hooks land..github/workflow change.