Skip to content

fix(backend): a live reconnect resumes its conversation instead of minting a stub, plus the health-driven STT routing foundation - #15222

Closed
Git-on-my-level wants to merge 4 commits into
mainfrom
feat/stt-provider-routing
Closed

Git-on-my-level wants to merge 4 commits into
mainfrom
feat/stt-provider-routing

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Failure-Class

Failure-Class: FC-split-mutation-authority

Summary

Follow-on to #15193. That PR stopped offline sync adopting live reconnect stubs. This one fixes
the other half — realtime minting a fresh conversation on every reconnect — and lands the
foundation for choosing STT providers from live health instead of a hardcoded ladder.

The 2026-09-19 incident had two independent authorities over conversation identity. Sync's is now
one transaction (#15193). Realtime's was still create_new_in_progress_conversation(rollover=True),
which minted an unremembered UUID every time the previous client binding was terminal or missing,
so a flapping session produced a new empty conversation about every 35 seconds.

Audit first, then the fix

The change was written against an adversarial audit of what the three landed PRs actually fix.
Verdicts, each tied to the production seam that decides it and to a passing or deliberately-failing
hermetic test:

Shape Before this PR After
Unbound WALs adopting the nearest empty stub (the 09-19 shape) FIXED by #15193 FIXED
Several different existing explicit WAL targets in one capture NOT FIXED PARTIAL — new repeated-origin rollovers converge; historical distinct targets stay separate
Reconnect inside the 120 s window PARTIAL FIXED for a repeated durable origin on the same source/device; PARTIAL for anonymous cross-device lookup
Desktop recording vs phone shards of one call PARTIAL PARTIAL — links are advisory; a 60 s shard can miss the overlap threshold
#15106 cross-job allocation race FIXED FIXED
2026-09-18 03:08–03:47Z, eleven overlapping live conversations UNKNOWN cause Not claimed fixed — needs a provider-epoch replay and historical logs

Three earlier conclusions in this effort are corrected by code inspection, and they change what is
worth building:

  • The Modulate breaker already half-opens. ProviderCircuitBreaker.allow_request has probe
    admission and a multi-success recovery threshold. The "blind 180 s skip" premise was wrong. Its
    real weakness is that it measures socket success, not transcript proof, and fallback legs bypass
    much of that admission logic.
  • Deepgram already short-circuits 401/402/403 inside one connect call. It does not sleep through
    three payment retries per session. What is missing is a fleet-wide account quarantine.
  • There is no 35-second client retry policy. capture_controller.dart has a 15 s
    keepalive/reconnect timer and pure_socket.dart a 20 s ping with a 15 s connect timeout; the
    observed ~35 s is composed session-failure plus client scheduling, partly server-controlled.

One finding contradicts a stronger claim made earlier in this effort: read-only production logs show
four incident accepts carrying the same client recording ID. A listen request ID and a WAL
conversation ID are different evidence, so #15193's premise stands, but "no client ID was sent" was
too strong. The historical binding state at those instants was not read and remains UNKNOWN.

Changes

Reconnect continuity (the realtime half).
database/listen_continuations.py + utils/conversations/live_continuation.py: a terminal or
missing original binding stays immutable, and a transactional metadata pointer on it names the still
active continuation. Resume requires an exact source/device partition, in-progress status, no
lock/discard/deletion, and a gap strictly below the shared utils/conversation_continuity.py
threshold — the same predicate sync uses, so exact 120 s splits on both paths. Concurrent proposals
converge on the first resumable generation. A fake-clock replay at 0/35/70/105/119 s emits one
conversation id; 120 s creates a new one.

Fenced cleanup of empty generations.
recording_sessions.py::tombstone_and_delete_empty_conversation now also protects is_locked,
deleted and nonzero sync_content_revision. Losing proposals are deleted only after a revalidated
winner is adopted, so late content beats cleanup. No new sweeper job; the final abandoned stub still
goes through existing stale recovery.

Routing foundation, default off.
config/stt_routing.py declares each provider's surface, languages, channel limit, features and
cost class; utils/stt/routing.py ranks candidates as a pure seeded function and owns one attempt
cursor that connect-time and mid-session failover both consume, so they can no longer disagree.
This is where configured Soniox — absent from the hardcoded connect ladder — becomes a connect-time
leg. An ineligible provider is an explicit counted outcome, never a silent skip.
utils/stt/routing_health.py keeps closed/open/hard/half-open state in Redis with generation fences
and a 30 s probe lease: three transient failures open for 30 s plus jitter, a typed
budget/payment/quota/auth failure opens immediately for 300 s, and only a non-blank transcript
closes a circuit
— a successful socket never does. Redis failure, malformed state or three WATCH
conflicts fail open to configured order.

STT_ROUTING_MODE defaults to legacy: byte-for-byte today's behavior. ordered uses the shared
list, health adds shared admission. Rollback is unsetting the variable; in-flight sessions keep
their snapshot, health keys expire, and the continuation metadata is additive so old code ignores it.

Dependencies

Assumes #15193 (merged, a7ff0e069a) and #15189 (merged, deployed). It also assumes the in-flight
Soniox observability PR, which moves mid-session recovered to first transcript and adds typed
provider close reasons; those hunks are deliberately not reimplemented here and the typed
provider_budget_exhausted reason feeds hard health. A three-way git merge-file against
origin/main for the two overlapping files (receiver.py, streaming.py) exits 0 — textual
compatibility only; combined runtime execution is UNVERIFIED.

Tests

test_listen_reconnect_continuity.py (fake-clock reconnect replay, exact-boundary split, device
isolation, locked/deleted/discarded exclusion, competing proposals converging),
test_stt_routing_foundation.py (selection as a property test, health transitions including
half-open and stale-generation fences, Redis-down fail-open), test_listen_provider_routing.py,
plus additions to test_recording_sessions.py and test_sync_capture_continuity.py. The
partial-flap limitation has a test that proves the limit rather than asserting it is desired.

Verification

Not exercised: live vendor behavior, GPU live/batch contention under real load, physical client
acceptance, deployed first-transcript rates, real prevalence of partial-flap targets, the 09-18 root
cause, and combined execution with the Soniox branch.

Decisions that need David

Provider budgets and weights; whether to reserve dedicated live GPU capacity for Parakeet; and how
ambiguous or already-curated duplicate recordings should be presented before any lineage migration.
Sized follow-up briefs for smaller models are in the design notes: provider epoch clock, the
remaining premature-recovered call sites, hot policy config, routing metrics/TTFT, the client
backoff protocol, lineage assessment, and the capacity study.

🤖 Generated with Claude Code

Review in cubic

Keep locks, deletion tombstones and sync revision ownership ahead of empty-live-row cleanup. Content continues to use the existing codec-aware transactional fence.

Validation: BACKEND_UNIT_TEST_FILE_LIST=/tmp/omi-stt-selected-tests.txt bash backend/test.sh — 340 passed, including 33 recording-session cases. Existing resume assertions stay unchanged; fixtures now include their real source/device/finished-at metadata.

Failure-Class: FC-split-mutation-authority
Keep an immutable original recording binding and transactionally adopt its compatible active continuation. Reconnects inside the shared silence boundary reuse the continuation; expired empty and unexposed losing generations use lifecycle-owned fenced cleanup before STT admission.

Reject deleted, discarded, locked and other-device rows. Keep existing explicit WAL targets authoritative. Tests reproduce newest-first/interleaved legacy hints, the remaining partial-flap limit, same-origin 35-second reconnects, exact 120-second rollover, protected content and legacy principals.

Validation: BACKEND_UNIT_TEST_FILE_LIST=/tmp/omi-stt-selected-tests.txt bash backend/test.sh — 340 passed. Hermetic E2E: 120 passed, 3 skipped, 2 xfailed. Sync Cloud Tasks emulator gauntlet passed. Live provider/client acceptance was not run; only hermetic service seams are authorized.

Failure-Class: FC-split-mutation-authority
Add a pure capability registry and seeded ordered/weighted policy, a shared Redis admission state with generation-fenced half-open probes, and one ranked session cursor for connection and replacement. Socket acceptance never closes health or proves recovery; nonblank transcript content does. Keep late content with its serving-provider identity.

Default legacy mode retains the existing provider path. Ordered/health modes include configured Soniox at connect, count eligibility skips, skip quarantined accounts without vendor retries and fail open on Redis/config failure. Managed health excludes BYOK, custom STT and multichannel. Keep the existing rebuild ownership block intact for the in-flight first-transcript recovery PR.

Validation: BACKEND_UNIT_TEST_FILE_LIST=/tmp/omi-stt-selected-tests.txt bash backend/test.sh — 340 passed. Includes concurrent receiver failover, seeded selection properties, typed account failures, shared probe admission, transcript settlement and Redis outage. bash backend/testing/e2e/run.sh — 120 passed, 3 skipped, 2 xfailed. No live provider call or rollout was performed.
…policy

Move the unchanged resumable-continuation predicate out of database storage and into the shared continuity module. Async callers now depend on the pure rule; transactional metadata access stays on the persistence executor. This addresses the installed pre-push async-boundary guard without an exemption.

Validation: BACKEND_UNIT_TEST_FILE_LIST=/tmp/omi-stt-selected-tests.txt bash backend/test.sh — 340 passed after the move.
@Git-on-my-level
Git-on-my-level deleted the feat/stt-provider-routing branch September 20, 2026 19:32
@github-actions

Copy link
Copy Markdown
Contributor

Hey @Git-on-my-level 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

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