Repository navigation
fix(monitoring): retain enrichment LLM cost and usage metrics on the sync scrape (SCA-2067) - #25240
Conversation
…sync scrape (SCA-2067)
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…ode-deepseek-v4/8bc333e2fd05
…g (SCA-2067) Three bookkeeping values drifted on main and fail Backend Unit Tests on every branch. No flag, budget allowance, runtime lever or product default changes. - backend/config/flag_budget.json: count 277 -> 278 to match the existing names list. The merge in 6262a2b (SCA-2012) added names without bumping the count. budget stays 161. - backend/tests/unit/fixtures/usage_month_served_defaults.json: refresh the eight stale all_levers_sha256 values to the current FIRESTORE_READ_LEVERS maps. The only lever that moved is bpp_decision_cache 0 -> 100 from 9daefbf (SCA-1993); usage_month_cache and usage_month_total stay 0/0 (100/100 on backend-sync). - backend/deploy/runtime_env/pending/usage-month-enable-5.patch: refresh the patch context to the current prod.overlay.yaml. The proposal is unchanged: usage_month_cache/total 0 -> 5 for backend, backend-integration and backend-sync-backfill, nothing else. Droppable as one commit if the upstream owners land their own repairs.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cfa29a924e
ℹ️ 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".
| from utils.episodes.metrics import MOMENT_OUTCOMES, MOMENT_TRIGGERS | ||
| from utils.sync.repeat_work_metrics import LLM_FEATURES |
There was a problem hiding this comment.
Move the metric-enum imports to module scope
These function-local imports violate the explicit requirement in backend/AGENTS.md that all imports be at module top level, never inside functions. Move both imports alongside the existing producer imports; those modules are already imported during collection, so deferring these names does not provide additional isolation.
AGENTS.md reference: backend/AGENTS.md:L168-L168
Useful? React with 👍 / 👎.
What changed and why
Retain the enrichment LLM cost/usage families on the
backend-integrationGMP scrape (SCA-2067).backend-integrationruns the enrichment consumer, but the sync collector's__name__keep rule inbackend/deploy/cloud_run_gmp_sync.yamldropped the in-process families a release owner needs to measure the SCA-1960 guardrail regression. SCA-2057 verified the blind spot at 20:56Z 2026-11-13:omi_conversation_llm_calls_total,omi_shaped_agent_input_tokens_total,omi_notes_agent_*andomi_episode_moment_cost_usd_totalwere all absent from the integration scrape whileenrichment_early_abort_totalandenrichment_supersede_streak.*survived.The keep rule now names, explicitly:
omi_conversation_llm_calls_total— attributable calls by boundedfeature/outcomeomi_shaped_agent_input_tokens_total— shaped input tokens byfeature/kindomi_notes_agent_*— runs, forced runs, decisions, tool use, refused/duplicate lookups, repairs, tokens, transport skips, and the tool-calls/turns/estimated-cost/cache-ratio/latency histogramsomi_episode_moment_{cost_usd_total,tokens_total,updates_total}— per-moment cost and its attribution denominatorsExplicit names, not a
notes_agent_.*catch-all, so a new family still needs its own consumer before it is scraped. Episode-moment latency and the skipped-no-client counter stay out: they are not part of the cost readout.The cost families remain estimates — the gateway ledger is authoritative — and an empty vector means "not scraped", never "zero spend".
Product invariants affected
none
CI repair (bookkeeping only, separate commit)
Backend Unit Testsis red onmainitself, so this PR inherited three stale bookkeeping values. They are repaired in one droppable commit (chore(ci): refresh stale flag-budget count and usage-month bookkeeping); no flag, budget allowance, runtime lever or product default changes.backend/config/flag_budget.jsoncount277 → 278 to match the existingnameslist.budgetstays 161.6262a2b82e(SCA-2012) added names without bumping the count.backend/tests/unit/fixtures/usage_month_served_defaults.jsonall_levers_sha256values to the currentFIRESTORE_READ_LEVERSmaps.9daefbfefd(SCA-1993) movedbpp_decision_cache0 → 100.usage_month_cache/usage_month_totalstay 0/0 (100/100 on backend-sync).backend/deploy/runtime_env/pending/usage-month-enable-5.patchprod.overlay.yaml.The pending patch's proposal is unchanged and verified mechanically: its
-/+pairs differ only inusage_month_cache/usage_month_total0 → 5 forbackend,backend-integrationandbackend-sync-backfill.test_qualify_usage_month.pyasserts exactly that, plus that composing the patched tree changes nothing else.The unrelated wall-clock flake in
test_live_replay_provider_pairs.pyis owned by SCA-1994 / PR #25221; no threshold or workflow change here.How it was verified
backend/.venv/bin/python -m pytest tests/unit/test_flag_budget.py tests/unit/test_qualify_usage_month.py tests/unit/test_enrichment_llm_cost_metrics_are_scraped.py tests/unit/test_attach_cloud_run_gmp_sidecar.py tests/unit/test_monitoring_telemetry_contract.py tests/unit/test_timeliness_metrics_are_scraped.py tests/unit/test_enrichment_route.py tests/unit/test_backend_unit_selector_output.py— 486 passed, 1 skipped.backend/.venv/bin/python -m pytest tests/unit/test_render_backend_runtime_env.py tests/unit/test_backend_runtime_env_validator.py tests/unit/test_rendered_deployment_contract.py tests/unit/test_cross_service_deploy_contract.py— 409 passed, 3 skipped.utils.sync.repeat_work_metrics,utils.llm.shaped_agent,utils.llm.notes_agent,utils.llm.notes_agent_serving,utils.episodes.metrics), expands Counter/Histogram suffixes, and asserts each name matches the sync keep rule. It also pins that existing retained families still match, that near-miss and unrelated names stay dropped, thattargetLabels.metadata: [service]and the 15000-sample ceiling are unchanged, and that the added families' worst-case series bound stays under 500.python scripts/failure-class validate --pr-body-file <body>passes.Not verified here: no production read, deploy or scrape. Merged is not live completion — SCA-2026 must include this config in the next real backend-integration release and read nonempty service-attributed vectors for the retained names.
Tests
backend/tests/unit/test_enrichment_llm_cost_metrics_are_scraped.pyis the regression test: it fails if any required family is renamed in the emitter or dropped by the keep rule.test_attach_cloud_run_gmp_sidecar.pycoverage andscripts/select_backend_unit_tests.pyselection are updated so a future config-only edit re-runs the guard.UI evidence
UI-Evidence: none -- monitoring config only.
Cardinality estimate and assumptions
Worst-case bound for the added families, from the emitters' closed enums:
omi_conversation_llm_calls_totalLLM_FEATURES(40) x {completed, failed, other}omi_shaped_agent_input_tokens_totalMount.featureliterals (measured ~10, capped at 20) x {cached, uncached}omi_notes_agent_*countersomi_notes_agent_*histogramsomi_episode_moment_*MOMENT_TRIGGERS(6) xMOMENT_OUTCOMES(10) + tokens (2) + cost (1)Against the existing 15000-sample ceiling this is ~2.7% worst case, so no ceiling change is needed. No per-user, task or content labels are added; every label is a closed enum already emitted in-process.
Rollback
Revert this PR. Allowlist-only change; no runtime behavior, no product state, no flag.
Failure-Class: FC-metric-dropped-by-scrape-allowlist
Closes SCA-2067