Skip to content

fix(stt): prevent recovery pacing jitter from exhausting live sessions - #20491

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/stt-recovery-soak-terminals
Oct 3, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/stt-recovery-soak-terminals

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Fix the recovery-ON terminal-after-text defect demonstrated by the local window→Soniox soak. Admission and transport pacers rebased each packet on its actual wake time, accumulating timer oversleep until the bounded live tail filled and marked an otherwise healthy leg capacity_full.
  • Share slot advancement between both recovery pacers: absorb sub-frame scheduling jitter against the armed audio slot; rebase after a slip of at least one frame so a stall cannot bank unbounded catch-up credit. Preserve 1× pacing, two queued/in-flight frames, all replay/deadline limits, session-owned controller, unique-target accounting, and refusal backoff.
  • Flag-OFF paths are unchanged: legacy receiver/replay modules, plain queues, writer gating, and default-off flag declarations are untouched. Update the existing pipeline/cadence documentation and add deterministic regression coverage.

Failure-Class: FC-live-stt-audio-lost-on-provider-death

Diagnosis and connection cost

The fake WebSocket peer (backend/testing/live_stt_soak/transport.py) has no capacity refusal or connection limit. The failure originates locally in backend/utils/stt/replay_delivery.py: the old RecoveryWriterPace.note_write and ReplayPacer.send added each packet's duration to the observed clock instead of the armed slot. Persistent ReplayTailSocket delivery then hit its 26-second tail cap. This is not the 20-episode limit or a fake-peer quota artifact; the deterministic test produces a local capacity_full and client 1011 after successful replay/text.

The original ON arm dialed Soniox and then Modulate: 32 paid dials for 16 sessions, versus 16 Soniox dials in the OFF control (which ran four-session batches). There is no extra steady-state probe or parallel spare: one paid serving leg per session. A cross-provider rebuild connects before closing the failed socket, so two transports can briefly overlap; legacy also connects before finishing the previous socket. The avoidable second paid dial/replay is a real cost/quota risk, removed by fixing the pacing-induced death rather than widening target limits.

Test plan

  • Backend environment preflight: 18 passed, no required failures; optional missing-provider/Redis warnings expected for isolated tests.
  • Five fast deterministic pacing tests: the two drift cases fail on main (0.695-second next slot versus expected 0.600 after twenty 30 ms packets and 5 ms wake oversleep), then pass with the fix; per-test CPU remains below 0.30 seconds.
  • Slow-marked real-receiver/managed-adapter regression, Soniox and Modulate: 180 virtual seconds of exact 1× input, six-second retained prefix, pacing timers 15 ms late. Main closes 1011 with local capacity_full; fixed code retains one paid dial, exact ordered PCM, zero skips, and bounded queues/tail.
  • BACKEND_UNIT_TEST_FILE_LIST with test_live_recovery_pacing.py, test_live_recovery_matrix.py, test_live_replay_provider_pairs.py, and test_stt_failover_recovery_flag.py, through backend/test.sh: 174 passed, no CPU-guard violation.
  • Ten-minute fake-local window→Soniox soak rerun: eight concurrent sessions, zero terminals; raw before/after Prometheus, progress, isolation, cleanup and report artifacts retained locally.
  • OMI_PR_BODY_FILE=.local/pr-stt-recovery-soak-body.md make preflight: 30 checks passed.
  • Post-commit scripts/pr-preflight --metadata-only --pr-body-file .local/pr-stt-recovery-soak-body.md: four checks passed.
  • Normal pre-push hooks passed without bypass. An existing recovery-matrix case initially hit the 0.30 s CPU guard under load; the required single-file backend/test.sh rerun passed at 0.25 s, and the subsequent full push gate passed at 0.11 s. No thresholds or allowlists changed.
  • Remote CI at 8fe206e2506dd8e479b5455108a9a9d436ddb9f3: all scheduled checks passed, including all four backend unit shards, unit guardrails/suite, Hermetic Backend E2E/merge gate, CodeQL, formatting, hygiene, OpenAPI, source closure, and PR metadata. Scope-excluded checks remain skipped, not claimed as executed.

Local soak rerun

PYTHONPATH=backend backend/.venv/bin/python -m testing.live_stt_soak.local --firestore-jar <existing-emulator.jar> --java <installed-java> --redis /opt/homebrew/bin/redis-server --sessions 8 --minutes 10 --order parakeet-window,soniox,modulate-velma-2 --recovery --output .local/stt-soak-soniox-20261004

Used the exact local launcher from cef17a9, with only the temporary busy-machine batch cap changed from four to eight as requested. Admission load was 57.9, so eight sessions were selected; they ran concurrently, not as four-session batches. The temporary launcher was removed after cleanup; no harness code is included in this PR.

Measurement Recovery ON rerun
Sessions / exposure 8 × 10 minutes (600.07 s wall)
Client terminals / terminal-after-text 0 / 0
Ready / received transcript 8 / 8
Window 503 faults 8
Recovered / exhausted 8 / 0
Paid dials 8 Soniox, 0 Modulate
Positive prefix replays 8
Replay audio / wall sum 45.48 s / 49.88 s
Replay wall p95 histogram upper bound ≤10 s
Skipped audio 0 s
Peak sampled load / RSS 112.03 / 409.66 MiB

All eight clients closed normally with 1000. No missing metric families, resets, or sampling errors. Artifacts: .local/stt-soak-soniox-20261004/{before.prom,after.prom,progress.json,report.json,isolation.json,cleanup.json}. The driver correctly retains REVIEW_REQUIRED, not a production GO verdict.

Every runtime child was credential-scrubbed, had empty temporary HOME/CLOUDSDK_CONFIG, and used only demo Firestore/local Redis/fake providers. ADC lookup failed with DefaultCredentialsError. All three owned service PIDs were reaped and all five loopback ports checked free afterward. No cloud, cluster, production, monitoring, real provider, merge, or deploy actions.

Fake-local results do not qualify vendor quotas/billing/quality, GPU/backfill headroom, production images, or fleet behavior. The recovery flag remains default off.

Generated with Devin

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@Git-on-my-level
Git-on-my-level marked this pull request as ready for review October 3, 2026 18:34
@Git-on-my-level
Git-on-my-level merged commit f8ae0d5 into main Oct 3, 2026
61 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/stt-recovery-soak-terminals branch October 3, 2026 18:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-03T18:37:48.634065Z 8fe206e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Git-on-my-level added a commit that referenced this pull request Oct 5, 2026
## What changed and why

Set `STT_FAILOVER_RECOVERY_ENABLED=true` for prod listen in the Helm
values and runtime overlay, regenerate the runtime manifest and
feature-flag registry, and align the listen pipeline/rollout docs. This
enables the recovery stack from #20391/#20491/#20534/#20560/#20671 for
new stable listen sessions after deployment.

Dev listen remains `false` in its chart and runtime overlay. The shared
base and code default stay `false`, so a missing environment variable
means off. `SONIOX_IDLE_CLOSE_SECONDS`, router mode, provider order, and
allocations are unchanged.

## Canary evidence — coordinator to complete

**PLACEHOLDER:** attach the 25% prod listen canary versus control
evidence after it holds through the next peak: exact image/config,
observation window including peak, cohort and scrape coverage, session
counts, recovery/continuity and terminal-after-text rates, latency and
error comparison, and the coordinator's acceptance decision. Canary
success is supplied context; this PR preparation does not independently
qualify production health. Keep this PR draft until the coordinator
fills this evidence and authorizes the stable flip.

## Deploy and rollback

Deploy prod listen Helm through the normal `gcp_backend_listen_helm.yml`
workflow (`environment=prod`, `mode=deploy`) after the coordinator
merges the approved config flip. This draft does not merge or deploy
anything.

Rollback: revert this PR and deploy listen through the same normal
workflow. For emergency rollback, use `gcp_backend_listen_helm.yml` with
`environment=prod`, `mode=rollback` (select the pre-flip Helm revision
if needed).

## Follow-up

This flag also flips the canary-only terminal-after-text (TAT) metric,
`omi_live_session_terminal_after_text_total`, fleet-wide. After stable
rollout, relax the canary-scoped selectors from #20660 for the alert's
volume floor, numerator, and denominator together. Alert rules are
unchanged here; the coordinator owns this follow-up to #20660.

## Product invariants affected

- INV-MEM-4: the generated runtime manifest is in scope; canonical
memory intake, promotion authority, and processing-host bindings are
unchanged.

## How it was verified

- `PATH="$PWD/backend/.venv/bin:$PATH" bash
backend/scripts/pre-deploy-check.sh`: passed runtime/workflow/state
validation for dev and prod, plus 284 deploy contract tests.
- `BACKEND_UNIT_TEST_FILE_LIST="$PWD/.local/stable-flip-test-files.txt"
bash backend/test.sh`: 73 cases passed across
`test_stt_failover_recovery_flag.py` (45) and
`test_listen_stt_rollout.py` (28), including Helm canary rendering and
flag-off behavior.
- Offline `helm template` for prod and dev: exactly one recovery
declaration per rendered listen container, prod `true` / dev `false`.
Compared chart env and composed runtime state against `origin/main`:
only prod listen's recovery value changed; other runtime settings and
code defaults were preserved.
- `OMI_PR_BODY_FILE=.local/pr-stable-flip-round2-body.md make
preflight`: all 38 selected checks passed, including the committed-diff
rerun.
- `scripts/pr-preflight --lane local --metadata-only --pr-body-file
.local/pr-stable-flip-body.md`: all 3 metadata checks passed.
- Re-ran the committed-diff preflight with the required INV-MEM-4
citation for `backend/deploy/runtime_env.yaml`.

Production acceptance remains the coordinator's canary evidence above.

## Tests

Added `test_stable_recovery_flag_is_scoped_to_prod_listen` in
`backend/tests/unit/test_listen_stt_rollout.py`: prod listen must
declare `true` in Helm values and both committed/freshly composed
runtime manifests; dev listen must declare `false`. Exhaustive runtime
declaration paths require pusher, sync, desktop-backend, jobs, shared
config, and every other service to leave the flag unset.
`test_stable_recovery_code_default_remains_off` checks unset and
explicit false against the production reader. Existing default-off and
canary tests are unchanged. This pins the rollout boundary identified in
Luna's review of #20696; the shared composition primitive already
validates general config consistency, while this test preserves the
intended service scope.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/20696?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="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
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