Skip to content

feat(legacy-retire): make legacy draining reachable — prod C3/C8 transport and cap-hold census - #24222

Merged
Git-on-my-level merged 5 commits into
mainfrom
lane/planc-ready
Nov 1, 2026
Merged

Git-on-my-level merged 5 commits into
mainfrom
lane/planc-ready

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Plan C: make legacy draining/dark reachable without waiting on batch 100. Two independent blockers sat outside the ramp; this PR removes both. Evidence (ro-prod aggregates, 2026-11-01 06:07–06:15Z): swarm/state/refs/planc-darkready-2026-11-01.md in the workspace.

1. Prod transport for C3 enrichment and C8 provider-STT

Prod has no enrichment or provider-stt Cloud Tasks queue (Monitoring lists every queue with a depth series; empty queues still report 0), no enrichment-maintenance job, and no ENRICHMENT_TASKS_* / PROVIDER_STT_TASKS_* env. So provider_stt_live, a DRAINING_PRECONDITIONS id, is false, and at draining unsupported-language units would strand in provider_pending. None of this depends on batch percent.

  • deploy/ops/prod.yaml: the config-train creates enrichment (was enabled: false) and the new provider-stt queue (48 concurrent, 10/s, unlimited attempts, 10–300s backoff). Sizing: at 100% about 205k units/day take the provider route (2.4/s mean); 48/10 covers a 2x peak at ~10s per vendor call. One paid call per unit is the outbox intent's job, not the queue's. staging.yaml mirrors (mirror test).
  • deploy/runtime_env/prod.overlay.yaml (+ regenerated runtime_env.yaml):
    • ENRICHMENT_ROUTE=enrichment_queue, ENRICHMENT_TASKS_QUEUE, _HANDLER_URL, _OIDC_AUDIENCE on backend, backend-sync, backend-sync-backfill and backend-integration (every sr- producer).
    • PROVIDER_STT_TASKS_QUEUE, _HANDLER_URL, _OIDC_AUDIENCE on backend-sync and backend-integration (intake, cap-hold admission, maintenance sweep).
    • Both handlers are served by backend-integration, matching the prod enrichment-maintenance scheduler entry already in jobs.yaml, and moving this work off backend-sync, which Plan C retires. backend-integration already admits Cloud Tasks OIDC (public ingress, token verified in-app); the invoker identity is the existing SYNC_TASKS_INVOKER_SA. No IAM change.
    • The staging overlay gets its own provider handler so the isolation fence holds.
  • GKE listen/pusher are untouched: no listen or pusher roll. Listen keeps the default route; its rows bind sync_handler and still drain.
  • scripts/cross_service_contract.py: the provider-stt edge now has append_route=True. create_wake joins the route onto the handler origin (test_wake_task_shape), so the contract was demanding a doubled path. The stale prod ENRICHMENT_ROUTE known gap is deleted. Contract: 0 new violations, 0 stale gaps.

2. Retained cap holds no longer gate the dark census

drain_census --env prod counted every stt_cap_holds row as a dark blocker: 5,390,555 rows (held 5,304,010, purged 86,612). Held rows are retained audio waiting on the owner's credits and never drain to zero, so dark could never be entered. They are not stranded by dark: cap_hold_recovery.recover_selected admits every eligible hold to batch once legacy is draining/dark (cap_hold_admission.enabled_for), and a hold whose legacy spend already started finishes on the shared segment core (kept by C11), not on legacy jobs, queues or the sequencer. The census now counts pending holds (the cap_hold_redrive.PENDING_STATES, through the existing state group index) as an informational field; soak gate 4c ("cap-hold redrives served by batch") stays the assurance. Runbook updated. This changes a dark-entry gate: lead ruling required before merge.

Lead apply sequence (after merge; each step is an existing command)

source ~/.local/bin/gcp-agent-env.sh prod-operator
cd backend
.venv/bin/python scripts/ops_train.py plan --env prod      # expect: create enrichment, create provider-stt; nothing else
.venv/bin/python scripts/ops_train.py apply --env prod --revision-suffix <suffix>
# then the next backend train (Cloud Run only) carries the env; queues must exist first
# after the train serves (the sweep verifies ENRICHMENT_TASKS_OIDC_AUDIENCE on backend-integration):
.venv/bin/python scripts/scheduler_reconcile.py --environment prod --project based-hardware --apply --jobs enrichment-maintenance

jobs.yaml now marks the prod enrichment-maintenance job active (dev stays planned/paused), so provider_stt_live is satisfied in source and a full scheduler reconcile keeps it; it also sweeps the provider-stt outbox, re-waking any unit whose task create failed (Luna r1 P1).

Trap: ops_train apply applies the whole plan. On 11-01 live backend-sync max_instances is 40 while source says 50 (syncquick's source change is separate), so the plan would also revert that cap. Apply only if the plan shows nothing but the two creates; otherwise create the two queues directly with the same values and leave the rest of the plan alone:

gcloud tasks queues create enrichment --location us-central1 --project based-hardware --max-concurrent-dispatches=50 --max-dispatches-per-second=25 --max-attempts=unlimited --min-backoff=10s --max-backoff=300s &&
gcloud tasks queues create provider-stt --location us-central1 --project based-hardware --max-concurrent-dispatches=48 --max-dispatches-per-second=10 --max-attempts=unlimited --min-backoff=10s --max-backoff=300s

Verify after the train: each serving revision of the four services shows the new keys (shape only), enrichment queue depth drains, sr- first-summary dispatch ≤121s flat, zero 5xx/429/503 on /v2/enrichment/run; provider-stt stays idle until draining.

Ramp plan (ENRICHMENT_ROUTE)

  • Cohorts: staging since 10-20 (M2); prod: every backend Cloud Run service at the train after the config-train.
  • Clean metric: fleet-gate first_summary_* (no dispatch over 121s) flat vs the prior 24h; zero 5xx/429/503 on /v2/enrichment/run; enrichment depth drains; old sync_handler bindings drain from sync-jobs.
  • Expander: two-lane lead. Done by: 2026-11-05.
  • Kill switch: ENRICHMENT_ROUTE=sync_handler (rows keep their binding; both handlers stay valid).

Validation

  • Targeted unit files through backend/test.sh with BACKEND_UNIT_TEST_FILE_LIST, omi-heavy, nice -n 19: staging overlay 32, config-train 51, runtime renderer 91, drift 21, cross-service deploy contract 23 (+3 skipped), scheduler reconcile 16, runtime validator 24, manifest compat 11, provider-STT outbox 148, legacy-dark 117 + lost-recordings 61 + GMP sidecar 8: all passed.
  • scripts/cross_service_contract.py: 0 new violations, 33 known gaps, 0 stale.
  • scripts/check_feature_flag_registry.py: OK.

Product invariants affected

  • INV-DATA-1: no audio is deleted or stranded; the census change only stops a count of retained holds from blocking dark; holds keep their recovery paths.
  • INV-MEM-4: runtime_env.yaml only gains task transport env; enrichment runs the same consumer and memory consolidation route on a different queue/host, so intake and promotion behavior are unchanged.

Failure-Class: none

Rollback: ENRICHMENT_ROUTE=sync_handler in the overlay and roll (in-flight rows keep their binding). Unset PROVIDER_STT_TASKS_* to stop provider wakes. Queues are left in place (idle). Census: revert the commit.

🤖 Generated with Claude Code

Git-on-my-level and others added 3 commits November 1, 2026 13:35
…-STT

Prod never got the M3 activation: no enrichment or provider-stt queue, no
transport env, so provider_stt_live (a draining precondition) is false.

- ops prod.yaml: create the enrichment queue and declare provider-stt
  (48 concurrent, 10/s, unlimited attempts; sized for ~205k units/day at
  100%); staging mirrors.
- prod overlay: ENRICHMENT_ROUTE=enrichment_queue plus ENRICHMENT_TASKS_* on
  backend, backend-sync, backend-sync-backfill and backend-integration;
  PROVIDER_STT_TASKS_* on backend-sync and backend-integration. Both
  handlers are served by backend-integration, matching the prod
  enrichment-maintenance scheduler entry. Staging gets its own provider
  handler so the isolation fence holds.
- cross_service_contract: the provider-stt edge appends its route like
  create_wake does (append_route), so the bare-origin URL now validates;
  drop the stale prod ENRICHMENT_ROUTE known gap.
- registry: ENRICHMENT_ROUTE ramp (lead expands, done by 2026-11-05).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The census counted every stt_cap_holds row (5.39M in prod, 5.30M held) as
a dark blocker, so dark could never be entered. Held rows are retained
audio waiting on credits; dark does not strand them (eligible holds go to
batch admission, spend-started holds finish on the shared segment core).
Count pending holds through the state group index as an informational
field and keep soak gate 4c as the cap-hold assurance.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cubic-dev-ai cubic-dev-ai 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.

4 issues found across 16 files

Confidence score: 4/5

  • backend/docs/runbooks/legacy-dark.md says any unavailable read blocks ZERO, but a failed cap-hold read is informational and still permits it. Qualify the instruction for that read.
  • backend/tests/unit/test_legacy_dark.py checks constants but does not verify that take_census counts pending cap holds. Use a fake Firestore query and assert the pending states and count.
  • backend/tests/unit/test_cross_service_deploy_contract.py can miss route drift between the deploy contract and create_wake. Import the producer’s ROUTE and assert edge.route == ROUTE.
  • config/feature-flags.yaml points operators to the wrong directory for handler and OIDC configuration. Point them to backend/deploy/runtime_env, and mention backend/deploy/ops only for queue resource definitions.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/tests/unit/test_legacy_dark.py">

<violation number="1" location="backend/tests/unit/test_legacy_dark.py:245">
P2: This test does not verify that the census actually counts pending cap holds; it only verifies two constants match. Exercise `take_census` with a fake Firestore query and assert the pending states are used and the count reaches `cap_holds_awaiting_legacy`, otherwise regressions in the census path remain undetected.</violation>
</file>

<file name="backend/docs/runbooks/legacy-dark.md">

<violation number="1" location="backend/docs/runbooks/legacy-dark.md:36">
P2: The “Any unavailable read blocks” instruction is false for the cap-hold read described in the next sentence. `drain_census` treats that query failure as informational and still permits `ZERO`, so qualify this as “Any unavailable gating read blocks” to prevent operators from relying on a cap-hold read that never succeeded.</violation>
</file>

<file name="backend/tests/unit/test_cross_service_deploy_contract.py">

<violation number="1" location="backend/tests/unit/test_cross_service_deploy_contract.py:369">
P2: This regression test does not verify that the contract route matches the route used by `create_wake`. Import the producer’s `ROUTE` constant and assert `edge.route == ROUTE`, otherwise route drift can pass the deployment contract.</violation>
</file>

<file name="config/feature-flags.yaml">

<violation number="1" location="config/feature-flags.yaml:105">
P3: This runbook pointer sends operators to the wrong directory for the handler and OIDC configuration. Point the note to `backend/deploy/runtime_env` (and mention `backend/deploy/ops` only for queue resource definitions).</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

from database.cap_hold_redrive import PENDING_STATES
from scripts.legacy_dark import drain_census

assert drain_census.CAP_HOLD_PENDING_STATES == PENDING_STATES

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This test does not verify that the census actually counts pending cap holds; it only verifies two constants match. Exercise take_census with a fake Firestore query and assert the pending states are used and the count reaches cap_holds_awaiting_legacy, otherwise regressions in the census path remain undetected.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/tests/unit/test_legacy_dark.py, line 245:

<comment>This test does not verify that the census actually counts pending cap holds; it only verifies two constants match. Exercise `take_census` with a fake Firestore query and assert the pending states are used and the count reaches `cap_holds_awaiting_legacy`, otherwise regressions in the census path remain undetected.</comment>

<file context>
@@ -230,6 +230,21 @@ def test_informational_ledger_counts_never_gate():
+    from database.cap_hold_redrive import PENDING_STATES
+    from scripts.legacy_dark import drain_census
+
+    assert drain_census.CAP_HOLD_PENDING_STATES == PENDING_STATES
+
+
</file context>

```

It gates on `sync_backfill_pending`, sequencer active owners, `sync_redrive_required`, `stt_cap_holds` (upper bound), the depth of `sync-jobs`, `sync-jobs-fresh`, `sync-backfill` and `sync-backfill-fresh`, and `increase(omi_legacy_sync_admissions_total[30m])`. Any unavailable read blocks. Inline (non-Cloud-Tasks) legacy jobs have no aggregate source; the 30-minute zero-admission window plus the 10-minute confirmation bounds them. A stranded `sr-` enrichment backlog on a legacy queue (C3's pre-switch rows still bound to `sync_handler`) is non-blocking for `dark` entry only when the enrichment route is switched (`ENRICHMENT_ROUTE=enrichment_queue`) AND the backlog's cause is external, as on staging, where the LLM gateway is blackholed (lead ruling 10-20). Every legacy count must still read zero, including non-`sr-` tasks (operator count of task names). Prod's gateway works, so prod's pre-switch backlog drains and the plain census applies. `--with-ledger` adds informational ledger counts where a collection-group index exists (prod has none).
It gates on `sync_backfill_pending`, sequencer active owners, `sync_redrive_required`, the depth of `sync-jobs`, `sync-jobs-fresh`, `sync-backfill` and `sync-backfill-fresh`, and `increase(omi_legacy_sync_admissions_total[30m])`. Any unavailable read blocks. Pending `stt_cap_holds` are counted but never gate: held rows are retained audio waiting on credits (5.3M in prod, 2026-11-01) and never drain to zero, and `dark` does not strand them, because eligible holds go to batch admission and spend-started holds finish on the shared segment core. Gate 4c below carries the cap-hold assurance. Inline (non-Cloud-Tasks) legacy jobs have no aggregate source; the 30-minute zero-admission window plus the 10-minute confirmation bounds them. A stranded `sr-` enrichment backlog on a legacy queue (C3's pre-switch rows still bound to `sync_handler`) is non-blocking for `dark` entry only when the enrichment route is switched (`ENRICHMENT_ROUTE=enrichment_queue`) AND the backlog's cause is external, as on staging, where the LLM gateway is blackholed (lead ruling 10-20). Every legacy count must still read zero, including non-`sr-` tasks (operator count of task names). Prod's gateway works, so prod's pre-switch backlog drains and the plain census applies. `--with-ledger` adds informational ledger counts where a collection-group index exists (prod has none).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: The “Any unavailable read blocks” instruction is false for the cap-hold read described in the next sentence. drain_census treats that query failure as informational and still permits ZERO, so qualify this as “Any unavailable gating read blocks” to prevent operators from relying on a cap-hold read that never succeeded.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/docs/runbooks/legacy-dark.md, line 36:

<comment>The “Any unavailable read blocks” instruction is false for the cap-hold read described in the next sentence. `drain_census` treats that query failure as informational and still permits `ZERO`, so qualify this as “Any unavailable gating read blocks” to prevent operators from relying on a cap-hold read that never succeeded.</comment>

<file context>
@@ -33,7 +33,7 @@ Any failure to read the mode serves `on`. During the soak the legacy image, queu
  • It gates on sync_backfill_pending, sequencer active owners, sync_redrive_required, stt_cap_holds (upper bound), the depth of sync-jobs, sync-jobs-fresh, sync-backfill and sync-backfill-fresh, and increase(omi_legacy_sync_admissions_total[30m]). Any unavailable read blocks. Inline (non-Cloud-Tasks) legacy jobs have no aggregate source; the 30-minute zero-admission window plus the 10-minute confirmation bounds them. A stranded sr- enrichment backlog on a legacy queue (C3's pre-switch rows still bound to sync_handler) is non-blocking for dark entry only when the enrichment route is switched (ENRICHMENT_ROUTE=enrichment_queue) AND the backlog's cause is external, as on staging, where the LLM gateway is blackholed (lead ruling 10-20). Every legacy count must still read zero, including non-sr- tasks (operator count of task names). Prod's gateway works, so prod's pre-switch backlog drains and the plain census applies. --with-ledger adds informational ledger counts where a collection-group index exists (prod has none).
  • It gates on sync_backfill_pending, sequencer active owners, sync_redrive_required, the depth of sync-jobs, sync-jobs-fresh, sync-backfill and sync-backfill-fresh, and increase(omi_legacy_sync_admissions_total[30m]). Any unavailable read blocks. Pending stt_cap_holds are counted but never gate: held rows are retained audio waiting on credits (5.3M in prod, 2026-11-01) and never drain to zero, and dark does not strand them, because eligible holds go to batch admission and spend-started holds finish on the shared segment core. Gate 4c below carries the cap-hold assurance. Inline (non-Cloud-Tasks) legacy jobs have no aggregate source; the 30-minute zero-admission window plus the 10-minute confirmation bounds them. A stranded sr- enrichment backlog on a legacy queue (C3's pre-switch rows still bound to sync_handler) is non-blocking for dark entry only when the enrichment route is switched (ENRICHMENT_ROUTE=enrichment_queue) AND the backlog's cause is external, as on staging, where the LLM gateway is blackholed (lead ruling 10-20). Every legacy count must still read zero, including non-sr- tasks (operator count of task names). Prod's gateway works, so prod's pre-switch backlog drains and the plain census applies. --with-ledger adds informational ledger counts where a collection-group index exists (prod has none).

Transitions

</file context>


</details>

```suggestion
  It gates on `sync_backfill_pending`, sequencer active owners, `sync_redrive_required`, the depth of `sync-jobs`, `sync-jobs-fresh`, `sync-backfill` and `sync-backfill-fresh`, and `increase(omi_legacy_sync_admissions_total[30m])`. Any unavailable gating read blocks. Pending `stt_cap_holds` are counted but never gate: held rows are retained audio waiting on credits (5.3M in prod, 2026-11-01) and never drain to zero, and `dark` does not strand them, because eligible holds go to batch admission and spend-started holds finish on the shared segment core. Gate 4c below carries the cap-hold assurance. Inline (non-Cloud-Tasks) legacy jobs have no aggregate source; the 30-minute zero-admission window plus the 10-minute confirmation bounds them. A stranded `sr-` enrichment backlog on a legacy queue (C3's pre-switch rows still bound to `sync_handler`) is non-blocking for `dark` entry only when the enrichment route is switched (`ENRICHMENT_ROUTE=enrichment_queue`) AND the backlog's cause is external, as on staging, where the LLM gateway is blackholed (lead ruling 10-20). Every legacy count must still read zero, including non-`sr-` tasks (operator count of task names). Prod's gateway works, so prod's pre-switch backlog drains and the plain census applies. `--with-ledger` adds informational ledger counts where a collection-group index exists (prod has none).

# utils/provider_stt_tasks.create_wake posts to PROVIDER_STT_TASKS_HANDLER_URL + ROUTE (test_wake_task_shape),
# so the configured URL is a bare origin; without append_route the contract demanded the doubled path.
edge = next(e for e in contract.TASK_EDGES if e.id == 'provider-stt')
assert edge.append_route is True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This regression test does not verify that the contract route matches the route used by create_wake. Import the producer’s ROUTE constant and assert edge.route == ROUTE, otherwise route drift can pass the deployment contract.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/tests/unit/test_cross_service_deploy_contract.py, line 369:

<comment>This regression test does not verify that the contract route matches the route used by `create_wake`. Import the producer’s `ROUTE` constant and assert `edge.route == ROUTE`, otherwise route drift can pass the deployment contract.</comment>

<file context>
@@ -362,6 +362,13 @@ def test_append_route_edge_with_path_fails(results: Results) -> None:
+    # utils/provider_stt_tasks.create_wake posts to PROVIDER_STT_TASKS_HANDLER_URL + ROUTE (test_wake_task_shape),
+    # so the configured URL is a bare origin; without append_route the contract demanded the doubled path.
+    edge = next(e for e in contract.TASK_EDGES if e.id == 'provider-stt')
+    assert edge.append_route is True
+
+
</file context>

Comment thread config/feature-flags.yaml
- {"key":"BATCH_JOBSTORE_MODE","aliases":[],"kind":"env","terminal":"undecided","lifecycle":"rollout","surfaces":["backend"],"summary":"Default firestore; shadow mirrors committed batch job-store writes to the staging Postgres and counts read parity (Firestore stays the only authority)","fail":"closed","owner":"dazheng","created":"2026-10-19","review_by":"2026-11-02","decision":"pending","notes":"Plan A2, legacy-sync retirement lane 12. Takes effect only with JOBSTORE_PG_HOST/_DATABASE/_USER set (IAM database auth, no password); the batch_pipeline_prod namespace is refused in code, and every other value or a missing setting keeps plain Firestore. Ramp: staging worker plus the staging backend services that build the batch store, after the A2 PR lands; metric omi_jobstore_shadow_parity_total must stay at or above 99.99% read match over 12h (M3), with mirror write errors and timeouts near zero. Prod needs the approved Cloud SQL instance (S1-b) and Postgres coverage for the writers that bypass Store.run (purge, retention, recovery); the lead expands. postgres_primary and postgres are reserved for A7. Rollback: unset, or JOBSTORE_SHADOW_WRITES=off."}
- {"key":"JOBSTORE_SHADOW_WRITES","aliases":[],"kind":"env","terminal":"keep","lifecycle":"ops_kill","surfaces":["backend"],"summary":"Default on unless 0/false/off/no; off stops the A2 Postgres shadow mirror (and its parity reads) while BATCH_JOBSTORE_MODE=shadow","fail":"open","owner":"dazheng","created":"2026-10-19","decision":"keep","notes":"Cost and load lever only: the mirror is best effort and never affects the Firestore primary. Writes skipped while off count as omi_jobstore_shadow_parity_total{op=write,outcome=skipped}. See backend/database/jobstore/dual_store.py."}
- {"key":"ENRICHMENT_ROUTE","aliases":[],"kind":"env","terminal":"undecided","lifecycle":"rollout","surfaces":["backend"],"summary":"Default sync_handler; enrichment_queue binds new sr- enrichment obligations to /v2/enrichment/run on the enrichment queue (plan C3)","fail":"closed","owner":"dazheng","created":"2026-10-19","review_by":"2026-11-02","decision":"pending","notes":"Legacy-sync retirement lane 9 (#22462). A row keeps the binding it was created with, so switching back never strands in-flight work; both bindings stay valid. Ramp: staging at M2 under replay (sr- 120s dispatch SLI clean, old bindings drain, zero 5xx), then prod after the M3 train under the C3 24h sr- dispatch SLI gate; the lead expands. Must be enrichment_queue before legacy draining (contract (h) invariant 3). Replaced by E1's enrichment_route policy field. Queue wiring (ENRICHMENT_TASKS_QUEUE, _HANDLER_URL, _OIDC_AUDIENCE, _INVOKER_SA) is deploy config in backend/deploy/ops, not a flag."}
- {"key":"ENRICHMENT_ROUTE","aliases":[],"kind":"env","terminal":"undecided","lifecycle":"rollout","surfaces":["backend"],"summary":"Default sync_handler; enrichment_queue binds new sr- enrichment obligations to /v2/enrichment/run on the enrichment queue (plan C3)","fail":"closed","owner":"dazheng","created":"2026-10-19","review_by":"2026-11-09","decision":"pending","notes":"Legacy-sync retirement lane 9 (#22462). A row keeps the binding it was created with, so switching back never strands in-flight work; both bindings stay valid. Staging has served enrichment_queue since M2. Prod activation (planc, Plan C): the prod overlay sets enrichment_queue on backend, backend-sync, backend-sync-backfill and backend-integration, with backend-integration serving /v2/enrichment/run; the config-train must create the enrichment queue before that roll. Kill switch: sync_handler. Must be enrichment_queue before legacy draining (contract (h) invariant 3). GKE listen keeps the default until its own roll; its rows bind sync_handler and still drain. Replaced by E1's enrichment_route policy field. Queue wiring (ENRICHMENT_TASKS_QUEUE, _HANDLER_URL, _OIDC_AUDIENCE, _INVOKER_SA) is deploy config, not a flag.","ramp":{"cohorts":["staging since 2026-10-20 (M2)","prod: every backend Cloud Run service at the backend train after the config-train creates the enrichment queue"],"clean_metric":"sr- first-summary dispatch within 121s of first_pending_at (fleet-gate first_summary_* tokens) flat vs the 24h before; zero 5xx/429/503 on /v2/enrichment/run; enrichment queue depth drains; old sync_handler bindings drain from sync-jobs","expander":"two-lane lead","done_by":"2026-11-05"}}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: This runbook pointer sends operators to the wrong directory for the handler and OIDC configuration. Point the note to backend/deploy/runtime_env (and mention backend/deploy/ops only for queue resource definitions).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At config/feature-flags.yaml, line 105:

<comment>This runbook pointer sends operators to the wrong directory for the handler and OIDC configuration. Point the note to `backend/deploy/runtime_env` (and mention `backend/deploy/ops` only for queue resource definitions).</comment>

<file context>
@@ -102,7 +102,7 @@ flags:
   - {"key":"BATCH_JOBSTORE_MODE","aliases":[],"kind":"env","terminal":"undecided","lifecycle":"rollout","surfaces":["backend"],"summary":"Default firestore; shadow mirrors committed batch job-store writes to the staging Postgres and counts read parity (Firestore stays the only authority)","fail":"closed","owner":"dazheng","created":"2026-10-19","review_by":"2026-11-02","decision":"pending","notes":"Plan A2, legacy-sync retirement lane 12. Takes effect only with JOBSTORE_PG_HOST/_DATABASE/_USER set (IAM database auth, no password); the batch_pipeline_prod namespace is refused in code, and every other value or a missing setting keeps plain Firestore. Ramp: staging worker plus the staging backend services that build the batch store, after the A2 PR lands; metric omi_jobstore_shadow_parity_total must stay at or above 99.99% read match over 12h (M3), with mirror write errors and timeouts near zero. Prod needs the approved Cloud SQL instance (S1-b) and Postgres coverage for the writers that bypass Store.run (purge, retention, recovery); the lead expands. postgres_primary and postgres are reserved for A7. Rollback: unset, or JOBSTORE_SHADOW_WRITES=off."}
   - {"key":"JOBSTORE_SHADOW_WRITES","aliases":[],"kind":"env","terminal":"keep","lifecycle":"ops_kill","surfaces":["backend"],"summary":"Default on unless 0/false/off/no; off stops the A2 Postgres shadow mirror (and its parity reads) while BATCH_JOBSTORE_MODE=shadow","fail":"open","owner":"dazheng","created":"2026-10-19","decision":"keep","notes":"Cost and load lever only: the mirror is best effort and never affects the Firestore primary. Writes skipped while off count as omi_jobstore_shadow_parity_total{op=write,outcome=skipped}. See backend/database/jobstore/dual_store.py."}
-  - {"key":"ENRICHMENT_ROUTE","aliases":[],"kind":"env","terminal":"undecided","lifecycle":"rollout","surfaces":["backend"],"summary":"Default sync_handler; enrichment_queue binds new sr- enrichment obligations to /v2/enrichment/run on the enrichment queue (plan C3)","fail":"closed","owner":"dazheng","created":"2026-10-19","review_by":"2026-11-02","decision":"pending","notes":"Legacy-sync retirement lane 9 (#22462). A row keeps the binding it was created with, so switching back never strands in-flight work; both bindings stay valid. Ramp: staging at M2 under replay (sr- 120s dispatch SLI clean, old bindings drain, zero 5xx), then prod after the M3 train under the C3 24h sr- dispatch SLI gate; the lead expands. Must be enrichment_queue before legacy draining (contract (h) invariant 3). Replaced by E1's enrichment_route policy field. Queue wiring (ENRICHMENT_TASKS_QUEUE, _HANDLER_URL, _OIDC_AUDIENCE, _INVOKER_SA) is deploy config in backend/deploy/ops, not a flag."}
+  - {"key":"ENRICHMENT_ROUTE","aliases":[],"kind":"env","terminal":"undecided","lifecycle":"rollout","surfaces":["backend"],"summary":"Default sync_handler; enrichment_queue binds new sr- enrichment obligations to /v2/enrichment/run on the enrichment queue (plan C3)","fail":"closed","owner":"dazheng","created":"2026-10-19","review_by":"2026-11-09","decision":"pending","notes":"Legacy-sync retirement lane 9 (#22462). A row keeps the binding it was created with, so switching back never strands in-flight work; both bindings stay valid. Staging has served enrichment_queue since M2. Prod activation (planc, Plan C): the prod overlay sets enrichment_queue on backend, backend-sync, backend-sync-backfill and backend-integration, with backend-integration serving /v2/enrichment/run; the config-train must create the enrichment queue before that roll. Kill switch: sync_handler. Must be enrichment_queue before legacy draining (contract (h) invariant 3). GKE listen keeps the default until its own roll; its rows bind sync_handler and still drain. Replaced by E1's enrichment_route policy field. Queue wiring (ENRICHMENT_TASKS_QUEUE, _HANDLER_URL, _OIDC_AUDIENCE, _INVOKER_SA) is deploy config, not a flag.","ramp":{"cohorts":["staging since 2026-10-20 (M2)","prod: every backend Cloud Run service at the backend train after the config-train creates the enrichment queue"],"clean_metric":"sr- first-summary dispatch within 121s of first_pending_at (fleet-gate first_summary_* tokens) flat vs the 24h before; zero 5xx/429/503 on /v2/enrichment/run; enrichment queue depth drains; old sync_handler bindings drain from sync-jobs","expander":"two-lane lead","done_by":"2026-11-05"}}
   - {"key":"BATCH_PIPELINE_PROJECTION_PREDECESSOR_REPLAY_ENABLED","aliases":[],"kind":"env","lifecycle":"ops_kill","surfaces":["backend"],"summary":"Default on; a blocked projection successor schedules its owner's missing predecessor through the existing ordered walk","fail":"open","owner":"dazheng","created":"2026-10-21","terminal":"keep","decision":"keep","ramp":{"cohorts":["all admitted batch owners at deployment"],"clean_metric":"owner_chain advanced increases for replayable predecessors; no new privacy, binding or chain-order violations","expander":"two-lane lead","done_by":"2026-10-22"},"notes":"False restores blocked-page discovery behavior. One bounded replay per owner per sweep, or the existing owner-drain queue; every assignment retains transactional predecessor, privacy, binding and replay fences. A head with an unresolved safety fence remains blocked. See backend/docs/batch-pipeline-serving.md."}
   - {"key":"STT_PRERECORDED_LANGUAGE_GUARD_ENABLED","aliases":[],"kind":"env","lifecycle":"ops_kill","surfaces":["backend"],"summary":"Default on unless false; unknown/multilingual audio needs independent supported-language detection at confidence >=0.9 for probes under10s or >=0.8 for longer probes to use Parakeet; unsupported or uncertain speech uses Modulate","fail":"open","owner":"dazheng","created":"2026-10-21","terminal":"keep","decision":"keep","notes":"CPU selection/intake switch. Bounded Modulate language-only classification precedes unknown-language dispatch; confident European speech retains Parakeet. False disables new probes and restores ordinary prerecorded routing; admitted worker audio still requires supported-language proof and drains through multilingual recovery. The short-probe floor has its own default-on kill switch. No streaming change. See backend/docs/batch-language-quality.md."}
</file context>

…tt sweep)

Luna r1 P1 on #24222: the job stayed lifecycle planned, so nothing
re-woke a provider unit whose task create failed and provider_stt_live
stayed false. Prod is active; dev stays planned and paused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Luna round 2 on #24222: two P1s, planc rebuttal (round cap reached; lead decides)

Head 663aa0f45c30, CI 65/65 green. Review: /Volumes/Ephemeral/scratch/two-lane-lead/review-24222-r2.md.

P1 (b): provider-STT sweep rotates task_token every tick without refreshing woken_at

Not the case on main. Prod's provider outbox is FirestoreProviderSttOutbox (database/outbox.py:outbox_for always returns the Firestore implementation; outbox_firestore.py:446-459). Its sweep (database/outbox_provider_stt.py:314-357) skips any row with now - woken_at < REWAKE_AFTER_SECONDS (600s, line 335), and rearm writes 'woken_at': now together with the new task_token (lines 344-350). A row is therefore re-armed at most once per 10 minutes, not on every 2-minute tick. A delayed task from the previous token is only invalidated if Cloud Tasks delivery delay exceeds 10 minutes, and then the new token's task is already enqueued. No change made.

P1 (a): dark becomes reachable while sync-origin cap holds stay pending

The observation is correct, but the condition is pre-existing and not created by dark:

  • Prod sets STT_CAP_DISPATCH_LANES=live (deploy/runtime_env.yaml). cap_hold_recovery._selected_lane returns None for an origin=sync hold because recovery_admission_enabled(uid, 'sync') requires the lane to be selected (config/stt_cap_dispatch.py:57-99,132-151). Offline (sync) holds are still created (offline_admission_enabled → offline_enforcement_enabled). So today, in legacy on, sync-origin holds are recovered by no path, and a client retry of held content is acknowledged as held.
  • Dark changes nothing for them. Recovery does not use legacy jobs, queues or the sequencer: once the sync lane enters recovery scope, eligible holds go to batch admission (cap_hold_admission.enabled_for, mode != on) and spend-started ones to _recover_row on the core C11 keeps. The audio is retained (the checkpoint has no application TTL, docs/stt-cap-dispatch.md).
  • Keeping them as a dark gate means dark never happens: 5.30M held rows today, and none can drain while recovery scope excludes sync.

Separate finding, tracked for the owner (Subscription session / lead), not a #24222 change: with STT_CAP_DISPATCH_LANES=live, sync-origin held captures have no recovery path at all, including after the owner buys credits (processing_backlog_worker → recover_selected is lane-gated the same way). If that is not the intended policy, about 5.3M held captures are waiting on it. planc did not measure the sync/live split (origin is in encrypted hold metadata, not an aggregatable field).

Recommendation: merge #24222 as is, record ruling on the census gate, and route the sync-lane recovery-scope question to the Subscription session with a dated promise.

Git-on-my-level added a commit that referenced this pull request Nov 1, 2026
Apply the 15% GPU floor share at every step of the queue table, size the
staging ladder's audio budget and temporary queue raise, state that the
provider-stt entries and staging mirror arrive with #24222, mark the sim drill
cases as slice D prerequisites, and update the two worker docs that still
named the floor of three. Record the F1/F2 fixes as built: a durable
job-document route proof in the observer, and a provider-stage VAD
measurement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Nov 1, 2026
#24243)

Slice E of all-vendor batch routing: the standing GPU floor and the
capacity plan around it.

**Floor 3 → 4 on-demand L4.** David (11-01) wants GPUs kept even when a
vendor is cheaper, because Modulate has outages. L4 stockouts fail
scale-up but never take running on-demand nodes, so the floor must
already be standing before an outage. `replicaCount` and
`autoscaling.minReplicas` move together, and a chart test pins them
equal. Takes effect at the lead's next worker Helm roll: about $20.5/day
list above floor 3. On 11-01 the pool had 5 Ready nodes during the a/b/c
stockout, so 4 fits without scale-up. Rollback: 3. The floor *share*
(`gpu_floor_percent`) is slice B's route-table value; slice E has no
flags.

**Runbook** `backend/docs/runbooks/batch-vendor-routing-capacity.md`:
- floor sizing and cost;
- `provider-stt` queue sizing (dispatch ≥ 2 × peak, concurrency ≈ 2 ×
peak × L), with a step table. L is unmeasured, so every row is an
estimate. The sync handler holds one `sync` thread (16/instance) per
vendor call;
- the staging rate-limit ladder (5 → 10 → 25 → 50 concurrent, stop
rules, receipt);
- staging/sim and 1% prod failover drills;
- guard interlocks F1–F4 behind lead ruling `d914f8`;
- rollout order, and the outage and stockout plays.

The `provider-stt` queue resize itself is not in this PR. The queue is
created by #24222 at 48/10, which covers the 1% step if L ≤ about 5s.
The resize waits for #24222 and the staging L measurement, and lands as
a lead-owned `deploy/ops/prod.yaml` change.

Verification: `backend/test.sh` with `BACKEND_UNIT_TEST_FILE_LIST` =
`test_batch_pipeline_chart.py` and
`test_monitoring_adapter_hpa_contract.py`, through `omi-heavy`: 80
passed (Helm present). Layer: offline Helm render and unit tests only.
No deploy, no flag, no queue, no prod reads.

Deploy needed (lead): a worker Helm roll to carry floor 4, after
confirming at least 4 Ready on-demand nodes and that the
`batch-pipeline-pool` minimum is ≥ 4.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/24243?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/24243?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F24243&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
# Conflicts:
#	backend/deploy/runtime_env/prod.overlay.yaml
@Git-on-my-level
Git-on-my-level merged commit 6583f4c into main Nov 1, 2026
62 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/planc-ready branch November 1, 2026 15:38
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