Skip to content

fix(desktop): bind the hub route when the realtime transport goes ready - #9699

Merged
kodjima33 merged 2 commits into
mainfrom
watchdog/ptt-warm-wait-hub-commit
Jul 14, 2026
Merged

kodjima33 merged 2 commits into
mainfrom
watchdog/ptt-warm-wait-hub-commit

Conversation

@kodjima33

@kodjima33 kodjima33 commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

Product invariants affected

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

The bug

Every push-to-talk turn taken while the realtime socket was still warming up died silently: the thinking spinner stayed up forever, the user's speech was dropped, and no reply, transcription fallback, or journal row was ever produced. Only pressing PTT again escaped it.

Root cause

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

With the route stranded in .hubWarmWait:

  1. commitBufferedRealtimeHubTurn() opens with guard isHubMode (route .hub) — so the one function that exists to serve the buffered warm-wait path returned immediately.
  2. hubCommitPending therefore stayed false, so when admission landed, finishContextFreshInputOnCurrentSession() replayed the buffered audio and called beginInputTurn but never commitInputTurn — the provider was never asked to respond.
  3. hubReady had already cancelled the .hubWarm deadline, and the successful reconnect cancelled .providerReconnect, so no deadline was armed. The turn sat in finalizing indefinitely.

Mid-hold mic audio in that window never reached the hub at all: the tap only calls feedAudio when isHubMode.

Ironically it broke precisely when admission succeeded — a rejected admission at least terminated the turn via providerReconnectFailed.

The fix

Restore the route binding in hubReady, and widen the hubAdmissionRejected guard to routeMatchesHub. That event is sent from inside the prepareHubInput effect handler — i.e. after the route has been applied — so the #9684 transcription fallback would otherwise go stale.

The fail-closed property is preserved. The route is a driver-routing signal, not an admission grant. Audio still cannot reach the provider before the canonical context is bound: feedAudio parks chunks in reconnectAudioBuffer, and commitTurn defers through hubCommitDeferred (which also arms the deferredCommit deadline, closing the no-deadline hang) until RealtimeInputAdmissionPolicy admits the input.

Verification

  • Added testBufferedWarmWaitTurnStaysCommittableAfterTransportReady and reworked testTransportReadyBindsHubRouteAndPreparesContext (it previously asserted the broken state). Both fail on the pre-fix reducer and pass after it — verified by stashing the source fix and re-running.
  • desktop/macos/scripts/agent-logic-harness.sh --swift-only → 379 tests, 0 failures.
  • make preflight → green.

Not runtime-exercised in a live named bundle (UNVERIFIED on-device); the finding and fix are established by static trace plus the reducer/coordinator regression tests above.

Scope / risk

The regressing commit is on main and rode into the v0.12.73 candidate, but that release is still channel: candidate — it has not been promoted to beta or stable, so no production user is affected yet. This lands the fix before it can ship.

🤖 automated by hourly watchdog; opened for review, not merged (not live on prod → outside the auto-merge gate).

Review in cubic

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.
@kodjima33
kodjima33 merged commit 3dc9a88 into main Jul 14, 2026
20 of 23 checks passed
@kodjima33
kodjima33 deleted the watchdog/ptt-warm-wait-hub-commit branch July 14, 2026 14:36
@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