Repository navigation
feat(listen): mobile local-preview lane for batch-lane users; defer, never drop, the cloud stream - #23610
Conversation
…ocal_preview handshake, saved-seconds metrics Dark foundation for the batch-only cloud transcription proposal. Default stream reproduces today's behavior exactly; when_watched forces the existing #21481 live-demand machinery to admit every session (no parallel switch); off opens no cloud streaming STT session at all while audio is still received and persisted (the #23388 cap_paused receive/persist shape), with BYOK custom STT never suppressed. local_preview is a client capability declaration on /v4/listen. Metrics: omi_cloud_live_stt_mode_sessions_total and omi_cloud_live_stt_saved_seconds_total.
…never drop, the cloud stream A mobile session that declares local_preview=enabled and whose uid is on the batch record lane (allowlist or batch percent), with private cloud sync and no custom STT, is admitted to the local-preview lane: ready and every mobile_batch_admission renewal carry local_preview=true with mobile_standard_batch=true, so the client journals all pendant audio through the lossless mobile Standard batch route and renders its own on-device preview. Integrations no longer hold these sessions on the live stream (David, 2026-10-25: realtime apps/webhooks degrade). Listen defers the provider stream instead of dropping it: live segments are what keep a listen conversation alive and register it for batch, so a session with audio and no stream loses its transcript. The first socket audio opens today's stream. CLOUD_LIVE_STT_MODE=off (#23498) now uses the same deferral. Kill switch LOCAL_PREVIEW_BATCH_ENABLED, on unless set off; no separate ramp. 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: 945fa8c7b5
ℹ️ 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 demand is not None and supervisor is not None: | ||
| # Session start skipped this task while the stream was deferred. | ||
| supervisor.create_lifetime_task(demand.run(), name='live_demand_routing') |
There was a problem hiding this comment.
Include the deferred demand task in active supervision
When socket audio opens a deferred stream after session startup, this task is created after ListenSessionRuntime._run() has entered task_supervisor.supervise(). WebSocketTaskSupervisor.supervise() copies _monitored_tasks, and supervise_tasks() builds a fixed monitored set, so the newly registered task is never actually supervised. If demand routing crashes, the connection remains active without further visibility/consumer-driven lane changes. Register a supervised waiter before starting supervision, or make the supervisor accept dynamically added tasks.
AGENTS.md reference: backend/AGENTS.md:L297-L297
Useful? React with 👍 / 👎.
| totals = self.host.state.realtime_demand.totals() | ||
| OMI_CLOUD_LIVE_STT_SAVED_SECONDS_TOTAL.labels(mode=mode).inc( | ||
| totals.get('background', 0.0) + totals.get('foreground', 0.0) |
There was a problem hiding this comment.
Meter saved seconds from actual provider-lane usage
With CLOUD_LIVE_STT_MODE=when_watched, this counts all hidden session time as savings even when demand routing never admits the session or retains a vendor for an active realtime consumer. For example, demand_routing.ineligible_reason() excludes non-English sessions, which keep their vendor stream but still increment this counter for background time. It also counts vendor dwell time before a switch. Use actual lane-meter intervals rather than visibility totals so rollout cost measurements do not report savings for audio that was still sent to a paid provider.
Useful? React with 👍 / 👎.
| except Exception as error: | ||
| logger.warning('Local preview batch policy failed type=%s', type(error).__name__) | ||
| return 'policy_error' |
There was a problem hiding this comment.
Record the policy-error fallback through the shared helper
If batch-policy resolution raises, this branch refuses local preview and continues with cloud streaming, but emits only a warning and the admission-outcome counter. The backend guide explicitly requires new fallback paths to call utils.observability.fallback.record_fallback; without that call, policy failures that restore vendor streaming are absent from the shared fallback monitoring. Record the recovered batch-to-live transition here, and cover the equivalent outer admission-error branch as well.
AGENTS.md reference: backend/AGENTS.md:L318-L318
Useful? React with 👍 / 👎.
…m actually opens Luna r1 P2 on #23610: a deferred open that cap admission pauses creates no socket, and the later cap-recovery re-init never started the demand-routing task the session skipped. ensure_live_demand_routing() starts it exactly once whenever a stream exists (session start, deferred open, cap recovery); the deferred-open counter now counts only opens that produced a socket. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d reason enum CI test_reason_label_enums: outcome labels must come from a reasons.py enum via reason_label(). Adds LocalPreviewOutcome (LIVE_STT family); REASONS derives from it. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
…late routing tasks Luna r2 on #23610: a deferred open that cap admission paused, then cap recovery opened, was never counted; note_deferred_stream_opened() counts once from either path. Routing tasks started after supervise() snapshots its set are tracked and cancelled at teardown but cannot end the session; that fail-soft behaviour is intended and now documented at the call. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Server half of the on-device live preview for batch-lane mobile users (David, 2026-10-25: ship the new live
UX to users on the default batch lane so it goes live with full batch; mobile only; realtime apps/webhooks degrade;
never fall back to cloud live STT because a phone has no engine). Builds on draft #23498's commit (its
local_previewhandshake andCLOUD_LIVE_STT_MODEmodule are reused, not forked).Why not "just don't open the stream": a listen conversation is kept alive, finalized and registered for batch
only by live segments. With no stream, the row closes on the silence timeout and is deleted as empty
(
routers/listen/conversations.py:385-398);register_recordingonly runs from finalization(
utils/conversations/finalizer.py:367). The audio survives in GCS but no lane ever transcribes it. #23498'soffmode had exactly this hole.
What this PR does instead:
routers/listen/local_preview.py), pinned once at session start: the client sentlocal_preview=enabledAND kill switchLOCAL_PREVIEW_BATCH_ENABLEDis on (default; only false/0/off/nodisables) AND the uid is on the batch record lane (
resolve_batch_policy(uid).batch_enabled, read through thesanctioned
config/batch_live_preview.pyedge: batch allowlist or batch percent) AND private cloud sync is onAND the session is not custom STT, multi-channel, onboarding or a phone call. Closed reason codes in
omi_listen_local_preview_sessions_total{outcome,client_platform}.readyand everymobile_batch_admissionrenewal carrylocal_preview: trueplusmobile_standard_batch: true, without the Standard lane's cohort and integrationchecks (integrations degrade by ruling). The client then journals all pendant Opus through the existing
lossless mobile Standard batch route (feat: gate hidden mobile Standard capture onto lossless upload-and-batch #21479: journal →
/v2/sync-local-files→ raw archive → batch record),visible or not, and renders its own on-device preview. The kill switch revokes at the next 60 s renewal.
CLOUD_LIVE_STT_MODE=off) opens no providersocket at start (neither vendor nor the Parakeet window leg). The first audio that reaches the socket (a frame
the journal refused: low disk, journal failure) opens today's stream, starts the demand-routing task the
session skipped, and counts in
omi_listen_deferred_stream_opened_total{deferred_by}. Multi-channel is neverdeferred.
readyfor a deferred session names no provider.Released clients never send
local_preview, so their behaviour is unchanged. David's allowlisted account isadmitted as soon as listen deploys and a new app build runs; the batch percent ramp carries everyone else. There
is no separate ramp: the kill switch is on by default and is the rollback.
Design note (constraints, gaps and open decisions):
omi-workspace data/run-2026-10-13-two-lane-nemotron/odpreview-design-2026-10-25.md. The mobile PR (engine, UX,telemetry, screenshots) follows separately and needs this deploy first to do anything.
Known gaps, stated up front
local_previewfor it(nor for non-Omi devices, auto-sync off, Transcribe Later): those sessions keep today's cloud transcript. Follow-up.
not yet evidenced; this lane routes batch-lane users onto it.
Testing
backend/tests/unit/test_local_preview_lane.py(kill-switch parsing; full admission reason matrix; policyerror keeps streaming; pinning + counter; renewal revoke; deferral at init with no demand attach and no lane
switch; deferred open on socket audio incl. demand task + counter; flush opens only with audio and stops on a
failed open;
offdefers while multi-channel never does; non-batch uid keeps provider selection; mobile batchgrant without inventory reads and kill-switch revoke;
readypayload; field absent for older clients).backend/tests/unit/test_cloud_live_stt_mode.pyupdated:offsaves seconds only while still deferred.test_listen_*,test_transcribe_*,test_mobile_standard_batch,test_batch_live_preview,test_stt_cap_dispatch,test_live_demand_*,test_flag_budget,test_batch_unit_policy:bin/omi-heavy run -- nice -n 19 env BACKEND_UNIT_TEST_FILE_LIST=<list> BACKEND_PYTEST_WORKERS=4 bash backend/test.sh→ exit 0.scripts/check_feature_flag_registry.pyOK; registry doc re-rendered.Product invariants: none
Failure-Class: none
UI-Evidence: none -- backend-only; the mobile PR carries the screenshots
Line-Count-Exception: backend/routers/listen/receiver.py | 2796 -> 2895 | deferred-stream seam (init deferral, open-on-audio, flush hook, idempotent demand-routing start) lives at the existing _initialize_stt/_flush_stt_buffer seam; admission logic is split out to routers/listen/local_preview.py; to move with the listen-edge split
Line-Count-Exception: backend/routers/listen/runtime.py | 1474 -> 1491 | local-preview admission renewal, deferred ready event, and demand routing started on cap recovery
Line-Count-Exception: backend/utils/metrics.py | 1563 -> 1587 | four listen counters (two from #23498, two for the local-preview lane); single central metrics module
🤖 Generated with Claude Code