Skip to content

fix(monitoring): retain enrichment LLM cost and usage metrics on the sync scrape (SCA-2067) - #25240

Merged
Git-on-my-level merged 3 commits into
mainfrom
agent/m1-studio-opencode-deepseek-v4/8bc333e2fd05
Nov 14, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
agent/m1-studio-opencode-deepseek-v4/8bc333e2fd05

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

What changed and why

Retain the enrichment LLM cost/usage families on the backend-integration GMP scrape (SCA-2067).

backend-integration runs the enrichment consumer, but the sync collector's __name__ keep rule in backend/deploy/cloud_run_gmp_sync.yaml dropped 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_* and omi_episode_moment_cost_usd_total were all absent from the integration scrape while enrichment_early_abort_total and enrichment_supersede_streak.* survived.

The keep rule now names, explicitly:

  • omi_conversation_llm_calls_total — attributable calls by bounded feature/outcome
  • omi_shaped_agent_input_tokens_total — shaped input tokens by feature/kind
  • omi_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 histograms
  • omi_episode_moment_{cost_usd_total,tokens_total,updates_total} — per-moment cost and its attribution denominators

Explicit 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 Tests is red on main itself, 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.

File Repair Why it drifted
backend/config/flag_budget.json count 277 → 278 to match the existing names list. budget stays 161. The merge in 6262a2b82e (SCA-2012) added names without bumping the count.
backend/tests/unit/fixtures/usage_month_served_defaults.json Refresh the eight stale all_levers_sha256 values to the current FIRESTORE_READ_LEVERS maps. 9daefbfefd (SCA-1993) moved bpp_decision_cache 0 → 100. usage_month_cache/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. Same SCA-1993 lever change moved the hunk context.

The pending patch's proposal is unchanged and verified mechanically: its -/+ pairs differ only in usage_month_cache/usage_month_total 0 → 5 for backend, backend-integration and backend-sync-backfill. test_qualify_usage_month.py asserts exactly that, plus that composing the patched tree changes nothing else.

The unrelated wall-clock flake in test_live_replay_provider_pairs.py is 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.
  • The new guard derives every sample name from the producer registrations (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, that targetLabels.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.py is 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.py coverage and scripts/select_backend_unit_tests.py selection 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:

Family Bound Assumption
omi_conversation_llm_calls_total 120 LLM_FEATURES (40) x {completed, failed, other}
omi_shaped_agent_input_tokens_total 40 low-cardinality Mount.feature literals (measured ~10, capped at 20) x {cached, uncached}
omi_notes_agent_* counters 108 9 counters x closed label enum capped at 12
omi_notes_agent_* histograms 70 bucket count + 2 per histogram
omi_episode_moment_* 63 MOMENT_TRIGGERS (6) x MOMENT_OUTCOMES (10) + tokens (2) + cost (1)
Total ~400 realistic ~250 series per instance

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

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T23:23:16.921700Z cfa29a9 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.

…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.

@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: 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".

Comment on lines +182 to +183
from utils.episodes.metrics import MOMENT_OUTCOMES, MOMENT_TRIGGERS
from utils.sync.repeat_work_metrics import LLM_FEATURES

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 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 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 1a7baa6 into main Nov 14, 2026
74 of 76 checks passed
@Git-on-my-level
Git-on-my-level deleted the agent/m1-studio-opencode-deepseek-v4/8bc333e2fd05 branch November 14, 2026 00:02
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