Skip to content

refactor(desktop): make PTT voice turns reducer-driven - #9370

Merged
Git-on-my-level merged 2 commits into
mainfrom
codex/ptt-voice-turn-orchestrator
Jul 10, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
codex/ptt-voice-turn-orchestrator

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Introduce a single authoritative VoiceTurnReducer / VoiceTurnCoordinator for PTT phase, route, deadlines, terminal reasons, presentation, diagnostics, and exact-once cleanup.
  • Carry typed turn, capture, session, response, tool-call, and output-lease identities across async boundaries so stale work is rejected before it mutates state.
  • Route every PTT audible path through one VoiceOutputCoordinator, including realtime PCM, selected-voice fallback, deterministic agent acknowledgement, filler, and system-voice fallback.
  • Normalize provider callback ordering, make provider-specific barge-in atomic, and fence transcript persistence/voice-seed refresh before reconnecting.
  • Preserve user-visible failure hints while emitting enum-only diagnostics, bounded per-turn timelines, stale/invalid-transition counters, and shared fallback telemetry.
  • Add a hermetic, real-action desktop E2E flow for PTT lifecycle verification.

Why this closes #9264

The issue's underlying failure mode—multiple components independently owning one turn, output lane, and UI phase—is removed. The reducer/coordinator is now the semantic owner; capture, realtime providers, playback, and presentation code are adapters around it.

The hot PCM buffer remains bounded sidecar storage in PushToTalkManager, and RealtimeHubController remains a compatibility facade. Its route booleans are derived projections rather than an independent state machine. This centralizes lifecycle ownership without putting audio chunks through the main-actor reducer or combining an unrelated mechanical class split with the behavioral refactor.

Independent review hardening

A separate subagent reviewed the implementation before push. Its findings were addressed with:

  • cancellation/rewarm fencing that cannot strand the realtime hub;
  • bounded transcript resolution before persistence, seed refresh, replacement sessions, or agent handoff;
  • canonical, stale-checked agent delegation with success acknowledgement only after execution;
  • typed presentation reset through the coordinator;
  • payload-free diagnostic labels and reducer timelines;
  • shared recovered/degraded/exhausted fallback telemetry;
  • per-turn anomaly-counter reset and provider identity-map cleanup;
  • behavioral regression tests for each of these boundaries.

Verification

  • OMI_SWIFT_TEST_SUITE_WORKERS=4 ./scripts/swift-test-suites.sh — all 184 isolated Swift suites passed.
  • Focused lifecycle/orchestration suite — 110 tests passed.
  • Headless PTT automation regression suite — 4 tests passed.
  • Desktop launcher shell-test discovery — all tests passed.
  • Strict desktop E2E coverage — 11 changed Swift files covered, 0 uncovered.
  • ./scripts/desktop-core-harness.sh --self-check — 28 flows and 65 actions validated.
  • Named bundle omi-ptt-orchestrator, flow ptt-lifecycle — 5/5 steps passed in 218.75 ms, exercising actual ptt_start / ptt_stop actions through recording to terminal_too_short, with zero stale or invalid-transition anomalies.
  • Clean Swift release compile and the repository pre-push clean debug build passed.
  • Fallback instrumentation, product-invariant, changelog, formatting, and git diff --check validations passed.

The named bundle was intentionally hermetic and signed out, so this run did not send live audio to an external provider. It did exercise the real PTT lifecycle, coordinator projections, terminal cleanup, and diagnostic assertions without requiring microphone permission or network state.

Closes #9264

Related: #9342 tracks a distinct agent-bridge startup failure. This PR improves the shared robustness patterns but does not claim to fix or close that separate issue.

Product invariants affected

  • INV-CHAT-1 — preserves one kernel-owned transcript across typed, floating-bar, PTT/realtime, and pill surfaces. This refactor changes PTT lifecycle ownership only; it introduces no transcript/session store or per-surface history.

Centralize PTT lifecycle, deadlines, UI projection, and terminal ownership in a typed reducer/coordinator. Fence provider callbacks, persistence, seed refresh, and audible output with turn-scoped identities and leases.

Verification:\n- 97 focused voice-turn tests passed\n- desktop agent logic harness passed (212 lifecycle tests)\n- clean arm64 release build passed\n- isolated omi-ptt-orchestrator PTT entry/cleanup exercised
@mintlify

mintlify Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
omi 🟢 Ready View Preview Jul 10, 2026, 1:04 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

@codex review

@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: 0455398a27

ℹ️ 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".

return
}

voiceTurnCoordinator.send(.transcriptionFinal(turnID: turnID, text: query))

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 Finish non-hub PTT turns after chat completion

When the Omni/Deepgram path reaches this event, the reducer enters awaitingResponse and schedules the provider-response deadline, but the normal floating-chat path that sendQuery uses never emits providerTurnFinished (repo-wide, that event is only sent from RealtimeHubController). For any non-hub PTT turn—such as hub warm fallback, hub unavailable, or voice answers disabled—the user can still get a successful text/voice answer, then 20s later the turn times out as provider_no_response and shows the failure hint / records a false terminal.

Useful? React with 👍 / 👎.

func release(_ lease: VoiceOutputLease) -> Bool {
guard activeLease == lease, turnID == lease.turnID else { return false }
activeLease = nil
providerOutputSuppressed = false

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 Keep deterministic ack suppression for the whole turn

If a .deterministicAgentAck lease drains before the provider's post-tool audio/text arrives (for example the spawn_agent path speaks the local kickoff and then returns the tool result), releasing the lease clears providerOutputSuppressed. The hub gates provider audio/text on this flag, so late provider output in the same turn is no longer suppressed and can speak a second acknowledgement after the deterministic one; this suppression should last until endTurn/the next turn rather than until playback release.

Useful? React with 👍 / 👎.

Address independent review findings across cancel rewarm handoff, late transcript continuity, canonical stale-safe agent delegation, presenter ownership, diagnostic privacy, fallback telemetry, and realtime identity cleanup.

Verification: OMI_SWIFT_TEST_SUITE_WORKERS=4 ./scripts/swift-test-suites.sh (184 suites passed); desktop launcher test discovery passed; desktop-core-harness --self-check passed; strict e2e flow coverage passed; named-bundle ptt-lifecycle flow passed; focused PushToTalkStateMachineTests passed.
@Git-on-my-level
Git-on-my-level merged commit 7572bcf into main Jul 10, 2026
20 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/ptt-voice-turn-orchestrator branch July 10, 2026 04:23

This branch was successfully deployed

1 active deployment
staging - docs — 6aa0e026 Deployed Jul 10, 2026 by mintlify[bot]
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.

[Desktop][PTT] Refactor voice turns into explicit state machines

1 participant