Skip to content

fix(desktop): recover PTT turns rejected by realtime context admission - #9684

Closed
kodjima33 wants to merge 1 commit into
mainfrom
watchdog/ptt-context-admission-fallback
Closed

kodjima33 wants to merge 1 commit into
mainfrom
watchdog/ptt-context-admission-fallback

Conversation

@kodjima33

@kodjima33 kodjima33 commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

Bug

A spoken push-to-talk question can be silently dropped — the user holds PTT, speaks a full question, releases, and gets no answer, no transcript, and no error. The captured audio is discarded.

Root cause

dbd69e71c5 ("make realtime context admission fail closed") made context admission fail-closed and routed all three asynchronous rejection sites through .providerReconnectFailed:

  • RealtimeHubController.finishContextFreshInputOnCurrentSession()
  • RealtimeHubController.finishSessionReconnectAfterReady()
  • RealtimeHubController.failContextFreshInputPreparation()

.providerReconnectFailed means transport failure, and the reducer maps it to terminate(reason: .providerFailed) — the turn dies with no transcription fallback.

But an admission rejection is a context/policy decision, not a transport failure. The buffered audio never reached the provider and is still intact in batchAudioBuffer, so the turn is recoverable. The follow-up 711b3a13af restored exactly that bounded Deepgram fallback — but only for the synchronous rejection (.hubAdmissionRejected), which fires before .providerReconnectStarted projects the turn. The async half stayed fatal.

Reachable without a race: .rejectStaleProviderContext fires on any owner-scope skew between the context bind and the socket build (sessionVoiceContextFreshnessIdentity is reset to "" by teardownSession() and re-derived empty when prefetchedVoiceContextOwnerScope != ownerScope).

Fix

Add .providerContextAdmissionRejected for the three sites that discard buffered input before it ever reached the provider. The reducer:

  1. undoes the awaitingResponse projection that providerReconnectStarted applies to a released turn (the transcription fallback only runs from an input phase — otherwise the turn would hang instead of dying, which is worse);
  2. takes the same bounded transcription fallback as the synchronous case.

A phase with no buffered input to rescue keeps the terminal behavior, and a genuine transport failure (hubDidError) still terminates via .providerReconnectFailed.

Closing the class: the failed contract was conflating admission rejection with transport failure on one event. Both halves of the rejection surface now map to the same recovery, and .providerReconnectFailed is left to mean only what it says.

Verification

  • xcrun swift build -c debug --package-path Desktop — green.
  • VoiceTurnReducerTests — 57/57 pass, including 2 new regression tests: a released turn transcribes instead of dying; a still-held turn keeps recording on the transcription route.
  • Teeth check: with the reducer forced back to terminate(), both new tests fail (10 assertions); with the fix they pass.
  • Not exercised in a live app — the rejection needs a provider-side race / stale-context condition I cannot reproduce on demand. Coverage is behavioral through the production reducer API (a controllable seam), not a source grep.

Scope

4 files, +114/−3. Unreleased code (dbd69e71c5 is not in v0.12.72, the current prod build), so this is not live on prod — opened for review, not merged.

🤖 automated by hourly watchdog; opened for review, not merged.

Review in cubic

Product invariants affected

  • INV-CHAT-1
  • INV-VOICE-1

A spoken push-to-talk question could be silently dropped — no answer, no
error, no transcript — when the realtime hub rejected the turn's context
admission asynchronously.

Root cause: dbd69e7 made context admission fail-closed and routed all
three async rejection sites (finishContextFreshInputOnCurrentSession,
finishSessionReconnectAfterReady, failContextFreshInputPreparation)
through `.providerReconnectFailed`. That event means *transport failure*
and the reducer maps it to terminate(reason: .providerFailed): the turn
dies with no transcription fallback and the buffered audio is discarded.

But an admission rejection is a context/policy decision, not a transport
failure — the captured audio never reached the provider and is still
intact in the capture buffer, so the turn is recoverable. The follow-up
711b3a1 restored exactly that bounded Deepgram fallback, but only for
the *synchronous* rejection (`.hubAdmissionRejected`), which fires before
`.providerReconnectStarted` projects the turn. The async half stayed
fatal.

Fix: add `.providerContextAdmissionRejected` for the three sites that
discard buffered input before it reached the provider. The reducer undoes
the awaitingResponse projection that `providerReconnectStarted` applied to
a released turn (the transcription fallback only runs from an input
phase), then takes the same bounded fallback as the synchronous case.
A phase with no buffered input to rescue keeps the terminal behavior, and
a genuine transport failure still terminates via `.providerReconnectFailed`.

Verification:
- xcrun swift build -c debug --package-path Desktop — green.
- VoiceTurnReducerTests: 57/57 pass, incl. 2 new regression tests
  (released turn -> transcribes; still-holding turn -> keeps recording on
  the transcription route).
- Teeth check: with the reducer forced back to terminate(), both new
  tests fail (10 assertions); with the fix they pass.
- NOT exercised in a live app: the rejection requires a provider-side
  race/stale-context condition I cannot reproduce on demand. Coverage is
  behavioral through the production reducer API, not a source grep.
kodjima33 added a commit that referenced this pull request Jul 14, 2026
…dy (#9699)

* fix(desktop): bind the hub route when the realtime transport goes ready

dbd69e7 ("make realtime context admission fail closed") stopped the
`hubReady` reducer case from binding `route = .hub(sessionID:)`, intending
to keep transport readiness separate from context admission. But the route
is what the PTT driver reads to decide it owns a hub turn — admission is
fenced separately by `providerConnection` + `RealtimeInputAdmissionPolicy`
inside RealtimeHubController.

With the route stranded in `.hubWarmWait`, every PTT turn taken while the
socket was still warming died silently:

- `commitBufferedRealtimeHubTurn()` opens with `guard isHubMode` (route
  `.hub`), so the buffered warm-wait commit — the one function that exists
  to serve this path — returned immediately.
- `hubCommitPending` therefore stayed false, so when admission landed,
  `finishContextFreshInputOnCurrentSession()` replayed the audio and called
  `beginInputTurn` but never `commitInputTurn`.
- `hubReady` had already cancelled the `.hubWarm` deadline and the
  successful reconnect cancelled `.providerReconnect`, so no deadline was
  armed: the turn sat in `finalizing` with the thinking spinner forever —
  no reply, no transcription fallback, no journal row. Only a new PTT press
  escaped it. Mid-hold mic audio in that window never reached the hub at all.

Restore the binding and widen the `hubAdmissionRejected` guard to
`routeMatchesHub`, since that event is sent from inside the `prepareHubInput`
effect handler — i.e. after the route is applied — so the PR #9684
transcription fallback would otherwise go stale. The fail-closed property is
unchanged: `feedAudio` still parks audio in `reconnectAudioBuffer`, and
`commitTurn` still defers via `hubCommitDeferred` (which also arms the
`deferredCommit` deadline) until the admission policy admits the input.

Verification:
- Added `testBufferedWarmWaitTurnStaysCommittableAfterTransportReady` and
  reworked `testTransportReadyBindsHubRouteAndPreparesContext`; both fail on
  the pre-fix reducer and pass after it (verified by stashing the source fix).
- desktop/macos/scripts/agent-logic-harness.sh --swift-only → 379 tests, 0 failures.

* chore(desktop): changelog fragment for the PTT warm-wait commit fix
@kodjima33

Copy link
Copy Markdown
Collaborator Author

Closing — opened by an automated bot and left unreviewed. The bot policy has changed: it now tests and merges fixes directly (or reports them), and no longer leaves open PRs for review. If this fix is still wanted, reopen and it'll be landed properly (tested → merged). 🤖

@kodjima33 kodjima33 closed this Jul 22, 2026
@kodjima33
kodjima33 deleted the watchdog/ptt-context-admission-fallback branch July 22, 2026 19:07
@github-actions

Copy link
Copy Markdown
Contributor

Hey @kodjima33 👋

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!

@undivisible undivisible added the AI label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants