Repository navigation
fix(stt): make the free-allowance watch see every route (SCA-1750) - #25318
Conversation
The watch-only allowance observer is serving, but 24h of prod GMP showed three blind spots that block any enforcement decision: - live_open: ~40% of free opens reported usage_unavailable. Prod listen/pusher read monthly_usage_totals with epoch v1 while the Cloud Run billing gate rebuilds and trusts c2fs_20261026_r1, so listen rejected the trusted doc. Align the epoch on prod listen/pusher (chart + manifest); their read levers stay 0, so no legacy reader changes. - prerecorded: every observation was would_refuse/identity_unavailable from calls with no account (speaker samples, recovery recognizers). Report them as `unbound`, not as allowance refusals. - batch/upload/sync: counters were emitted then dropped. Add omi_free_allowance_* to the sync GMP keep rule and register the collectors on the batch worker's private /metrics registry. Failure-Class: FC-metric-dropped-by-scrape-allowlist Co-Authored-By: Claude Opus 5.5 <[email protected]>
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8d9aa9e34
ℹ️ 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".
| path, | ||
| provider, | ||
| 'would_refuse', | ||
| 'unbound' if reason == 'identity_unavailable' else 'would_refuse', |
There was a problem hiding this comment.
Add the required transcription pipeline change note
This changes transcription-watch decision semantics from would_refuse to unbound, aligns production usage epochs, and expands metric export, but the commit adds no note under backend/docs/listen_pusher_pipeline/changes/. backend/AGENTS.md explicitly requires a same-PR change note for transcription changes. Add a dated note covering the new decision semantics, rollout/rollback state, and verification evidence so operators interpreting the allowance reconciliation window can distinguish pre-change and post-change observations.
AGENTS.md reference: backend/AGENTS.md:L164-L164
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Added in 16e6c09: backend/docs/listen_pusher_pipeline/changes/2026-11-15-free-allowance-watch-coverage.md (decision semantics, epoch alignment, metric export, reading series across the serving revision, rollback).
Records the unbound decision semantics, the listen/pusher epoch alignment, the metric export fix, how to read series across the serving revision, and rollback, as backend/AGENTS.md requires for transcription changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…'s policy imports Importing utils.stt.allowance_watch into the batch worker made the cross-service deploy contract treat the worker as a reader of BATCH_PIPELINE_UPLOAD_COALESCING_ENABLED (reader-split, Backend unit shard 2/8). Move the four counters into utils/stt/allowance_metrics.py, which imports only prometheus_client; allowance_watch re-exports them, and the worker imports the metrics module. Failure-Class: FC-metric-dropped-by-scrape-allowlist Co-Authored-By: Claude Opus 5.5 <[email protected]>
allowance_session reads watch.SETTLED_SECONDS, so the import is a re-export; the backend typecheck rejected it as unused (reportUnusedImport). Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review (Luna, FIX on d63d6be): after prod listen/pusher move to the c2fs epoch, monthly_usage_totals docs that listen previously rebuilt under v1 fail verification with a plain ValueError, which the watch reports as usage_unavailable and never rebuilds (it rebuilds only on UsageBaselineNotReady). A doc that is ready under a different valid epoch is a missing baseline for this host, so raise UsageBaselineNotReady and let the existing fenced source scan re-prove it. Corrupt totals and an invalid configured epoch still raise ValueError. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
Why
SCA-1750 is meant to close free-tier allowance leaks. Its watch-only counter (#25155) is serving in production, but a 24h GMP read (ro-prod, aggregates only, to about 2026-11-15T01:40Z) showed it can't judge most free spend:
live_openwould_allow, 5,334usage_unavailableprerecordedwould_refuse, all reasonidentity_unavailableNo enforcement decision can be made until the counter sees these routes. David ruled on 2026-11-15 that the counter is validated by sampling free users, and this fix comes first.
What changes
monthly_usage_totalsdocs underc2fs_20261026_r1(config(firestore-reads): guard flag-off 7 levers 100->0 (backend-sync 5xx re-escalation, WQ31) #24194, 0d18df1). Prodbackend-listenandpusherread the same doc withv1, so the watch raisedValueError('unverified monthly usage')and reportedusage_unavailable.runtime_env.yamland both prod chart values.FIRESTORE_READ_LEVERSstays atusage_month_*=0on GKE, so no legacy reader starts trusting monthly totals.unbounddecision.observe_unboundused to emitwould_refusewhen the call had no uid: speaker-sample verification, recovery recognizers and the transcription shadow. It now emitsunbound. Lease reasonidentity_unavailableis unchanged.would_refuse/billing_scope_unavailable.omi_free_allowance_.*is added to the explicit keep rule incloud_run_gmp_sync.yaml(backend-sync, backend-sync-backfill, backend-integration)./metricsregistry now registers the four allowance collectors, sobatch_gpuobservations are exported.There is no change to serving admission, prices, plans or user-visible behaviour, and no data is deleted.
Rollback
Revert this PR, or delete the two overlay lines and restore
v1in the two prod chart values, then regenerate. The observer kill switch,STT_FREE_ALLOWANCE_WATCH_ENABLED=false, is unchanged.Verification
backend/:pytest tests/unit/test_free_allowance_metrics_are_scraped.py test_free_allowance_session.py test_free_allowance_watch.py test_free_allowance_leases.py test_qualify_usage_month.py test_backend_runtime_env_validator.py test_render_backend_runtime_env.py test_verify_pusher_config_references.py test_batch_pipeline_runtime.py test_quiet_check_metrics_are_scraped.py test_attach_cloud_run_gmp_sidecar.py test_monthly_usage_totals.py test_fsr_s4_caches.py: 876 passed.scripts/check_feature_flag_registry.py: OK, after regenerating the registry doc.usage_unavailableonlive_openshould fall sharply,unboundshould replace the prerecordedwould_refuse, andbatch_gpu,syncandbatch_providerseries should appear.Product invariants affected
Failure class (fixes)
Failure-Class: FC-metric-dropped-by-scrape-allowlist
🤖 Generated with Claude Code