Skip to content

fix: drain accepted STT tails adopted after client close - #20560

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/stt-recovery-adopted-tail-drain
Oct 4, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/stt-recovery-adopted-tail-drain

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

  • Carry client-close drain eligibility into an already-connected successor before starting its adopted tail pump. Previously, close marked only the old socket, so the new pump saw an inactive host and discarded accepted audio despite unused shutdown budget.
  • Keep the original shared 28-second delivery + 2-second cleanup deadline, no-new-paid-dial-after-departure guards, and default-OFF legacy path unchanged. Adoption reuses a provider dial begun before departure; it does not authorize a new dial.
  • Add deterministic runtime/receiver/provider-wire regression coverage and document the handoff in the existing listen pipeline guide.

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

Product invariants affected

none

Test plan

  • Regression fails on unchanged origin/main (d04010dffcce) because the post-close adopted successor delivers the prefix but discards its nonempty accepted tail.
  • After the fix, exact prefix + tail PCM reaches the real provider send loop before EOS, final LAST callback persists before conversation finalization, and skipped audio is zero.
  • Focused canonical backend/test.sh: 243 tests passed across shutdown, provider pairs, flag-OFF/session pinning, recovery matrix, pacing, and transcript replay. No fast test exceeded the 0.30-second CPU guard.
  • Strengthened post-close blocked-wire test proves an attempted tail write expires at the unchanged shared deadline, meters only unwritten bytes once, closes transports, and leaves no STT tasks. Final canonical shutdown-file rerun: 14 passed, no CPU guard trips.
  • Eight-session shutdown-heavy fake-local arm, with each client closing about five seconds after injected window 503 during active prefix replay; 45-second post-close observation.
  • PYTHON=backend/.venv/bin/python OMI_PR_BODY_FILE=.local/pr-stt-adopted-tail-body.md make preflight: all 31 selected checks passed. scripts/pr-preflight --lane local --pr-body-file .local/pr-stt-adopted-tail-body.md: all 31 passed. Touched production-file Pyright: zero errors. Evidence .local/adopted-tail-{preflight,pr-body-check,pyright}.log.
  • Normal pre-push hooks passed without bypass on head f00d466b3aec086a168a24a490656647f4a44a05: shared preflight/metadata, CPU-guarded units, formatting, API/released-client compatibility and source closure.
  • Exact-head GitHub CI green on f00d466b3aec086a168a24a490656647f4a44a05: all four backend unit shards, backend unit suite/guardrails, Hermetic Backend E2E/merge gate, Listen Pusher Stack Gauntlet, metadata, formatting, hygiene, API/source-closure contracts, and CodeQL passed. No failed or pending checks; scope-excluded/post-merge skipped checks are not claimed as executed. Evidence .local/ci-adopted-tail.json and .local/adopted-tail-ci-watch.log.

Local shutdown-heavy soak

Runtime: main d04010dffcce plus this reviewed four-file diff; production diff SHA256 483f116d503b92c5eaffc5c99caf2f9c11e4e863901c64f35293e3faa637519d. Harness: #20477 plus the preserved round-3 shutdown observer snapshot; only the owned-PID file destination changed.

Measurement Result
Concurrent sessions / active-replay closes 8 / 8
Fault-to-close request 5.073–5.077 s
Skipped accepted audio 0.00 s total; zero in each session
Server close p95 / max 5.351 s / 5.351 s
Paid dials 8 Soniox, 0 Modulate; 1.0/session, exactly one in each
Terminals / terminal-after-text 0 / 0
Positive replays / sessions receiving text 8 / 8
Peak sampled listen RSS / CPU seconds per session 400.19 MiB / 0.2595

Close duration is server disconnect receipt through ASGI-handler completion; p95 uses nearest rank (with eight sessions, p95 equals max), not client handshake duration. Every adopted tail started with host_active=false, draining=true, 4.16 s queued, and ended with zero queued and no death. This replaces the prior arm's 4.04 s loss per session without spending a new deadline or dial.

Frozen count-only evidence: .local/adopted-tail-soak-summary.json; raw .local/stt-adopted-tail-shutdown-20261004/{before.prom,after.prom,report.json,batch-1.json,progress.json,isolation.json,cleanup.json}; harness/source snapshot hashes .local/adopted-tail-harness-source.json. RED/GREEN tests: .local/adopted-tail-{red,green,selected-green}.log. All three spawned services were reaped; all five service ports were verified free; no other lane's process was signalled. Temporary harness changes were restored; only the intended four files remain changed.

Isolation: #20477 local harness plus the reviewed round-3 count-only shutdown observers; fresh demo Firestore/Redis/listen and fake loopback provider peers, credential-scrubbed allowlisted environment, empty HOME/CLOUDSDK_CONFIG, failed ADC lookup, loopback-only socket guard, no dotenv/cloud identity/real provider keys. Every spawned PID is recorded at spawn in this worktree's .local/owned-pids.txt; only newly owned registered process objects may be signalled. Temporary harness files are restored/removed after execution and are not committed.

Fake-local evidence is not vendor billing/quota/quality, GPU, production persistence/finalization, or fleet qualification. Recovery remains default off. Draft only; no merge, deployment, cluster, or monitoring actions.

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 4, 2026 03:16
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Git-on-my-level
Git-on-my-level merged commit aed3ef1 into main Oct 4, 2026
64 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/stt-recovery-adopted-tail-drain branch October 4, 2026 03:16
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