Skip to content

fix(stt): make the free-allowance watch see every route (SCA-1750) - #25318

Merged
Git-on-my-level merged 5 commits into
mainfrom
lane/allowance-coverage
Nov 14, 2026
Merged

Git-on-my-level merged 5 commits into
mainfrom
lane/allowance-coverage

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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:

Path 24h observations Problem
live_open 8,022 would_allow, 5,334 usage_unavailable about 40% of free live opens can't read usage
prerecorded 3,055 would_refuse, all reason identity_unavailable none of these are allowance refusals
batch / upload / sync none counters are emitted, then dropped before GMP

No 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

  1. Usage epoch on prod listen and pusher. The Cloud Run billing gate rebuilds and trusts monthly_usage_totals docs under c2fs_20261026_r1 (config(firestore-reads): guard flag-off 7 levers 100->0 (backend-sync 5xx re-escalation, WQ31) #24194, 0d18df1). Prod backend-listen and pusher read the same doc with v1, so the watch raised ValueError('unverified monthly usage') and reported usage_unavailable.
    • The epoch is now aligned in the prod overlay, the regenerated runtime_env.yaml and both prod chart values.
    • FIRESTORE_READ_LEVERS stays at usage_month_*=0 on GKE, so no legacy reader starts trusting monthly totals.
    • Dev, jobs and desktop-backend are unchanged.
    • The served-defaults snapshot and the render test record the new pair.
  2. unbound decision. observe_unbound used to emit would_refuse when the call had no uid: speaker-sample verification, recovery recognizers and the transcription shadow. It now emits unbound. Lease reason identity_unavailable is unchanged.
    • Calls that have a uid but no bound operation still emit would_refuse / billing_scope_unavailable.
    • Threading the uid into those callers is required before enforcement, and is left for a follow-up.
  3. Metrics reach GMP.
    • omi_free_allowance_.* is added to the explicit keep rule in cloud_run_gmp_sync.yaml (backend-sync, backend-sync-backfill, backend-integration).
    • The batch worker's private /metrics registry now registers the four allowance collectors, so batch_gpu observations 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 v1 in the two prod chart values, then regenerate. The observer kill switch, STT_FREE_ALLOWANCE_WATCH_ENABLED=false, is unchanged.

Verification

  • From 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.
  • After serving, readback is the same GMP query: usage_unavailable on live_open should fall sharply, unbound should replace the prerecorded would_refuse, and batch_gpu, sync and batch_provider series should appear.

Product invariants affected

  • INV-MEM-4: not affected. This change touches no memory promotion path. The citation is only path-triggered (backend Python).

Failure class (fixes)

Failure-Class: FC-metric-dropped-by-scrape-allowlist

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

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

chatgpt-codex-connector Bot commented Nov 14, 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-14T19:26:17.067280Z 16e6c09 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: 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',

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

Git-on-my-level and others added 4 commits November 15, 2026 02:21
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]>
@Git-on-my-level
Git-on-my-level merged commit 64797fe into main Nov 14, 2026
71 of 73 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/allowance-coverage branch November 14, 2026 21:28
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