Repository navigation
perf(listen): close idle Soniox sockets sooner - #22365
Conversation
Soniox bills every connected second, keepalive silence included. On
2026-10-18, 2,857 of 3,448 billed Soniox hours carried no audio.
- Idle close is default-on: SONIOX_IDLE_CLOSE_SECONDS defaults to 20 s
(0/off is the kill switch). Prod's 45 s pin is removed.
- Re-arm floor is configurable and lower: SONIOX_IDLE_REARM_SECONDS
default 10 s (floor 5 s), was hard-coded 60 s.
- Hourly close cap raised: SONIOX_IDLE_MAX_CLOSES_PER_HOUR default 120,
was 12.
- New wall-clock close when the client sends no frames at all for
SONIOX_IDLE_NO_FRAMES_SECONDS (default 20 s, 0 disables), independent
of VAD. It honors the re-arm floor; the next frame reopens through the
existing onset/rebase path.
- New omi_soniox_connected_seconds_total{demand_cohort} measures billed
websocket-open time directly, plus
omi_soniox_idle_no_frames_closes_total.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lowlist The prod pin is gone; the code default governs both charts. 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: 8b4981744e
ℹ️ 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".
| delay = self.check_no_frames() | ||
| if delay is None: | ||
| return | ||
| await _sleep(delay) |
There was a problem hiding this comment.
Replace the watchdog sleep with an interruptible wait
When a listen WebSocket disconnects while this coroutine is sleeping, the per-connection shutdown event cannot wake it, and this task was created without the supervisor's task set, leaving cleanup dependent on later wrapper-specific cancellation. Use wait_for_event(event, delay) with the connection shutdown event so disconnects stop the watchdog immediately rather than allowing it to remain alive and potentially start an idle close during teardown. The backend WebSocket concurrency contract explicitly prohibits bare asyncio.sleep() in polling loops for this reason.
AGENTS.md reference: backend/AGENTS.md:L293-L296
Useful? React with 👍 / 👎.
…ames close
Review found every idle reopen mints a new speaker scope, so a faster VAD
cadence churns live speaker labels. Re-scope:
- VAD close defaults return to the prod values (45 s, re-arm 60 s,
12 closes/hour); 45 s is now the code default.
- No-frames close defaults to 60 s, spends the shared hourly cap and
re-arm floor, and waits the 4 s VAD hangover after speech/ungated audio.
- omi_soniox_idle_closes_by_trigger_total{trigger=vad|no_frames}
replaces the no-frames-only counter.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Why
Soniox bills a real-time stream for every second it is connected, keepalive silence included. On 2026-10-18, 2,857 of 3,448 billed Soniox hours carried no audio ($171 of $238), per
opus-soniox-attribution.md. One part of that is sockets kept open while the client sends no frames at all: an app in the background, a disconnected pendant, or a socket the client left open.Today's idle close never fires for those sockets, because only VAD output drives it, and VAD only runs when frames arrive.
What
The PR was re-scoped after review. The VAD-silence policy is unchanged from prod. The PR adds a no-frames close and measurement.
SONIOX_IDLE_CLOSE_SECONDS(VAD silence)SONIOX_IDLE_REARM_SECONDSSONIOX_IDLE_MAX_CLOSES_PER_HOURSONIOX_IDLE_NO_FRAMES_SECONDS(new)0disables only this trigger)send()or the VAD observer and in any VAD mode, it starts the existing planned close: finalize, drain final tokens for up to 2 s, then close.VAD_HANGOVER_SECONDSis pinned toVAD_GATE_HANGOVER_MSby a test.omi_soniox_connected_seconds_total{demand_cohort}: wall time each Soniox websocket is actually open (the billed quantity), with idle close on or off.omi_soniox_idle_closes_by_trigger_total{trigger="vad"|"no_frames"}: shows how the saving splits between the two triggers.runtime_env.yamlno longer carrySONIOX_IDLE_CLOSE_SECONDS=45, because 45 is now the code default. Prod behaviour is identical. The stale entry in the pusher cohost listen-only allowlist is dropped. The flag registry and docs are updated.Expected capture
The attribution report (§5) estimates the no-client-audio share of the 10-18 silent hours as follows:
omi_listen_live_no_audio_sessionsaveraged 66 concurrent sockets, about 1,550 h/day across all providers.The no-frames close recovers most of that. Each stalled socket still bills up to 60 s (+4 s hangover) before closing. Sessions that already spent their 12 closes this hour wait for a slot. So the realistic range is ≈$40–58/day.
The remaining ~1,900 silent hours are short VAD-gated gaps and cap exhaustion. That part waits for the speaker-scope follow-up below.
Rollback
Each of the four knobs is an env var on backend-listen:
SONIOX_IDLE_NO_FRAMES_SECONDS=0. The other three are already at prod values:SONIOX_IDLE_CLOSE_SECONDS=45,SONIOX_IDLE_REARM_SECONDS=60,SONIOX_IDLE_MAX_CLOSES_PER_HOUR=12. Set all four explicitly to pin that.SONIOX_IDLE_CLOSE_SECONDS=0.Follow-up (required before any lower VAD threshold)
Preserve speaker scope across idle reopen. Today
IdleSonioxSocket._resumebumps_socket_epoch, andSpeakerProviderEpoch.stampmints a newspeaker_id_scopeon each epoch (speaker_identity.py:60-66). So Soniox's restartedSPEAKER_00becomes a new conversation speaker. The fix is to keep the conversation scope across a planned idle reopen and remap the new socket'sSPEAKER_Nonto the existing conversation speakers. Only after that lands should the VAD close move toward 20 s / 10 s re-arm / a higher cap. That is where the other ~$80–110/day lives.Deploy note
Deploy this listen change separately from the live static-routing stage changes (#22231), so their effects on Soniox connected hours, reopen latency and routing don't confound each other. Both PRs edit
prod_omi_backend_listen_values.yaml. After deploy, watch:increase(omi_soniox_connected_seconds_total[1d])/3600, against the baseline of about 3,450 h/day;omi_soniox_idle_closes_by_trigger_totalby trigger;omi_soniox_idle_reopens_total,omi_soniox_idle_reopen_secondsandomi_soniox_idle_reopen_failures_total.Verification
test_soniox_idle_close.py,test_listen_stt_rollout.pyandtest_soniox_idle_reopen_capture.py: 128 passed. New and updated tests cover:origin/main(merge commit, no rebase).closes_by_trigger.Product invariants affected
Failure class (fixes)
No
fix:commits (perf:andchore:), so no declaration is required.🤖 Generated with Claude Code