Skip to content

feat(stt): close idle Soniox transports behind a default-off flag - #20650

Merged
Git-on-my-level merged 10 commits into
mainfrom
feat/soniox-idle-close
Oct 4, 2026
Merged

Git-on-my-level merged 10 commits into
mainfrom
feat/soniox-idle-close

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Active VAD currently withholds silence but keeps Soniox's paid connection open. Add default-off SONIOX_IDLE_CLOSE_SECONDS; suggest 45 for a first canary. Unset/zero returns the original adapter and does not register idle metric series. Positive thresholds below 20s clamp to 20s and warn once per process. SONIOX_IDLE_REARM_SECONDS defaults to 60s (hard minimum 60s); SONIOX_IDLE_MAX_CLOSES_PER_HOUR defaults to 12 closes per rolling hour. A listen-session-owned budget survives provider leg replacement in both connector paths. Rate-limited closes leave the active transport serving audio and keepalive normally.

After continuous VAD silence, finalize and drain the old socket for at most two seconds, then close/abort its transport while retaining the logical provider leg. The next VAD onset retains original PCM pre-roll, waits for the old callback drain, opens the same captured endpoint/config through the shared Soniox connector, and sends pre-roll before onset. A real failed reopen enters ordinary connect/failover handling; retained onset queues behind recovery replay with already accepted capture prefixes excluded. Planned closes publish no death, breaker/quarantine strike, fallback or cost-router failure evidence. Genuine account/config errors still propagate.

Rebase each socket's restarted provider clock onto the existing accepted-audio ledger, including Soniox elapsed-axis mode, then use the existing wall/capture projection. Socket epochs reset provider-local speaker IDs. Shutdown while suspended finishes normally without reopening. Five unlabeled metrics measure closes, reopens, reopen latency, failures and estimated connected seconds avoided.

Billing scope: Soniox explicitly bills the full stream, including keepalive-only idle time (docs). Deepgram streaming STT is billed by processed audio duration (official answer); keepalive control frames contain no audio (docs), so audio-free socket idle should not be billed as processed audio (inference from those sources). Modulate lists processed-audio-hour pricing (pricing); a keepalive-only billing guarantee is not documented there. Sent silence is still processed audio. Leave both adapters unchanged.

Validation: 918 focused fast tests pass through backend/test.sh on the synchronized branch, including 54 idle lifecycle cases, 149 runtime-env cases and 129 connector/rejection/rate-limit/recovery cases. The canonical runtime-env fixture also passes separately with the unchanged CPU guard. New regressions exercise 120 alternating threshold/onset cycles with recovery on/off and default/custom hourly caps, exact cooldown/rolling-hour expiry, session budget continuity across socket replacement, safe config parsing and one-time floor warning. Unset/zero parity snapshots the real default Prometheus registry with cold and already-registered idle metrics, asserting identical global series and unchanged idle samples. Legacy connector fixtures assert the receiver budget is passed through both normal and same-provider dials. Typecheck: 0 errors. Local preflight and all normal exact-head push gates passed. Exact-head CI results are available in the PR checks. A repeated CI timing failure in the unchanged containment detector required a one-line dictionary field-read fast path, retaining the generic Mapping/object fallback. All 162 containment tests pass, including new non-dict Mapping parity, with the original 0.30s limit unchanged. Seven local trials of six maximum-layout decisions reduced median CPU from 102ms to 41ms. Recent main changes are incorporated; both concurrent pipeline documentation sections are preserved. Luna's P2 findings are addressed; no new review verdict is claimed.

Local fake-mode soak uses draft #20477's preserved harness on throwaway branch soak/soniox-idle-close-round2, with all 16 changed production Python files byte-identical to execution head 049ede6e3f5f9b12385bf6a63896485ae77d454e; the final STT implementation is unchanged by the later containment lookup optimization (the fake harness is isolated from the production tree). Two sessions per arm, 129s each, 6s public speech / 60s silence, 45s threshold, 60s rearm and default 12/hour cap. Scrubbed environment; local Firestore/Redis emulators; ADC unavailable. Every manually launched process, service and metrics probe records its PID in .local/owned-pids.txt; all owned service PIDs were reaped. No provider fault is injected.

Recovery Closes Reopens Reopen p95 Connected seconds Avoided vs flag-off Lost-onset seconds Terminals
on 2 2 10.19 ms 213.34 44.35 0 0
off 2 2 4.45 ms 215.48 42.21 0 0
flag-off control 0 0 n/a 257.69 0.00 0 0

Reopen failures: 0. Onset byte hashes matched 2/2 per enabled arm. Flag-off emitted no idle series. The avoided counters read 43.35s / 42.24s; independent arm scheduling accounts for small differences versus measured socket lifetime. Cooldown reduces closes from four in the historical round-one run to two in each current enabled arm. The generic recovery gate remains REVIEW_REQUIRED because there is no fault injection; the requested idle assertions pass. Count-only receipts: .local/round2-synced-soak-summary.json, with raw metrics, isolation and cleanup receipts in the three arm directories. No live Soniox or acoustic acceptance is claimed.

CI: head 475ac229d16bd73ca91facca35e60fe17f79305f: exact-head checks; flag-off keeps its original wire path. Draft only; no merge or deployment. Fake dial latency is not real Soniox handshake latency or acoustic acceptance.

Product invariants affected: none

Failure-Class: none

Additive, default-off cost optimization; existing failure contracts remain authoritative.

Line-Count-Exception: backend/routers/listen/receiver.py | 2398 -> 2402 | Add session-owned Soniox churn budget and pass it through the two legacy connection paths so provider leg replacement cannot reset the rolling hourly cap.

@Git-on-my-level
Git-on-my-level marked this pull request as ready for review October 4, 2026 16:53
@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 e7116e5 into main Oct 4, 2026
59 checks passed
@Git-on-my-level
Git-on-my-level deleted the feat/soniox-idle-close branch October 4, 2026 16:53
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