Repository navigation
SCA-2012: store the fresh result class and publish the delivery guard - #25224
Conversation
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. |
…-sol/sca-2012-r1 # Conflicts: # backend/config/flag_budget.json
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: adb514d23d
ℹ️ 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".
| if self.metrics: | ||
| # Explicit reconcile bypasses the periodic lease; the guard never does. | ||
| if self._leads(True): | ||
| self.metrics.fresh_guard.refresh(self.store) |
There was a problem hiding this comment.
Keep fresh-guard count RPCs off the metrics request path
When projection-pump and read-only-metrics modes are disabled, backend/routers/batch_pipeline.py::metrics awaits service.reconcile_async(periodic=True), which reaches this synchronous refresh on the maintenance leader. Consequently, a scrape that encounters a due sample waits for both Firestore count RPCs (each with a 10-second timeout), rather than just collecting cached gauges. Slow count queries therefore delay the entire metrics response and can cause scrape timeouts, losing unrelated metrics as well. The collector concurrency test bypasses this HTTP path, so it does not establish that actual scrapes avoid waiting. Run sampling from supervision independently of scrape-triggered reconciliation.
Useful? React with 👍 / 👎.
#25224 and #25226 each added a name; the merged file declared 277. Co-Authored-By: Claude Fable 5.2 <[email protected]>
SCA-2012's live samples exceeded the 120-second age budget after PR #25224 deployed. Sampling ran only at the start of general maintenance, and the serving supervisor waited for that entire pass before ticking again. A deterministic test holds cleanup in flight for 180 simulated seconds and reproduces the stale gauge. Current integration head: `fdfb46738ae61a513eb1f081bcf58131e1b5a918`, a normal merge of main `d1fb900e5b` into the previously reviewed commit `8def546556dd20f13f6a835d75a1be13550d10a2`. This incorporates the CPU-test repair #25312 (merge `8614ee4cad335ca13da7df9e17875012f3985077`) that blocked the previous candidate. The merge completed without conflicts or additional source edits. Main's allowance-hold maintenance and all other current-main changes are retained; the fresh guard still has its independent timer and stored-class count cohort. Luna independently reviewed this current integration commit and posted REVIEW: SHIP on SCA-2012 at 2026-11-15 00:20:47 UTC. The subsequent merge-stage receipt confirms all eight backend shards, emulator proofs, and the hermetic merge gate passed on this commit. The guard now has an independent 20-second supervised timer on the shared DB executor, using the same maintenance leader lease. All callers retain the existing nonblocking overlap lock and 60-second count-start cadence. The timer is owned by the serving runtime and stopped with it; projection-pump-only instances do not run it. Query failures and stale samples still remove counts/ratio, and scrapes do no IO. This establishes and corrects a scheduling defect; raw production ages alone do not prove it was the sole cause of every breach. The new count-only `backend/scripts/fresh_guard_cohort.py` replaces the prescribed external `projection_cohort.py` for this acceptance check: it selects stored `fresh_capture == True` and the inclusive commit window, not fresh_first/capture age. It requires the matching read-only tier. A sample-timestamp gauge exposes the exact pre-RPC window anchor for equivalent comparisons; it expires with the counts. No documents, audio or content are read, and failed/empty windows have no healthy ratio. Failure-Class: new New class: FC-observer-cadence-coupled-to-maintenance. Prevention is independent bounded supervision while preserving leader election, overlap coalescing and sample expiry. The reusable regression artifact stalls real maintenance while exercising the real guard on a deterministic clock. Stored-state contract: no field/writer change. `OrderedMerge.commit_next` remains the sole result-class writer. Runtime reader remains the maintenance-leader guard; the only added semantic reader is the count-only acceptance CLI. Existing merge/projection/discovery/drain/enrichment/recovery/shadow/simulator/worker readers retain their semantics. No provider, hold/release, predecessor, privacy, erasure, hard-3, alert or index-shape change. Cost: unchanged count pair, roughly one read per 1,000 index entries per count (minimum two reads per pair). The timer adds up to three existing maintenance-lease checks per minute per serving replica. Each independent acceptance comparison costs a separate count pair. Its new query site has a declared planning envelope of 200 reads/comparison at 100,000 rows and 4,000/day at 20 comparisons; these are estimates, not runtime caps or booked savings. No new collection or lease role. Validation on `fdfb46738ae61a513eb1f081bcf58131e1b5a918`: - Nine isolated files through `backend/test.sh` under `bin/omi-heavy`, offline/simulator-only: 359 passed. Covers the stalled-maintenance regression, count comparison CLI, serving/config, fresh merge and provider membership, delivered-share contract, and repaired erasure deployment tests. - All 42 local preflight checks passed, including the Firestore index guard's 591 query-shape tests. - Normal bounded pre-push gate passed; no hooks bypassed. - Luna's exact-commit REVIEW: SHIP: 2026-11-15 00:20:47 UTC. Merge-stage CI receipt: 2026-11-15 00:40:07 UTC, all eight backend shards, emulator proofs, and the hermetic merge gate green. - No endpoint changed; exercised the real collector/count builders against synthetic metadata and the real maintenance path with cleanup blocked. No production action/read or live acceptance claim. Release owner must admit the correction through the existing train and verify collector retention of the new anchor gauge. Acceptance still requires two equivalent count comparisons at least 30 minutes apart within one percentage point, plus a complete healthy sample-age hour, after the admitted release. Revert through the release train or use the existing controlled guard kill switch; no data rollback. Live acceptance remains open on SCA-2012; SCA-2063 owns release coordination.
Fresh results now retain their admitted class when committed, and the maintenance leader publishes the share still pending projection in the 10–20 minute commit window. No scheduling, projection, enrichment or release behavior changes. SCA-2012 (fresh-first step 1/5). Includes the round-one contract fixes for the registered guard kill switch and reviewed merge-writer payload. 319 changed non-test lines.
Implementation
Reader declaration (before implementation)
#25210 remains open, so the complete declaration is in backend/docs/listen_pusher_pipeline/changes/2026-11-13-fresh-delivery-guard.md. The merge transaction is the sole class writer; the guard is its only new semantic reader. The audit covers backend/ result consumers and shared services on current main; no existing reader routes on unknown fields or this result field. Deployed image SHAs still need release-owner confirmation.
utils/batch_pipeline/{merge,scheduler,provider_stt}.py;database/batch_pipeline_{coalescing,paid_attempt,recognizer_receipts,terminal_empty,artifact_missing,speech_redrive}.py;database/{batch_final_pass,batch_voice_evidence}.pyutils/batch_pipeline/{projection,projection_drain,projection_discovery,projection_followup,projection_repair,voice_evidence}.py;database/batch_pipeline_{projection,projection_session,projection_privacy,projection_release,privacy}.pyutils/batch_pipeline/{retention,held_dead_letter,held_coverage}.py;database/batch_pipeline_{store,purge,conversation_purge,quarantine_recovery}.pyutils/batch_pipeline/{enrichment,metrics}.py,database/outbox*database/jobstore/{dual_store,postgres_store,codec,backfill}.py;database/batch_pipeline_shadow_hook.pytesting/pipeline_sim/{store,postgres_store,sim,trace,scorer,policy_invariants}.py;testing/{batch_replay,store_fixtures,sync_cloud_tasks_stack}; unit MemoryStorescripts/{batch_pipeline_held_disposition,batch_pipeline_terminal_empty,batch_pipeline_artifact_missing,batch_pipeline_speech_redrive,reconcile_batch_projection_ghost_holds,redrive_staging_inputs}.py; replay/owner-lab metadata toolsresultsare encrypted blobs, a separate namespace from result-row metadata.Cost and rollback
Two count RPCs/sample: approximately max(1, ceil(total/1000)) + max(1, ceil(pending/1000)) billed reads, normally 2/minute or 2,880/day per leader. The extra advisory leader check reads the existing lease once per maintenance invocation. A registered planning envelope of 100,000 rows/count gives 200 reads/sample/environment (576,000/day across prod/dev); it is an estimate, not a throughput cap. No document/content streaming. BATCH_PIPELINE_FRESH_GUARD_ENABLED=off suppresses count queries and all four gauges. The unconditional row field rolls back by revert; existing stamps have no other semantic reader.
Review round 1 fixes
The guard now calls the registered policy kill-switch helper (with read logging suppressed), preserving default-on and off/false/0/no behavior in off, shadow and serve parser modes. Its helper-backed flag-budget entry has an owner and review date; the budget's seeded/replacement limit remains unchanged. The merge writer declaration is updated in
backend/tests/support/lifecycle_writer_inventory.py, which is imported bylifecycle_state_table.pyon this branch.Validation
make preflightchecks and all 5 PR metadata checks pass after merging current main.Live acceptance outstanding
Release owner must deploy indexes and this code to backend-integration AND the GKE batch worker. Then record two timestamped ro-prod count comparisons at least 30 minutes apart (within 1 percentage point), and sample age under 120 s for one hour, on SCA-2012. This PR performs no production reads, writes, deploys or activations. Merging is not completion of the issue.
Product invariants affected
none — additive internal metadata and count-only observability; no user-facing behavior changes.
Pipeline tuning disclosure
No capacity, scheduling, hold/release, routing or pipeline-state changes. Sampling constants define measurement only (60 s cadence, inclusive 10–20 minute cohort, 120 s visibility expiry); existing pipeline capacity settings are unchanged.
Failure-Class: none