Repository navigation
fix(batch): provider-route units join the ordered merge - #25187
Conversation
Provider-route units (languages Parakeet cannot serve, mostly Japanese) settled to result_ready and stayed there: on 2026-11-13, 1.68M were unmerged and 97-100% of each day's settles since 11-05 never committed, so no conversation was projected from them. Three gaps, closed behind BATCH_PIPELINE_PROVIDER_MERGE_MEMBERSHIP_ENABLED (on unless false): - provider admission stamps fresh_capture, as GPU admission does - provider settle stamps ready_at, so the head wait can apply - the serving route wakes one coalesced owner drain after a delivery that settles or terminally ends a unit; provider rows admitted before the stamp count as catch-up, so fresh rows commit ahead of that backlog The commit body, privacy fence, log chain and projection order are unchanged; no row skips the head wait or the catch-up depth hold. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The working-tree scan read backend/.venv and backend/.openapi-venv and failed every local pre-push from a worktree that had run make setup, on the Firestore SDK's own computed collection names. Co-Authored-By: Claude Fable 5.2 <[email protected]>
- a provider row settled before the ready_at stamp waits from its intent's settled_at, so it can also pass an unready head - an owner past the wake-task bound queues instead of being dropped - wake tasks are tracked background tasks Co-Authored-By: Claude Fable 5.2 <[email protected]>
…cker Co-Authored-By: Claude Fable 5.2 <[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. |
main fixed the collection-budget virtualenv scan itself (#25186); take its version of the check and its test. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The wake holds no obligation: the settled row is durable and a lost wake only delays the owner to its next settle or the maintenance page. Co-Authored-By: Claude Fable 5.2 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1642acbc4c
ℹ️ 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._waiting and len(self._tasks) < self._max_owners: | ||
| waiter = next(iter(self._waiting)) | ||
| del self._waiting[waiter] | ||
| self._start(waiter) |
There was a problem hiding this comment.
Avoid starting queued drains during cancellation
When the owner bound is exceeded and the process shuts down, cancelling an active drain runs this finally block and starts a queued owner's task. However, drain_background_tasks() in backend/utils/executors.py cancels and awaits only a snapshot of the tracked tasks, so the newly started drain escapes shutdown and can attempt database work after the shared clients and executors are closed. Skip promoting queued owners when _run is exiting due to cancellation, or explicitly stop the coalescer before draining background tasks.
Useful? React with 👍 / 👎.
…der rows only (#25204) ## What Follow-up to #25187. While a new switch is off (the default), the ordered merge does not commit provider-route catch-up rows. An owner's fresh provider rows still commit, ahead of that held backlog, whenever the fresh-row query is available (see the known limits for when it is not). ## Why #25187 reached `backend-integration` on 2026-11-13 at 11:36Z. Measured in production (job and result metadata, request logs): - Active provider owners began draining their own already-transcribed backlog: about 230,000 rows an hour left `result_ready` (170,000 at catch-up depth 4, 125,000 at depth 1). - Projection takes owners from one FIFO queue with no class for fresh work. Of results committed 10–20 minutes earlier, 35% were still unprojected, and 45% of those captured under an hour before. It was about 0.2% before the deploy. That delay applied to every user, not only provider-route users. - The owner drains run in the serving process. `backend-integration` was at its instance ceiling, and completed enrichment and provider-STT requests fell by about half until the ceiling was raised from 35 to 70. - What the fix was meant to do did work: of provider units settled 3–8 minutes earlier, 53% were committed at 12:35Z (0% before, 3% while admission stamps were missing). So the fault is the unmetered release of the backlog, not provider merge membership. This PR removes the release from the owner wake and leaves delivery of fresh units in place. ## Change `BATCH_PIPELINE_PROVIDER_BACKLOG_RELEASE_ENABLED`, off unless `true`. While off, in `utils/batch_pipeline/merge.py`: - A provider-route row that is not stamped fresh (`fresh_capture` absent, or false) is not committed. It stays `result_ready` with `merge_pending`. This holds whatever `BATCH_PIPELINE_PROVIDER_MERGE_MEMBERSHIP_ENABLED` is set to: on 2026-11-13 at 13:00Z, 78 minutes after that switch was set to `false`, 3,435 provider rows captured over a day earlier were still committed in a 2-minute window, 2,925 of them through the head wait, because rows stamped `ready_at` while it was on stay eligible afterwards. Unprojected results rose from 78,204 (12:12Z) to 117,076 (12:56Z). - The fresh-first probe still runs for that owner, so its fresh rows commit ahead of the held rows. It does not run while the fresh query is backing off after `FailedPrecondition`; fresh rows behind a held row then wait for the query to work again. The probe now also runs when the catch-up depth hold is switched off (depth 0), both when the held row heads the owner and when an unready provider backlog row does (there the head wait alone would pick a held row and commit nothing). - While the fresh query is backing off after `FailedPrecondition`, a held owner is not probed and its backlog stays held. Before review this path recursed without bound. - The hold writes no `merge_holds` marker and adds no owner to the in-memory re-offer set, including when the owner is at the depth cap and whether the held head is ready or not, so maintenance does not re-drain held owners every pass. - A recovered provider row that is not fresh is held as well: the recovery wake does not pass the backlog hold. GPU-route rows, recovered or not, are unchanged. Details: `backend/docs/listen_pusher_pipeline/changes/2026-11-13-provider-backlog-hold.md`. ## What is not delivered while the switch is off - The backlog transcribed since 5 Nov (about 1.59 million rows at 12:35Z). - New provider uploads that arrive more than 10 minutes after capture (`FRESH_CAPTURE_LAG_SECONDS`): 13% of 1,820 provider admissions sampled on 2026-11-13. These were not being delivered before today either. Known limit: when an owner's oldest pending row is a GPU-route row that is not ready, a fresh provider row behind a held provider row waits for that head, because the fresh probe only runs behind a catch-up head. Provider owners are almost entirely single-route, and this is the behaviour GPU rows already have. Known limit: a GPU-route catch-up row (an old upload) that sits behind a held provider row of the same owner waits with it, because the merge takes an owner's rows in capture order and cannot select past the held row. Fresh rows of either route still commit ahead of the held row through the fresh probe. The exception is while the fresh query is unavailable (`FailedPrecondition`, a missing index): the probe backs off, and a fresh row behind a ready held provider row waits until the query works again. It ends with the metered release. ## Rollout and the default-off switch This is a default-off gate, so here is its plan. It is not a per-user ramp; it guards one stock of rows. - Ships off. `backend-integration` then turns `BATCH_PIPELINE_PROVIDER_MERGE_MEMBERSHIP_ENABLED` back on (it was set to `false` after the measurements above). - The metric that must stay clean when that is turned on: share of results committed 10–20 minutes earlier that are still unprojected, under 2%; and completed enrichment requests per minute on `backend-integration`, flat. - The backlog is released by a metered job with its own rate setting, after the projection owner queue gives fresh owners their own class. Owner: the provider-STT drain owner (anx `card:drain-stuck-provider-stt-backlog-for`). Date: before 2026-12-05, when the oldest staged results reach the bucket's 30-day lifecycle. The switch is removed with that job. - Turning this switch to `true` is the old behaviour (release paced only by the depth hold) and should not be used without projection headroom. Rollback of this PR's effect: `BATCH_PIPELINE_PROVIDER_BACKLOG_RELEASE_ENABLED=true`. `BATCH_PIPELINE_PROVIDER_MERGE_MEMBERSHIP_ENABLED=false` now stops fresh delivery too (no new row is stamped fresh, and unstamped rows are held), without releasing anything. ## Tuning disclosure No value changes and no new knob. No new pipeline state: a held row keeps `state=result_ready`, `merge_pending=true`. Its exit is a commit, when the switch is on or the release job offers it, or the existing terminal paths. ## Product invariants affected none ## Failure class (fixes) Failure-Class: new Proposed: `FC-backlog-release-shares-lane-with-fresh-work`. A fix that made stuck work eligible released all of it at once into stages (projection owner queue, serving CPU) that fresh work also depends on, with no class and no rate of its own. ## Tests ``` cd backend .venv/bin/python -m pytest tests/unit/test_batch_provider_merge_membership.py tests/unit/test_batch_provider_stt.py \ tests/unit/test_batch_pipeline_merge_fresh_first.py tests/unit/test_batch_pipeline_merge_head_wait.py \ tests/unit/test_batch_pipeline_recovered_release.py tests/unit/test_pipeline_characterization.py -q ``` New in `tests/unit/test_batch_provider_merge_membership.py`: by default only fresh rows commit and the backlog stays ready, with no hold marker and no re-offer, however far projection advances; opting in releases it under the depth hold; fresh rows pass a held backlog with the depth hold off; a provider row stamped not-fresh is held too; a ready backlog row does not pass an unready head; GPU catch-up rows are not affected. Added after review: the membership switch off still holds the backlog; a fresh row passes an unready backlog head at depth 0; an unavailable fresh query is asked once and the backlog stays held; a held head at the depth cap writes no marker. Each of the four fails without the fix. `tests/unit/test_flag_budget.py` failed in CI on `b1165bd` (the new name was missing from the budget count and the helper-switch list); fixed. The two provider golden traces (`provider_stt_ja`, `provider_stt_unsupported`) admit their uploads after the fresh lag, so their config now sets the switch on and the traces are unchanged: they keep pinning the commit and projection path. ## Review Independent review (Luna), round 1 on `b1165bd`: FIX, two blockers (no fresh probe at depth 0 behind an unready provider head; unbounded recursion when the fresh query is unavailable) and one should-fix (a depth marker written for a held head at the cap). All three are fixed with a test each. The reviewer found no privacy-fence bypass and confirmed the other commit routes use the guarded path. Round 2 on `bfa768a`: FIX. Round-1 findings confirmed closed; no privacy-fence bypass. Two blockers and two should-fix: 1. Blocker, fixed: a recovered non-fresh provider row passed the hold through the recovery wake. It is now held; test in `tests/unit/test_batch_pipeline_recovered_release.py`. 2. Should-fix, fixed: an unready held provider head at the depth cap still wrote a marker. Test added. 3. Blocker, left open as existing production state: the maintenance page (`due('result_ready')`) takes the 100 oldest `result_ready` rows with no cursor, so rows that never commit pin it. That page is already pinned: on 2026-11-13 at 13:35Z its 100 rows were all 9.1 to 10.1 days old (71 GPU-route, 29 provider). This PR adds more rows that stay `result_ready`, behind those. Rows that can commit are reached by their owner wake and the per-pump drains, as today. One class is not: a GPU-route catch-up row behind a held provider row of the same owner (the known limit above) is reached by its wake, commits nothing, and has no marker or page to bring it back; it waits for the release like the provider row in front of it. The fix is a cursor on that page plus the metered release. 4. Should-fix, fixed after the head confirmation: a probe made only for the backlog hold now backs off on its own clock, so its failure no longer switches the depth hold off for the merge instance. Test added. Head confirmation on `2e675fc`: FIX. It confirmed 1 and 2 closed, no privacy-fence bypass, and no change for owners without provider rows. It found my account of items 3 and 4 inaccurate; both are corrected above (the GPU catch-up case is stated, item 4 is now fixed in code). It also raised custody: held results are GCS artifacts under the 30-day staging lifecycle, and this PR adds no enforcement of the release deadline. That is accurate and stays open by design: these rows have been undelivered since 2026-11-05 with or without this PR, releasing them unmetered is what delayed every user's results on 2026-11-13, and the metered release has an owner and a date (before 2026-12-05, see Rollout). If that job is late, the oldest held results become unprojectable. Narrow confirmation on `b1cbfad`: item 4 confirmed closed, recursion terminates on every path, no new data-loss or privacy-fence risk, and the account of the two open items matches the code. Its verdict was FIX for one sentence in this description ("Fresh rows of either route are not affected"), which lacked the query-availability exception; the sentence is corrected under the known limits. No code change followed, so the head is unchanged. Rulings by the rollout owner session (goal-owners rollout, R14 self-drive, 2026-11-13), both accepted for this PR: 1. The maintenance page without a cursor is existing behaviour and not a blocker. The added cost, an old GPU-route upload waiting behind a held provider row of the same owner, is acceptable; the cursor goes in the metered-release PR. 2. No enforced release deadline for held provider results is accepted on condition that the metered release has an owner and a date: the provider-STT drain owner, 2026-11-28, recorded on anx `card:drain-stuck-provider-stt-backlog-for` with what is lost if it slips. Not tested here: production behaviour. The acceptance read after re-enabling is the share of fresh provider units settled 3–8 minutes earlier that are committed, and the two must-stay-clean metrics above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
… s of speech (#25192) ## What A provider-route batch unit whose strict-VAD speech is under **2 s** is now answered as local silence, with no vendor call. Before this change, only a unit with no speech spans at all skipped the vendor. The threshold is `BATCH_VENDOR_MIN_SPEECH_SECONDS`: default `2`, and `0` restores the old no-spans-only rule. ## Why David, 2026-11-13: process user recordings economically; skipping very short ones is fine. Provider units are ~31 s capture spans, and each is billed for its full duration even when VAD found a second of speech. Production sample (2026-11-13 ~10:30Z, ro-prod, metadata only): - 2,966 settled `result_ready` provider-route units; 1,345 had no speech and were already skipped. - Share of **billed** provider audio by measured speech: under 1 s **20%**, 1–2 s 6%, 2–3 s 3.6%, 3–5 s 7.6%, 5–10 s 15.4%, 10 s or more 47.5%. - So units under 2 s are **26% of billed provider audio**. Provider STT runs at about $155–190/day (KB `daily-cost-current`, 11-05..11-09), so this saves about **$40–50/day** on fresh input, plus the same share of the provider backlog still to drain. - Content lost per skipped unit: under 2 s of speech in a 31 s span, a word or two at most. On 11-02 most `empty_asr` quarantines were exactly these sub-2 s units, so vendors often return nothing for them anyway. ## Change - `config/batch_pipeline_vendor_failover.py`: `min_speech_seconds()` reads `BATCH_VENDOR_MIN_SPEECH_SECONDS`. Default 2, range 0–10; malformed or out-of-range values keep 2. - `utils/batch_pipeline/provider_stt.py`: `_skips_vendor(inspected)` is decided once in `_prepare` and carried on `_Call.skip_vendor`. The health arm, the intent's `vendor_skipped`, `_call_sync` and `_call_async` all use it. The skip reuses the existing local-silence path end to end: `silence_payload`, outcome `silence`, `audio_seconds=0`, normal settle and merge. No new state, and no change to the merge, projection, custody or privacy fences. - The intent keeps `measured_vad_speech_seconds > 0` next to `vendor_skipped: true`, so a short-speech skip stays distinguishable from true silence. The abandoned-intent reconcile already settles `vendor_skipped` intents as silence without billing. - New counter `omi_batch_pipeline_vendor_short_speech_skipped_audio_seconds_total{provider}` measures the unbilled audio (frozen-name pin 18 → 19). It counts on the direct path and on the abandoned-intent silence reconcile. - The flag registry, `flag_budget.json` and the rendered registry doc are updated. - Tests: - short speech skips the vendor, is marked, and is counted; - threshold 0 restores the old rule; - malformed values keep the default; - exactly 2.0 s still calls the vendor. - The shared `SPEECH` fixtures widened from 0.5 s to 2.5 s so existing paid-path tests keep exercising the vendor. ## Not in scope - The GPU route: GPU cost is fixed node time (mostly idle), so skipping there saves nothing. - Age-based skipping of old backlog: measured separately and reported to David. - The provider merge fix: that is #25187, owned by the provider-STT design session. This branch is rebased on it. - Allowance runs before VAD in `_prepare`, so a unit held for allowance is deferred before the skip can apply. That ordering already applies to true silence and is unchanged here; moving VAD ahead of allowance is a separate design question. ## Review Luna (gpt-6-luna, read-only) on the first commit: P1 conformance test still expected a vendor call for 1 s of speech (fixed: span widened); P2 reconcile path did not count skips (fixed, with a test); P1 allowance-before-VAD (pre-existing for silence, left as noted above). ## Rollout - Ships on. - Rollback: set `BATCH_VENDOR_MIN_SPEECH_SECONDS=0` on `backend-integration` (where the provider stage serves). Units already skipped keep their silence result. - Watch: - `omi_batch_pipeline_vendor_short_speech_skipped_audio_seconds_total` should be about 26% of billed provider audio; - `omi_batch_pipeline_vendor_attempt_audio_seconds_total{outcome="ok"}` should fall by that share; - silence share of provider results should rise from about 43% to about 55% of units. - Must stay flat: provider settle rate and merge commit rate. - Verification layer: local unit tests only. No production read of the new metric yet. ## Landing verification The provider merge emulator fixture now uses 2.5 seconds of strict-VAD speech so it continues to exercise the paid vendor path under the new default. The nojob emulator's repeat-sweep assertion compares selected row identities because a new sweep recomputes ages against wall time; its minimum-age assertions remain. Main's additional flags are preserved in the ledger count. Failure-Class: none 🤖 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/25192?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/25192?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F25192&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. -->
What
Provider-route batch units (languages Parakeet cannot serve; Japanese is about 85% of them) are transcribed and then never merged, so no conversation is projected from them. This makes them full members of the ordered merge the GPU route already uses.
Measured in production on 2026-11-13 (job metadata only):
result_readywithmerge_pendingset; 98% of a 3,000-row sample were provider-route.Why they did not merge
ProviderSttStage._finishsettled and returned. The only discovery left was the maintenance page of the 100 oldestresult_readyrows, and two owners filled it.ready_at. The head-wait probe orders byready_at, so a ready provider row could never commit past an unready head.fresh_capture, so fresh-first could not apply.Change
Behind one kill switch,
BATCH_PIPELINE_PROVIDER_MERGE_MEMBERSHIP_ENABLED(on unlessfalse):fresh_capturewith the rule GPU admission uses.ready_aton a result.fresh_capture(admitted before the stamp) as catch-up, so an owner's fresh rows commit ahead of that backlog and the backlog follows under the existing depth hold.utils/batch_pipeline/provider_drain.py,Serving.drain_settled_async). Per owner per process: one drain after 2 s, one after the head wait; a settle during that round buys exactly one more round. At most 4 drains run at once per process. Past 4,096 live wake tasks an owner waits its turn; no request is dropped. Wake tasks are tracked background tasks.ready_atstamp waits from its intent'ssettled_at: when theready_atprobe finds no waiter, the merge reads the owner's earliest ready row once (one extra query per blocked drain), so those rows can also pass an unready head after the head wait.Unchanged: the commit body, late marking, log chain, privacy fence and projection order. No row skips the head wait or the catch-up depth hold. The wake is an in-memory hint; if the process stops first, the owner is drained by its next settle or the maintenance page, as today.
Details:
backend/docs/listen_pusher_pipeline/changes/2026-11-13-provider-merge-membership.md.Rollout
Ships on. Rollback: set the switch to
falseonbackend-integration(and wherever the merge runs). Rows stamped while it was on keep their fields and stay eligible for the existing head wait and fresh-first; nothing needs undoing.Watch after deploy:
committed(about 0% now; should pass 90% for fresh units).firestore_transaction_contention operation=batch_pipeline_store ... outcome=exhausted.event=batch_provider_drain outcome=queued|retry.Known effect: owners who are active now will also start draining their already-transcribed backlog, paced by the catch-up depth hold (16 rows awaiting projection per owner). Owners with a backlog and no new settles are not woken by this change.
Tuning disclosure
No existing value changes. New knobs in
utils/batch_pipeline/provider_drain.py:No new pipeline state.
Background-task ratchet
The owner wake is a tracked background task that outlives its request, so it adds one entry to
tests/unit/fixtures/background_task_baseline.json. Why losing it at SIGKILL is safe: it holds no obligation. The settled row is already durable asresult_ready; the wake only asks the merge to commit it, and a lost wake delays that owner until its next settle or the maintenance page, which was the only path before this change. Awaiting it in the request would hold aprovider-sttqueue slot through the 60 s head wait. A request-backed owner-wake task is the durable replacement once a queue for it exists.Review
Independent exact-head review (Luna), two rounds:
e3f20ba: FIX, three should-fix, no blockers. All addressed (unstamped rows and the head wait, the owner bound no longer drops, tracked background tasks).5b09fad: no remaining merge, projection-chain, duplicate-commit or drain issue. Its one finding was in a CI-check commit this branch no longer carries (main fixed that check in ci(firestore-budget): skip virtualenvs and site-packages when scanning #25186 and this branch takes main's version).result_readywithmerge_pending; of units settled 1 h to 6 days earlier, 97-100% stillresult_ready.Product invariants affected
none
Failure class (fixes)
Failure-Class: FC-bounded-discovery-pinned-by-blocked-page
The 100-row oldest-first
result_readypage was filled by two owners' blocked rows, and provider units had no other route to the merge. This change gives them the per-owner wake the GPU route has; it does not change the page itself.Tests
New:
tests/unit/test_batch_provider_merge_membership.py(29 tests) covers both stamps and the switch-off shape, the head wait and fresh-first on provider rows through the real admission, settle and merge transactions, the unstamped-backlog classification, the coalescer (burst, re-request during a round, owner bound, failure, concurrency), the delivery hook, anddrain_settled_async.Two golden traces (
provider_stt_ja,provider_stt_unsupported) gain thefresh_capturefield on provider jobs and nothing else.Not tested here: live behaviour against Firestore, and the effect on maintenance load of more owners holding
merge_holdsmarkers.🤖 Generated with Claude Code