Repository navigation
feat(batch): C8 provider-STT consumer, route and draining/dark admission (lane 8 slice 2) - #22457
Conversation
…utral) Adds the batch provider-STT stage for languages Parakeet cannot serve, so batch never needs the legacy fallback for them: - resolve_route(): admission-time stt_route/provider_reason/provider_service (contract (c) fields). Unknown language is 'multi' -> Parakeet, as legacy. BYOK never changes the STT route (sync prerecorded never used BYOK keys). - enqueue_in_transaction(): writes a provider unit as provider_pending with merge_pending set, outside the GPU DRR ring, keeping the owner revision fence and late-capture watermark. Intended for an admit() enqueue hook. - ProviderSttStore/ProviderSttStage: paid-once job-row intent (pending -> running CAS mints the token), one Modulate call with client retries disabled, deterministic per-token result object, settle to the same result_ready transition Scheduler.complete performs. Redelivery reconciles, never re-spends; vendor failure and abandoned intents settle failed_held (never 'held', so quarantine recovery cannot pay twice). Nothing imports the new module yet: intake wiring, the queue consumer and the router follow once the lane-1 stubs and the admit() hook land. Expected C8 traces are pinned under pipeline_sim_goldens_pending/ with a strict xfail until the sim configs exist. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…stt.resolve_route Behaviour-neutral at legacy_sync 'on': unknown and 'multi' languages keep today's legacy fallback explicitly, and a parametrized test pins the old and new conditions equal for every language class with and without BYOK. This is the seam the C8 provider route replaces in draining/dark. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…U budget Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contract (a) amendment (lead ruling 10-19): enqueue= lets the C8 provider stage write its units and their outbox rows outside the GPU ring in the admission transaction; adopt= lets intake take over a legacy ledger row it re-validates inside that transaction (a row legacy can no longer finish). With both unset, behaviour is unchanged. File owned by E1/Sol: needs Sol's agreement before merge. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion (lane 8 slice 2) - ProviderSttConsumer (kind provider_stt, role workers, 1800s lease, no heartbeat) maps the stage onto contract (a) results; the route POST /v2/batch-pipeline/provider-stt/run answers 200 / 409 retry / 400 malformed under Cloud Tasks OIDC, never 429/503. - Intake, with legacy_sync draining or dark: a language Parakeet cannot serve is admitted to the provider stage (outbox row in the admission transaction, wake after commit); legacy-owned content is fenced per contract (h) invariant 4 through lane 10's fence_decision; a stranded legacy row is adopted once by the admit() adopt= CAS; a legacy final-pass recording is acknowledged, never re-admitted. At 'on' every route is today's. - BYOK (David, 10-19): routed like every other upload. The batch 503 sync_batch_byok_unavailable and the live-upload legacy owner choice for BYOK are removed; enrichment runs on Omi's keys. - merge.py (lead sign-off, one line): provider results carry the recovery_version marker, so projection uses vendor labels as for recovered units. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis 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: 880ea7ec79
ℹ️ 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".
| # Provider units are funded by the provider stage, not GPU compute admission. | ||
| items.append(replace(item, audio_uri=uri, requires_compute_admission=not provider)) |
There was a problem hiding this comment.
Reserve provider funding before bypassing compute admission
When a draining/dark upload contains multiple unsupported-language units, this bypasses compute admission and wakes an independent provider task for every unit. ProviderSttStage only reads sync_allowed, while usage is not recorded until Projection.complete_content finishes the entire content, so all sibling deliveries can observe the same remaining allowance and concurrently issue paid Modulate calls. A near-cap bundle of up to 128 units can therefore spend far beyond its allowance; reserve or debit funding atomically per unit, or serialize provider spending per owner.
Useful? React with 👍 / 👎.
| or not _bounded(body['wake_token']) | ||
| ): | ||
| return _malformed() | ||
| result = await run_blocking(sync_executor, run_delivery, body['row_id'], body['wake_token']) |
There was a problem hiding this comment.
Move provider delivery off the shared sync executor
With concurrent provider tasks, this holds one of the 16 shared sync_executor threads for the entire delivery, including GCS access and a vendor call whose consumer lease is explicitly 1,800 seconds. Sixteen slow deliveries can therefore exhaust the pool and starve ordinary sync endpoint work; make the delivery an async coordinator that offloads individual blocking steps, or use a separately sized provider pool.
AGENTS.md reference: backend/AGENTS.md:L268-L275
Useful? React with 👍 / 👎.
| # C8: with legacy draining or dark, a language Parakeet cannot serve goes | ||
| # to the batch provider-STT stage instead of the legacy fallback. | ||
| provider = mode is not LegacySyncMode.ON and route.stt_route == 'provider' |
There was a problem hiding this comment.
Document the new provider-STT pipeline path
This changes unsupported-language transcription from the legacy fallback to a new provider-STT admission, outbox, consumer, and projection path, but the commit does not update backend/docs/listen_pusher_pipeline.mdx. That leaves the repository-owned transcription flow contract inaccurate for subsequent rollout and operational work; update the pipeline document in this change.
AGENTS.md reference: backend/AGENTS.md:L159-L159
Useful? React with 👍 / 👎.
| def verify_provider_stt_task(request: Request) -> int: | ||
| from utils.cloud_tasks import verify_configured_cloud_tasks_oidc |
There was a problem hiding this comment.
Move the Cloud Tasks verifier import to module scope
The new route imports verify_configured_cloud_tasks_oidc inside its dependency function, contrary to the backend's module-level import rule. This also defers discovery of a missing or broken Cloud Tasks dependency until the first task request instead of normal import/startup validation; import it with the other utils dependencies at module scope.
AGENTS.md reference: backend/AGENTS.md:L163-L169
Useful? React with 👍 / 👎.
| # Provider units are funded by the provider stage, not GPU compute admission. | ||
| items.append(replace(item, audio_uri=uri, requires_compute_admission=not provider)) |
There was a problem hiding this comment.
Preserve the intake manifest for provider-routed units
Setting requires_compute_admission to false also tells Projector.assign_parts not to fetch the staged audio manifest or call resolve_context. Consequently, every provider-routed upload discards the geolocation and contextual binding metadata that with_context embedded during intake and can be assigned differently from the same upload on the GPU route. Decouple provider funding from manifest availability, or add a separate flag so these units still load their authenticated intake context.
Useful? React with 👍 / 👎.
…ider_reason='byok') The route stays language-only; provider_reason='byok' records that admission funded the unit while the validated keys were present. The provider stage never re-runs the keyless funding check for it. Writing the same value into ProjectionBinding.policy (lane 6's GPU dispatch skip) waits for E1 (#22448): neither ProjectionBinding.policy nor BatchUnitPolicy.provider_reason exists on integration yet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 525e04fe6b
ℹ️ 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".
| # A BYOK unit was funded at admission; the keyless re-check would hold it forever. | ||
| if route.provider_reason != 'byok' and not self.allowed( | ||
| item.owner_id, item.duration_seconds, route.provider_service | ||
| ): |
There was a problem hiding this comment.
Keep BYOK fallbacks behind the funded allowance
When legacy sync is draining or dark, an unsupported-language upload carrying any validated BYOK header gets provider_reason == 'byok', so this condition skips sync_allowed even though transcribe() always calls Modulate with the server's MODULATE_API_KEY. BYOK supports OpenAI, Anthropic, Gemini, OpenRouter, and Deepgram—not Modulate—and the funded-STT contract classifies Modulate and Omi-funded BYOK fallbacks as ordinary-allowance work. This is independent of the previously reported sibling race: even a single capped BYOK unit can issue a paid Modulate call, so retain the allowance check unless the selected provider call is actually customer-funded.
AGENTS.md reference: backend/AGENTS.md:L151-L151
Useful? React with 👍 / 👎.
| legacy_dark.FenceAction.ACK, | ||
| legacy_dark.LegacyDarkReason.LEGACY_ACTIVE, | ||
| legacy_dark.LegacyOwnership.ACTIVE, |
There was a problem hiding this comment.
Preserve the dark-mode legacy-owner signal
When a target still has record_lane_owner == 'legacy_final_pass_v1' after the runtime mode reaches DARK, this hard-codes LEGACY_ACTIVE instead of LEGACY_ACTIVE_IN_DARK. The normal fence_decision path distinguishes these modes because an active legacy owner in dark violates the zero-in-flight entry precondition and is intended to page; this branch instead records it as ordinary draining activity and hides that rollback signal. Select the reason from mode or route this case through the shared fence decision.
AGENTS.md reference: backend/AGENTS.md:L151-L151
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 460f3f5384
ℹ️ 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".
| record_origin=record_origin, | ||
| ) | ||
| wakes: dict[str, str] = {} | ||
| outbox = await run_blocking(db_executor, outbox_for, OutboxKind.PROVIDER_STT) if provider else None |
There was a problem hiding this comment.
Provide the provider-STT outbox before resolving it
When legacy sync is draining or dark and an upload selects the provider route, this call always raises NotImplementedError: outbox_for() delegates to database.outbox_firestore.firestore_outbox(), which accepts only ENRICHMENT and explicitly rejects PROVIDER_STT, and a repo-wide search of this commit finds no alternative implementation. accept_upload() catches that exception and returns 503 after staging the audio, so every provider-routed upload is unavailable; land and register the provider outbox implementation before invoking this factory.
Useful? React with 👍 / 👎.
| @router.post(ROUTE, include_in_schema=False) | ||
| async def run_provider_stt(request: Request, _retry_count: int = Depends(verify_provider_stt_task)): |
There was a problem hiding this comment.
Register the provider-STT router in the application
The reviewed backend/main.py neither imports batch_provider_stt nor calls app.include_router(batch_provider_stt.router); a repo-wide search finds no other application mounting this router. Consequently Cloud Tasks requests to /v2/batch-pipeline/provider-stt/run receive 404 and durable provider rows cannot be consumed, even after the outbox implementation is supplied.
Useful? React with 👍 / 👎.
| # C8: with legacy draining or dark, a language Parakeet cannot serve goes | ||
| # to the batch provider-STT stage instead of the legacy fallback. | ||
| provider = mode is not LegacySyncMode.ON and route.stt_route == 'provider' |
There was a problem hiding this comment.
Attribute provider-routed usage to Modulate
When this branch activates the provider route, transcription results correctly identify words_provider as modulate, but ProjectionStore.prepare_accounting() unconditionally records every batch upload with usage_metadata.provider='parakeet'. The hourly shadow meter prices Modulate at 60,000 micro-USD/hour and Parakeet at 20,000, so every newly routed provider upload is under-attributed by 3× and can distort both cost reporting and ladder-budget accounting; propagate the admitted provider service into completion accounting.
Useful? React with 👍 / 👎.
| or not _bounded(body['wake_token']) | ||
| ): | ||
| return _malformed() | ||
| result = await run_blocking(sync_executor, run_delivery, body['row_id'], body['wake_token']) |
There was a problem hiding this comment.
Add a request timeout for provider-STT deliveries
Once this route is mounted, a valid Modulate delivery can run for up to the client's 300-second HTTP timeout, while the consumer and Cloud Tasks contracts allow 1,800- and 1,500-second execution respectively. backend/main.py does not include this path in paths_timeout, and no deployed HTTP_POST_TIMEOUT binding exists, so TimeoutMiddleware applies its 120-second default: a slow transcription returns 504 and cancels the await while the executor thread continues, prompting a duplicate task delivery and risking an orphaned lease if the instance exits before settlement. Add a path-specific timeout below the Cloud Tasks deadline.
Useful? React with 👍 / 👎.
…slice 3, stacked on #22457) (#22467) * feat(batch): C8 provider-STT stage core (lane 8 slice 1, behaviour-neutral) Adds the batch provider-STT stage for languages Parakeet cannot serve, so batch never needs the legacy fallback for them: - resolve_route(): admission-time stt_route/provider_reason/provider_service (contract (c) fields). Unknown language is 'multi' -> Parakeet, as legacy. BYOK never changes the STT route (sync prerecorded never used BYOK keys). - enqueue_in_transaction(): writes a provider unit as provider_pending with merge_pending set, outside the GPU DRR ring, keeping the owner revision fence and late-capture watermark. Intended for an admit() enqueue hook. - ProviderSttStore/ProviderSttStage: paid-once job-row intent (pending -> running CAS mints the token), one Modulate call with client retries disabled, deterministic per-token result object, settle to the same result_ready transition Scheduler.complete performs. Redelivery reconciles, never re-spends; vendor failure and abandoned intents settle failed_held (never 'held', so quarantine recovery cannot pay twice). Nothing imports the new module yet: intake wiring, the queue consumer and the router follow once the lane-1 stubs and the admit() hook land. Expected C8 traces are pinned under pipeline_sim_goldens_pending/ with a strict xfail until the sim configs exist. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(batch): route the intake language decision through provider_stt.resolve_route Behaviour-neutral at legacy_sync 'on': unknown and 'multi' languages keep today's legacy fallback explicitly, and a parametrized test pins the old and new conditions equal for every language class with and without BYOK. This is the seam the C8 provider route replaces in draining/dark. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(batch): keep the pending C8 golden check inside the fast-unit CPU budget Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(batch): admit() enqueue= and adopt= hooks (additive, keyword-only) Contract (a) amendment (lead ruling 10-19): enqueue= lets the C8 provider stage write its units and their outbox rows outside the GPU ring in the admission transaction; adopt= lets intake take over a legacy ledger row it re-validates inside that transaction (a row legacy can no longer finish). With both unset, behaviour is unchanged. File owned by E1/Sol: needs Sol's agreement before merge. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(batch): C8 provider-STT consumer, route and draining/dark admission (lane 8 slice 2) - ProviderSttConsumer (kind provider_stt, role workers, 1800s lease, no heartbeat) maps the stage onto contract (a) results; the route POST /v2/batch-pipeline/provider-stt/run answers 200 / 409 retry / 400 malformed under Cloud Tasks OIDC, never 429/503. - Intake, with legacy_sync draining or dark: a language Parakeet cannot serve is admitted to the provider stage (outbox row in the admission transaction, wake after commit); legacy-owned content is fenced per contract (h) invariant 4 through lane 10's fence_decision; a stranded legacy row is adopted once by the admit() adopt= CAS; a legacy final-pass recording is acknowledged, never re-admitted. At 'on' every route is today's. - BYOK (David, 10-19): routed like every other upload. The batch 503 sync_batch_byok_unavailable and the live-upload legacy owner choice for BYOK are removed; enrichment runs on Omi's keys. - merge.py (lead sign-off, one line): provider results carry the recovery_version marker, so projection uses vendor labels as for recovered units. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(batch): resolve the provider-STT outbox off the event loop Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(batch): keep lane-8 tests inside the fast-unit CPU budget Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(batch): record BYOK as the admission-time funding decision (provider_reason='byok') The route stays language-only; provider_reason='byok' records that admission funded the unit while the validated keys were present. The provider stage never re-runs the keyless funding check for it. Writing the same value into ProjectionBinding.policy (lane 6's GPU dispatch skip) waits for E1 (#22448): neither ProjectionBinding.policy nor BatchUnitPolicy.provider_reason exists on integration yet. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(batch): cap-hold rehome adapter into batch admission (lane 8, C11 precondition) cap_hold_admission.admit_held decodes a claimed, sealed, unspent hold into one WAV and admits it through the same batch intake as uploads, under a content id derived from the hold, so a retried sweep re-presents the same content and the batch ledger guarantees one unit. Enabled only while legacy sync is draining or dark (cap_hold_mode batch_hold). Holds legacy recovery already spent on (piece receipts / processed paths) are refused and finish on the legacy path. Imports nothing from utils.sync.pipeline (C11). intake.accept_upload gains decode= for server-held audio; capture_decode exposes its canonicalization as canonical_pcm. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(sync): hand eligible cap holds to batch admission in recover_selected The one hook in #22388's recovery path (driven by /v2/cap-hold-recovery/sweep): under the existing row claim, an eligible hold in draining/dark is admitted to batch, marked batch_admitted, and erased; batch projection owns the conversation and usage, so the hold is never settled as legacy-transcribed. At legacy_sync 'on' the legacy path is unchanged. File owned by the Subscription session: needs its agreement before merge. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(batch): Firestore outbox for provider_stt (contract (b), lane 8) One row per provider unit keyed by its batch segment id, in a stage-scoped collection (dev and prod share a Firestore project). Lease-token fencing on every post-claim mutation, STALE/BUSY/DEFERRED/DISCARDED claim outcomes, transactional enqueue in the caller's batch transaction with the wake after commit, privacy discard at claim and sweep, and a sweep that re-wakes only lost wakes (older than 600s, no live lease). Wakes are pst- named Cloud Tasks built in utils/provider_stt_tasks.py, outside the env-ratcheted paths. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(outbox): route OutboxKind.PROVIDER_STT to lane 8's Firestore outbox The one-line selector branches in FirestoreOutbox and firestore_outbox (lead ruling 10-19: lane 8 owns the provider_stt outbox, lane 9's seam). Lane 9's selector tests now pin the still-reserved CAP_HOLD_REDRIVE as unserved. Lane 9's file: flagged for lane 9. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(firestore): register the provider-STT outbox claim/sweep query drivers Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(sync): gate cap-hold batch hand-off like legacy dispatch; batch_admitted is terminal Subscription-session review of #22467 (comment 6264627147): - The batch branch now runs _new_dispatch_allowed (funded allowance, hard restriction, daily audio ceiling) before admit_held; a gated owner's audio stays held. - A batch_admitted row is terminal: re-selecting it never claims, re-admits or settles (settlement would bill twice); it only finishes an interrupted erase. The adapter treats batch_admitted/completed/retained/purged as ineligible. - Tests pin the summary decrement in checkpoint's own transaction on held -> batch_admitted (once, not per retried save) and the re-select no-op. The durable sweep's backlog page (held/staging/sealing) and discovery kinds already skip batch_admitted rows. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Lane 8, slice 2 of C8. It wires the provider-STT stage into the admission path and applies the 10-19 rulings.
What
ProviderSttConsumer: kindprovider_stt, roleworkers, a 1800s lease, no heartbeat.POST /v2/batch-pipeline/provider-stt/run, behind Cloud Tasks OIDC (PROVIDER_STT_TASKS_OIDC_AUDIENCE, falling back to..._HANDLER_URL, with invokerSYNC_TASKS_INVOKER_SA).retry, 400 for a malformed task. It never returns 429 or 503.{"kind":"provider_stt","row_id","wake_token"}.legacy_syncisdrainingordark. Aton, every route is the same as today.fence_decision. Active, completed and held rows are acknowledged; capped rows keep their 409 until the pause ends.admit(adopt=...)CAS: the observed row is re-validated inside the transaction (fingerprint unchanged and still stranded).sync_batch_byok_unavailableand the BYOK-to-legacy owner choice inlive_upload. This changes behaviour aton: BYOK uploads from batch-cohort users are now admitted instead of held.database/batch_pipeline_intake.admit(): adds keyword-onlyenqueue=andadopt=hooks in a separate commit. With both unset, behaviour is unchanged. The file is E1/Sol's, so this commit needs Sol's agreement.merge.py: one line, signed off by lane 1. Provider results get therecovery_versionmarker, so projection uses the vendor's speaker labels, as it does for recovered units.Dependencies
outbox_for(PROVIDER_STT)still raises, so the provider route needs lane 9's outbox beforedraining. Aton, nothing calls it.main.pymount, from lane 1.Verification (local, m5, serial, unit layer)
test_batch_provider_stt: 54 passed, plus 3 strict xfails.Other suites, all passing:
test_batch_pipeline_intaketest_pipeline_characterizationtest_legacy_darktest_record_admission_review_fixestest_batch_pipeline_quarantine_recoverytest_batch_pipeline_schedulertest_sync_v2test_sync_cloud_taskstest_workers_consumer_contractscripts/typecheck.sh: 0 errors.No GCP, vendor or deploy.
Product invariants affected
Failure-Class: none
🤖 Generated with Claude Code