Skip to content

Commit b168442

Browse files
steipeteIWhatsskill
andcommitted
fix(android): harden Wear realtime Talk routing
Co-authored-by: IWhatsskill <[email protected]>
1 parent 219ca74 commit b168442

17 files changed

Lines changed: 673 additions & 167 deletions

File tree

‎apps/android/CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Adds foreground, on-device Voice Wake with editable Gateway-synced wake words an
66

77
Fixes malformed Android agent and profile initials when display names begin with emoji. Thanks @Leon-SK668.
88

9-
Adds a Wear OS companion for sessions, transcripts, text and voice replies, abort controls, reply notifications, and a launch Tile. The watch proxies through the paired phone and stores no Gateway credentials. Thanks @sibbl and @IWhatsskill.
9+
Adds a Wear OS companion for sessions, transcripts, text and voice replies, realtime Talk, abort controls, reply notifications, and a launch Tile. The watch proxies through the paired phone and stores no Gateway credentials. Thanks @sibbl and @IWhatsskill.
1010

1111
## 2026.7.2 - 2026-07-13
1212

‎apps/android/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ OpenClaw Android is the officially released Google Play app. It connects to an O
2424
- [x] Skills settings can search installed skills, enable or disable them, and install Gateway-verified ClawHub releases
2525
- [x] Per-app language selection for translated resources follows Android system settings and persistence
2626
- [x] Cron job settings support details, run history, run now, edits, enable/disable, and deletion with admin-scoped Gateway access
27-
- [x] Wear OS companion proxies sessions, transcripts, replies, and aborts through the paired phone without storing Gateway credentials on the watch
27+
- [x] Wear OS companion proxies sessions, transcripts, replies, aborts, and realtime Talk through the paired phone without storing Gateway credentials on the watch
2828

2929
## Open in Android Studio
3030

@@ -34,7 +34,7 @@ OpenClaw Android is the officially released Google Play app. It connects to an O
3434

3535
The `wear` app is a paired-phone companion with the same application ID and signing identity as the phone app. The watch discovers the phone through Wear OS Data Layer, then uses the phone's existing authenticated operator session. It never receives or stores Gateway tokens, passwords, TLS pins, or device-signing identity.
3636

37-
The watch supports session selection, bounded text-only transcript history, streaming reply state, text and voice replies, abort, local reply notifications, and a launch Tile. A missing Data Layer event sequence or changed phone-process epoch triggers a fresh history request instead of applying uncertain deltas.
37+
The watch supports session selection, bounded text-only transcript history, streaming reply state, text and voice replies, abort, realtime Talk within the selected session, local reply notifications, and a launch Tile. Realtime Talk streams watch microphone and playback audio over a temporary Wear OS Data Layer channel; it still uses the phone's authenticated Gateway session and closes when the selected phone or Gateway connection changes. A missing Data Layer event sequence or changed phone-process epoch triggers a fresh history request instead of applying uncertain deltas.
3838

3939
```bash
4040
cd apps/android

‎apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ class NodeRuntime private constructor(
10861086
}
10871087
},
10881088
onDisconnected = { message ->
1089+
if (wearRealtimeTalkControllerLazy.isInitialized()) wearRealtimeTalkController.abort()
10891090
clearOperatorGatewayState(retirePendingCronRuns = false)
10901091
chat.applyMainSessionKey(resolveMainSessionKey())
10911092
chat.onDisconnected(message)
@@ -1098,6 +1099,7 @@ class NodeRuntime private constructor(
10981099
wearProxyBridge()?.publishConnection(connected = false, status = message)
10991100
},
11001101
onConnectFailure = { error, pauseReconnect ->
1102+
if (wearRealtimeTalkControllerLazy.isInitialized()) wearRealtimeTalkController.abort()
11011103
val problem = gatewayConnectionProblem(error, pauseReconnect)
11021104
updateStatus {
11031105
operatorConnected = false
@@ -1118,11 +1120,11 @@ class NodeRuntime private constructor(
11181120
requestGateway = ::requestWearGateway,
11191121
isGatewayConnected = operatorSession::isReady,
11201122
gatewayStatusText = { synchronized(gatewayStatusLock) { operatorStatusText } },
1121-
startRealtimeTalk = { nodeId, language ->
1122-
if (startWearRealtimeTalk(nodeId, language)) wearRealtimeTalkSnapshot.value else null
1123+
startRealtimeTalk = { nodeId, sessionKey, attemptId, language ->
1124+
if (startWearRealtimeTalk(nodeId, sessionKey, attemptId, language)) wearRealtimeTalkSnapshot.value else null
11231125
},
1124-
stopRealtimeTalk = { nodeId ->
1125-
if (stopWearRealtimeTalk(nodeId)) wearRealtimeTalkSnapshot.value else null
1126+
stopRealtimeTalk = { nodeId, attemptId ->
1127+
if (stopWearRealtimeTalk(nodeId, attemptId)) wearRealtimeTalkSnapshot.value else null
11261128
},
11271129
)
11281130
}
@@ -1608,7 +1610,6 @@ class NodeRuntime private constructor(
16081610
WearRealtimeTalkController(
16091611
scope = scope,
16101612
isConnected = { gatewayConnectionDisplay.value.isConnected },
1611-
mainSessionKey = { resolveMainSessionKey() },
16121613
requestGateway = { method, paramsJson, timeoutMs ->
16131614
val gatewayId = connectedEndpoint?.stableId ?: error("Gateway not connected")
16141615
operatorSession.requestForEndpoint(gatewayId, method, paramsJson, timeoutMs)
@@ -1626,6 +1627,9 @@ class NodeRuntime private constructor(
16261627
onSnapshot = { snapshot ->
16271628
wearProxyBridge()?.publishTalk(WearRealtimeTalkCodec.encode(snapshot))
16281629
},
1630+
onForceCloseWatchChannel = { nodeId ->
1631+
scope.launch { (appContext as? NodeApp)?.wearRealtimeChannels?.close(nodeId) }
1632+
},
16291633
)
16301634
}
16311635

@@ -1637,19 +1641,22 @@ class NodeRuntime private constructor(
16371641

16381642
internal suspend fun startWearRealtimeTalk(
16391643
nodeId: String,
1644+
sessionKey: String,
1645+
attemptId: String,
16401646
language: String?,
16411647
): Boolean {
16421648
if (talkModeEnabled.value || micEnabled.value || micCooldown.value) return false
16431649
val resolvedLanguage = talkMode.resolveRealtimeLanguageHint(language)
1644-
return wearRealtimeTalkController.start(nodeId, resolvedLanguage)
1650+
return wearRealtimeTalkController.start(nodeId, sessionKey, attemptId, resolvedLanguage)
16451651
}
16461652

1647-
internal suspend fun stopWearRealtimeTalk(nodeId: String? = null): Boolean {
1648-
val stopped = wearRealtimeTalkController.stop(nodeId)
1649-
if (stopped && nodeId != null) {
1650-
(appContext as? NodeApp)?.wearRealtimeChannels?.close(nodeId)
1651-
}
1652-
return stopped
1653+
internal suspend fun stopWearRealtimeTalk(
1654+
nodeId: String? = null,
1655+
attemptId: String? = null,
1656+
): Boolean {
1657+
// The watch closes its channel after receiving the stop response. Closing
1658+
// here races the response and makes a normal stop look like link failure.
1659+
return wearRealtimeTalkController.stop(nodeId, attemptId)
16531660
}
16541661

16551662
internal fun appendWearRealtimeAudio(

‎apps/android/app/src/main/java/ai/openclaw/app/wear/WearProxyBridge.kt‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,6 @@ internal class WearProxyBridge(
7979
private val monotonicMillis: () -> Long = SystemClock::elapsedRealtime,
8080
private val handleRequest: suspend (String, WearMessage.Request) -> WearMessage.Response,
8181
) {
82-
internal constructor(
83-
scope: CoroutineScope,
84-
sender: WearMessageSender,
85-
peerResolver: WearPeerResolver = WearPeerResolver { emptySet() },
86-
monotonicMillis: () -> Long = SystemClock::elapsedRealtime,
87-
handleRequest: suspend (WearMessage.Request) -> WearMessage.Response,
88-
) : this(scope, sender, peerResolver, monotonicMillis, { _, request -> handleRequest(request) })
89-
9082
private val peerLock = Any()
9183
private val peers = LinkedHashMap<String, Long>()
9284
private val missingPeers = LinkedHashSet<String>()

‎apps/android/app/src/main/java/ai/openclaw/app/wear/WearProxyController.kt‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ internal class WearProxyController(
2828
private val requestGateway: suspend (method: String, params: JsonObject) -> JsonElement,
2929
private val isGatewayConnected: () -> Boolean,
3030
private val gatewayStatusText: () -> String,
31-
private val startRealtimeTalk: suspend (nodeId: String, language: String?) -> WearRealtimeTalkSnapshot? = { _, _ -> null },
32-
private val stopRealtimeTalk: suspend (nodeId: String) -> WearRealtimeTalkSnapshot? = { null },
31+
private val startRealtimeTalk:
32+
suspend (nodeId: String, sessionKey: String, attemptId: String, language: String?) -> WearRealtimeTalkSnapshot? = { _, _, _, _ -> null },
33+
private val stopRealtimeTalk: suspend (nodeId: String, attemptId: String) -> WearRealtimeTalkSnapshot? = { _, _ -> null },
3334
) {
3435
suspend fun handle(
3536
request: WearMessage.Request,
@@ -62,15 +63,17 @@ internal class WearProxyController(
6263
params: JsonObject,
6364
): JsonElement {
6465
if (sourceNodeId.isBlank()) throw WearProxyInvalidRequest("Missing Watch node")
65-
params.requireOnly("language")
66+
params.requireOnly("sessionKey", "attemptId", "language")
67+
val sessionKey = params.stringParam("sessionKey", MAX_SESSION_KEY_CHARS)
68+
val attemptId = params.stringParam("attemptId", MAX_ATTEMPT_ID_CHARS)
6669
val language =
6770
params
6871
.optionalStringParam("language", 2)
6972
?.lowercase(Locale.ROOT)
7073
?.takeIf { value -> value.length == 2 && value.all { it in 'a'..'z' } }
7174
?: if ("language" in params) throw WearProxyInvalidRequest("Invalid language") else null
7275
val snapshot =
73-
startRealtimeTalk(sourceNodeId, language)
76+
startRealtimeTalk(sourceNodeId, sessionKey, attemptId, language)
7477
?: throw WearProxyGatewayException("action_rejected", "Real-Time Talk is unavailable")
7578
return WearRealtimeTalkCodec.encode(snapshot)
7679
}
@@ -80,9 +83,10 @@ internal class WearProxyController(
8083
params: JsonObject,
8184
): JsonElement {
8285
if (sourceNodeId.isBlank()) throw WearProxyInvalidRequest("Missing Watch node")
83-
params.requireOnly()
86+
params.requireOnly("attemptId")
87+
val attemptId = params.stringParam("attemptId", MAX_ATTEMPT_ID_CHARS)
8488
val snapshot =
85-
stopRealtimeTalk(sourceNodeId)
89+
stopRealtimeTalk(sourceNodeId, attemptId)
8690
?: throw WearProxyGatewayException("action_rejected", "Real-Time Talk belongs to another Watch")
8791
return WearRealtimeTalkCodec.encode(snapshot)
8892
}
@@ -186,6 +190,7 @@ internal class WearProxyController(
186190
const val MAX_HISTORY_CHARS = 2_000
187191
const val MAX_HISTORY_OFFSET = 100_000
188192
const val MAX_SESSION_KEY_CHARS = 512
193+
const val MAX_ATTEMPT_ID_CHARS = 128
189194
const val MAX_MESSAGE_CHARS = 4_000
190195
const val MAX_IDEMPOTENCY_KEY_CHARS = 128
191196
const val MAX_RUN_ID_CHARS = 128

0 commit comments

Comments
 (0)