Skip to content

feat(listen): mobile local-preview lane for batch-lane users; defer, never drop, the cloud stream - #23610

Merged
Git-on-my-level merged 5 commits into
mainfrom
odpreview/server-local-preview-lane
Oct 25, 2026
Merged

Git-on-my-level merged 5 commits into
mainfrom
odpreview/server-local-preview-lane

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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_preview handshake and CLOUD_LIVE_STT_MODE module 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_recording only runs from finalization
(utils/conversations/finalizer.py:367). The audio survives in GCS but no lane ever transcribes it. #23498's off
mode had exactly this hole.

What this PR does instead:

  1. Local-preview admission (routers/listen/local_preview.py), pinned once at session start: the client sent
    local_preview=enabled AND kill switch LOCAL_PREVIEW_BATCH_ENABLED is on (default; only false/0/off/no
    disables) AND the uid is on the batch record lane (resolve_batch_policy(uid).batch_enabled, read through the
    sanctioned config/batch_live_preview.py edge: batch allowlist or batch percent) AND private cloud sync is on
    AND 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}.
  2. Client contract: an admitted session's ready and every mobile_batch_admission renewal carry
    local_preview: true plus mobile_standard_batch: true, without the Standard lane's cohort and integration
    checks (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.
  3. Deferred, never dropped, cloud stream: an admitted session (or CLOUD_LIVE_STT_MODE=off) opens no provider
    socket 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 never
    deferred. ready for a deferred session names no provider.

Released clients never send local_preview, so their behaviour is unchanged. David's allowlisted account is
admitted 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

  • Phone-mic capture is not on the batch journal, so the mobile client (feat(app): on-device live preview for batch-lane users (iOS + Android) #23617) does not request local_preview for it
    (nor for non-Omi devices, auto-sync off, Transcribe Later): those sessions keep today's cloud transcript. Follow-up.
  • Frames the journal refuses still stream (rare, counted): the never-lose-audio rule outranks "no cloud STT".
  • The mobile Standard batch journal's physical-phone battery/VAD-recall qualification (its own doc's ramp gate) is
    not yet evidenced; this lane routes batch-lane users onto it.

Testing

  • New backend/tests/unit/test_local_preview_lane.py (kill-switch parsing; full admission reason matrix; policy
    error 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; off defers while multi-channel never does; non-batch uid keeps provider selection; mobile batch
    grant without inventory reads and kill-switch revoke; ready payload; field absent for older clients).
  • backend/tests/unit/test_cloud_live_stt_mode.py updated: off saves seconds only while still deferred.
  • Targeted run, 59 files incl. every 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.py OK; 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

Git-on-my-level and others added 2 commits October 25, 2026 23:41
…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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T18:44:51.964042Z 4007639 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread backend/routers/listen/receiver.py Outdated
Comment on lines +1475 to +1477
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')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +867 to +869
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +63 to +65
except Exception as error:
logger.warning('Local preview batch policy failed type=%s', type(error).__name__)
return 'policy_error'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Git-on-my-level and others added 3 commits October 26, 2026 00:39
…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]>
@Git-on-my-level
Git-on-my-level merged commit e09ce02 into main Oct 25, 2026
58 checks passed
@Git-on-my-level
Git-on-my-level deleted the odpreview/server-local-preview-lane branch October 25, 2026 18:55
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