Skip to content

feat: unify Talk session runtime - #77929

Merged
steipete merged 16 commits into
mainfrom
codex/unify-talk-session-runtime
May 6, 2026
Merged

steipete merged 16 commits into
mainfrom
codex/unify-talk-session-runtime

Conversation

@steipete

@steipete steipete commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR unifies the Talk/voice stack around one Gateway-owned Talk session model.

  • Problem: browser Talk, native Talk, Voice Call realtime, Google Meet realtime, transcription relay, VoiceClaw realtime, and STT/TTS handoff paths each had separate session, turn, event, cancellation, and config semantics.
  • Why it matters: barge-in, stale-output suppression, relay close, provider config, native push-to-talk, and future walkie-talkie clients were hard to reason about because each surface implemented its own protocol shape.
  • What changed: adds shared Talk events/controllers, Gateway-managed talk.session.* RPCs, provider capability metadata, browser relay/WebRTC/provider-WebSocket adapters, native managed-room handoff, and telephony/meeting adapters over the same contract.
  • What did not change: browser-owned provider negotiation stays on the client/browser session path; legacy RPCs are only compatibility adapters while new code uses the unified API.

Unified Talk API

talk.session.* is the Gateway-managed API. The Gateway owns lifecycle, correlation, cancellation, and close semantics for these modes:

Mode Transport Brain Use
realtime gateway-relay agent-consult Full-duplex provider audio bridged through the Gateway; provider tool calls route through OpenClaw agent consult.
transcription gateway-relay none Streaming STT sessions that emit common Talk transcript events.
stt-tts managed-room agent-consult Native/mobile push-to-talk and room-style Talk where clients own capture/playback and Gateway owns turn state.
stt-tts managed-room direct-tools Admin-only trusted room mode for direct Gateway tool execution.

Current RPC surface:

  • talk.session.create: creates a Gateway-owned session and returns sessionId, mode, transport, brain, audio/room metadata, and any handoff token needed for room join.
  • talk.session.join: joins a managed-room session with the bearer token and establishes the active room connection.
  • talk.session.appendAudio: appends PCM/audio frames for realtime/transcription relay sessions owned by the same connection.
  • talk.session.startTurn, talk.session.endTurn, talk.session.cancelTurn: controls managed-room turns; these now require the active joined connection, not just knowledge of the session id.
  • talk.session.cancelOutput: cancels realtime relay output for barge-in/output interruption.
  • talk.session.submitToolResult: completes realtime relay tool calls.
  • talk.session.close: stops relay sessions or revokes managed-room handoff state, broadcasts terminal close events to active clients, and forgets the unified session id.

The shared event contract is the spine: session.started, session.ready, session.replaced, session.closed, turn.started, turn.ended, turn.cancelled, speech/transcript/audio/tool/agent events all flow as talk.event with session/turn/correlation metadata.

Compatibility / Migration

Compatibility adapters kept for this PR:

  • talk.realtime.session for browser-owned WebRTC/provider-WebSocket sessions and existing browser relay entry points.
  • talk.realtime.relay* for current Control UI relay clients.
  • talk.transcription.* for transcription relay clients.
  • talk.handoff.* for first-party/native handoff clients.

Config migration is doctor-owned. Legacy speech talk.provider remains speech/TTS config; realtime settings move through explicit talk.realtime/provider config migration rather than startup-time reinterpretation.

instructionsOverride is intentionally not preserved. Realtime instructions are server-owned policy now.

Behavior Changes

  • Control UI Talk can use WebRTC, provider WebSocket, or Gateway relay behind the same browser Talk selection path.
  • Gateway relay Talk cancels stale consult runs on barge-in/close and rejects late tool results after abort.
  • Native clients get managed-room push-to-talk primitives with shared Talk events.
  • Managed-room turn control now requires the active joined room connection, closing the room-id/session-id takeover path.
  • Managed-room close now delivers the terminal session.closed event to the active room client.
  • Voice Call and Google Meet realtime emit/consume shared Talk events for turns, cancellation, consults, metrics, and stale-output handling.
  • Raw streamed audio is kept out of Talk event payload/log sinks; events carry metadata/correlation instead.

Important Paths

  • Gateway API: src/gateway/server-methods/talk-session.ts, src/gateway/server-methods/talk.ts, src/gateway/talk-realtime-relay.ts, src/gateway/talk-handoff.ts, src/gateway/talk-transcription-relay.ts.
  • Shared contracts: src/talk/talk-events.ts, src/talk/talk-session-controller.ts, src/talk/provider-types.ts, src/plugin-sdk/realtime-voice.ts.
  • Browser behavior: ui/src/ui/chat/realtime-talk-shared.ts, ui/src/ui/chat/realtime-talk-gateway-relay.ts, ui/src/ui/chat/realtime-talk.ts.
  • Native behavior: apps/android/app/src/main/java/ai/openclaw/app/voice/TalkModeManager.kt, apps/ios/Sources/Voice/TalkModeManager.swift, apps/macos/Sources/OpenClaw/TalkModeRuntime.swift.
  • Telephony/meeting adapters: extensions/voice-call/src/webhook/realtime-handler.ts, extensions/google-meet/src/realtime.ts.
  • Refactor plan: docs/refactor/talk.md, docs/refactor/talk-api-contract.md, docs/refactor/talk-execution.md, docs/refactor/talk-surfaces.md.

Real behavior proof

  • Behavior or issue addressed: Managed-room Talk sessions no longer allow a caller that only knows the session id or room url to start/end/cancel turns or close an active room; close also delivers the terminal room event to the active client.
  • Real setup tested: Local OpenClaw checkout on the rebased PR branch codex/unify-talk-session-runtime at 4883e3950fc448f45114d71217d2eb3e7d9a04a8 on macOS, using the real repository command wrappers.
  • Exact steps or command run after this patch: Ran a terminal capture from the real checkout: node -e "console.log(process.cwd())", pnpm test src/gateway/server-methods/talk.test.ts src/gateway/talk-handoff.test.ts, and pnpm plugin-sdk:api:check.
  • Evidence after fix: Terminal output from the local OpenClaw checkout:
$ node -e "console.log(process.cwd())"
/Users/steipete/Projects/clawdbot7

$ pnpm test src/gateway/server-methods/talk.test.ts src/gateway/talk-handoff.test.ts
Test Files  2 passed (2)
Tests  21 passed (21)
[test] passed 1 Vitest shard in 62.50s

$ pnpm plugin-sdk:api:check
OK docs/.generated/plugin-sdk-api-baseline.sha256
  • Observed result after fix: The managed-room regression coverage exercises unjoined and wrong-connection calls for talk.session.startTurn, talk.session.endTurn, talk.session.cancelTurn, and talk.session.close; all are rejected with the active-connection error, while the joined active client can start a turn and receives session.closed on close.
  • What was not tested: Live provider audio against an external realtime/STT vendor was not rerun for this final ownership patch; that path is covered by the earlier broader Talk/voice surface tests listed below.

Verification

Latest after rebase:

  • pnpm test src/gateway/server-methods/talk.test.ts src/gateway/talk-handoff.test.ts
  • pnpm plugin-sdk:api:check
  • pnpm exec oxfmt --check --threads=1 src/gateway/server-methods/talk-session.ts src/gateway/server-methods/talk.test.ts docs/.i18n/glossary.zh-CN.json extensions/diagnostics-otel/src/service.ts docs/.generated/plugin-sdk-api-baseline.sha256
  • git diff --check

Earlier broader proof on this branch:

  • pnpm test src/gateway/server-methods/talk.test.ts src/gateway/method-scopes.test.ts src/gateway/server-methods-list.test.ts
  • pnpm test src/gateway/server-methods/talk.test.ts src/gateway/server-methods-list.test.ts src/gateway/protocol/index.test.ts
  • pnpm test extensions/voice-call/src/media-stream.test.ts extensions/voice-call/src/webhook/realtime-handler.test.ts extensions/google-meet/index.test.ts src/gateway/voiceclaw-realtime/session.test.ts src/talk/talk-session-controller.test.ts src/gateway/talk-handoff.test.ts src/gateway/talk-realtime-relay.test.ts src/gateway/talk-transcription-relay.test.ts src/gateway/server-methods/talk.test.ts src/gateway/server-methods-list.test.ts src/gateway/gateway-misc.test.ts ui/src/ui/realtime-talk.test.ts ui/src/ui/realtime-talk-gateway-relay.test.ts ui/src/ui/realtime-talk-google-live.test.ts ui/src/ui/realtime-talk-webrtc.test.ts
  • pnpm build:plugin-sdk:strict-smoke
  • pnpm tsgo:core
  • pnpm tsgo:test:ui
  • pnpm check:changelog-attributions
  • env OPENCLAW_TESTBOX=0 pnpm check:changed

Blacksmith Testbox pnpm check:changed stayed queued and was stopped; this branch currently relies on the local changed-gate fallback plus targeted Talk/voice surface tests above.

Risks and Mitigations

  • Risk: broad voice-surface refactor can regress one surface while another passes.
    • Mitigation: commits are split by owner, shared event/controller tests were added, and public adapters remain for existing clients.
  • Risk: cancellation semantics can diverge between provider-native realtime and Gateway relay.
    • Mitigation: cancellation now propagates through provider/agent/tool/TTS/session paths, with regression tests for stale turns, relay barge-in, relay close, aborted chat events, and late tool results.
  • Risk: realtime config migration could surprise users with legacy speech config.
    • Mitigation: realtime migration is doctor-owned and explicit; normal speech talk.provider remains speech config.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web app: android App: android app: ios App: ios app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime extensions: diagnostics-otel Extension: diagnostics-otel agents Agent runtime and tooling extensions: openai plugin: google-meet extensions: tts-local-cli plugin: azure-speech Azure Speech plugin plugin: file-transfer size: XL maintainer Maintainer-authored PR labels May 5, 2026
@clawsweeper

clawsweeper Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR introduces a unified Gateway-owned Talk session API and shared runtime across Gateway methods, provider contracts, browser/native clients, telephony/meeting adapters, docs, generated metadata, and tests.

Reproducibility: not applicable. for the feature as a whole; yes for the blockers by source inspection of current main and the downloaded PR head diff. Current main exposes the old RPCs and VoiceClaw endpoint, while the PR removes them without an adapter path visible in the changed handlers.

Real behavior proof
Needs real behavior proof before merge: The PR body provides after-fix terminal output for tests and API checks, but no live Gateway/client output, logs, recording, or copied runtime transcript showing the changed behavior after the patch. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, ask a maintainer to comment @clawsweeper re-review.

Next step before merge
Draft maintainer-labeled XL protocol/runtime PR needs author fixes, live proof, and maintainer product/compatibility review rather than a ClawSweeper repair lane.

Security
Cleared: No concrete new security or supply-chain issue found in the inspected diff; the earlier managed-room owner-control concern is addressed by active-client checks and terminal event broadcast.

Review findings

  • [P2] Preserve legacy Talk RPC adapters — src/gateway/server-methods-list.ts:61-71
  • [P2] Keep the VoiceClaw realtime upgrade compatible — src/gateway/server-http.ts:866-887
Review details

Best possible solution:

Keep the unified Talk architecture direction, but preserve or version existing public RPCs and the VoiceClaw endpoint, then add live Gateway/client proof for the changed managed-room and voice paths before merge.

Do we have a high-confidence way to reproduce the issue?

Not applicable for the feature as a whole; yes for the blockers by source inspection of current main and the downloaded PR head diff. Current main exposes the old RPCs and VoiceClaw endpoint, while the PR removes them without an adapter path visible in the changed handlers.

Is this the best way to solve the issue?

No, not yet. The shared runtime may be the right end state, but the current patch needs compatibility or explicit versioning for removed public surfaces plus live behavior proof before it is a maintainable merge candidate.

Full review comments:

  • [P2] Preserve legacy Talk RPC adapters — src/gateway/server-methods-list.ts:61-71
    Current main advertises talk.realtime.session and the talk.realtime.relay* methods, but this method list replaces them with only talk.client.* and talk.session.*. Existing clients using the published methods will get unknown-method errors unless the PR keeps compatibility aliases/handlers or lands this as an explicitly versioned protocol break.
    Confidence: 0.9
  • [P2] Keep the VoiceClaw realtime upgrade compatible — src/gateway/server-http.ts:866-887
    This branch removes the dedicated /voiceclaw/realtime upgrade handling and deletes the VoiceClaw realtime modules, while current main documents that endpoint for VoiceClaw desktop clients. Those clients will now fall into the generic Gateway WebSocket protocol instead of the VoiceClaw protocol, so keep an adapter or explicitly version/deprecate the endpoint before deleting it.
    Confidence: 0.87

Overall correctness: patch is incorrect
Overall confidence: 0.88

What I checked:

  • Protected PR state: The provided GitHub context shows this PR is open, draft, and labeled maintainer, so cleanup close is not allowed even when review blockers are clear. (b1d225b56df3)
  • Current main legacy Talk RPC surface: Current main advertises talk.realtime.session and talk.realtime.relay* methods in the public Gateway method list. (src/gateway/server-methods-list.ts:59, c744b2c236b2)
  • PR head removes legacy Talk RPCs: The PR head method list advertises only talk.client.* and talk.session.*, removing the currently public talk.realtime.* RPC entries without an adapter in the new handlers. (src/gateway/server-methods-list.ts:61, b1d225b56df3)
  • Current main VoiceClaw endpoint: Current main documents /voiceclaw/realtime as a VoiceClaw-compatible WebSocket endpoint and routes it through a dedicated upgrade handler. Public docs: docs/gateway/index.md. (docs/gateway/index.md:187, c744b2c236b2)
  • PR head removes VoiceClaw upgrade path: The PR deletes the VOICECLAW_REALTIME_PATH import, lazy upgrade module, and /voiceclaw/realtime branch from attachGatewayUpgradeHandler; the deleted endpoint modules are also removed. (src/gateway/server-http.ts:866, b1d225b56df3)
  • Managed-room blocker partly fixed: The latest PR head now rejects non-active managed-room connections before start/end/cancel and broadcasts terminal close events to the active client. (src/gateway/server-methods/talk-session.ts:443, b1d225b56df3)

Likely related people:

  • steipete: Prior merged history shows Peter introduced browser realtime Talk transports and has multiple recent realtime voice/provider and Talk config fixes in the affected area. (role: introduced behavior and recent maintainer; confidence: high; commits: 93bbbe5e3732, 04066d246abc, 526372ea36e3; files: src/gateway/server-methods/talk.ts, ui/src/ui/chat/realtime-talk.ts, src/realtime-voice/provider-types.ts)
  • vincentkoc: Recent main history shows Vincent maintaining Gateway HTTP/server hot paths and OpenAI realtime readiness behavior adjacent to the removed upgrade and provider surfaces. (role: recent gateway maintainer; confidence: medium; commits: d38e30e02cd1, 1497425b8dbb, f88e1f4c1c16; files: src/gateway/server-http.ts, extensions/openai/realtime-voice-provider.ts)
  • yagudaev: The current /voiceclaw/realtime endpoint and docs appear to originate from the merged VoiceClaw realtime brain endpoint commit. (role: introduced VoiceClaw endpoint; confidence: high; commits: c997a9f9788e; files: src/gateway/voiceclaw-realtime/session.ts, src/gateway/voiceclaw-realtime/upgrade.ts, docs/gateway/index.md)
  • scoootscooob: Recent main history shows substantial Google realtime and Voice Call work that this PR refactors through shared Talk events. (role: recent voice-call and Google realtime maintainer; confidence: medium; commits: 79dd65e20889, 309ff6bada57, 7fc9a82dca2f; files: extensions/google/realtime-voice-provider.ts, extensions/voice-call/src/webhook/realtime-handler.ts)
  • BunsDev: Recent UI history includes a fix keeping Google Talk off the wrong browser transport, which is directly adjacent to the PR's transport renaming and client selection path. (role: adjacent UI owner; confidence: medium; commits: 1cf68b9243aa; files: ui/src/ui/chat/realtime-talk.ts, src/gateway/server-methods/talk.ts)

Remaining risk / open question:

  • The PR removes public Talk/VoiceClaw surfaces without a demonstrated compatibility adapter or explicit protocol version gate.
  • The submitted real behavior proof is terminal test output only, so an external client/Gateway path has not been observed after the patch.
  • The branch is draft and protected by the maintainer label, so final direction needs explicit maintainer review.

Codex review notes: model gpt-5.5, reasoning high; reviewed against c744b2c236b2.

@steipete
steipete force-pushed the codex/unify-talk-session-runtime branch from e070905 to 6057d0e Compare May 5, 2026 17:51
@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label May 5, 2026
@steipete
steipete force-pushed the codex/unify-talk-session-runtime branch 2 times, most recently from 4b126f1 to bec56c5 Compare May 5, 2026 20:40
@openclaw-barnacle openclaw-barnacle Bot removed the channel: whatsapp-web Channel integration: whatsapp-web label May 5, 2026
@steipete
steipete force-pushed the codex/unify-talk-session-runtime branch 4 times, most recently from 6ff09e8 to b1d225b Compare May 6, 2026 01:10
@steipete
steipete marked this pull request as ready for review May 6, 2026 01:33
@steipete
steipete requested a review from a team as a code owner May 6, 2026 01:33
@steipete
steipete force-pushed the codex/unify-talk-session-runtime branch from efc96b4 to 4883e39 Compare May 6, 2026 01:38
@steipete
steipete merged commit 9b1d28e into main May 6, 2026
94 of 110 checks passed
@steipete
steipete deleted the codex/unify-talk-session-runtime branch May 6, 2026 01:39

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

Copy link
Copy Markdown
Contributor

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: efc96b446f

ℹ️ 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 on lines 480 to +483
export const talkHandlers: GatewayRequestHandlers = {
...talkSessionHandlers,
...talkClientHandlers,
"talk.catalog": async ({ params, respond, context }) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Preserve legacy Talk RPC aliases during migration

This handler table now exposes only talk.session.*/talk.client.* methods, so legacy RPC names (for example talk.realtime.session and talk.realtime.relay*) no longer resolve at all. Existing callers that haven't migrated yet will receive method-not-found instead of a compatibility path, which is a breaking protocol change on the gateway surface. Add alias handlers that forward old method names to the new implementation (or explicitly version-gate the break) before removing the old names.

Useful? React with 👍 / 👎.

Comment on lines +688 to +691
});
}
forgetUnifiedTalkSession(params.sessionId);
respond(true, { ok: true }, undefined);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Evict unified session entries on automatic session shutdown

Unified session records are removed only in talk.session.close, but relay/transcription/handoff sessions can also terminate asynchronously (TTL expiry, provider error, disconnect-driven cleanup). In those paths, the underlying session is gone while the unified registry entry remains, so the map grows indefinitely over time and stale sessionIds keep failing with runtime errors. Wire unified-registry cleanup into non-RPC shutdown paths too, not just explicit close calls.

Useful? React with 👍 / 👎.

@steipete

steipete commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

Landed via rebase onto main.

  • Source head: 4883e39
  • Landed main: 9b1d28e
  • Verification before merge: pnpm test test/vitest-unit-fast-config.test.ts src/gateway/server-methods/talk.test.ts src/gateway/talk-handoff.test.ts extensions/voice-call/src/realtime-fast-context.test.ts, pnpm plugin-sdk:api:check, pnpm exec oxfmt --check ..., git diff --check

Thanks @steipete.

@aiZKP

aiZKP commented May 6, 2026

Copy link
Copy Markdown

Hi @steipete, I’d like to discuss something regarding mobile. If you’re free, can we connect on Telegram?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: android App: android app: ios App: ios app: macos App: macos app: web-ui App: web-ui channel: voice-call Channel integration: voice-call commands Command implementations docs Improvements or additions to documentation extensions: diagnostics-otel Extension: diagnostics-otel extensions: openai extensions: tts-local-cli gateway Gateway runtime maintainer Maintainer-authored PR plugin: azure-speech Azure Speech plugin plugin: file-transfer plugin: google-meet size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants