Skip to content

Commit 06c451e

Browse files
committed
fix(macos): stop canceled voice wake timers
1 parent 859280e commit 06c451e

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Docs: https://docs.openclaw.ai
5858
- **Linux gateway service ownership:** refuse user-scope systemd publication and activation when the same gateway unit name is already owned or cannot be verified in the system scope, including `--force`, with actionable recovery guidance instead of creating restart-looping dual managers. Fixes #116129.
5959
- **macOS remote tunnel lifecycle:** prevent cancelled or superseded restart backoffs from recreating SSH tunnels, and join a tunnel create that another caller started while the actor was suspended.
6060
- **macOS location permission requests:** coalesce concurrent prompts so every caller resumes, and stop cancelled timeouts from opening Settings or completing a newer request.
61+
- **macOS Voice Wake cancellation:** stop superseded silence, capture, and recognizer-restart timers immediately so cancelled work cannot restart the microphone pipeline or keep stale monitor loops alive.
6162
- **Control UI update reconciliation:** preserve an unresolved managed-update request across disconnects, accept the replacement Gateway version when it proves success, and otherwise show explicit recovery guidance instead of trusting an unrelated cached update result or failing silently. Fixes #116075. Thanks @shakkernerd.
6263
- **Control UI model readiness:** put AI setup first when no model is selectable, distinguish signed-in credentials from ready providers, and route accounts with no exposed models directly to provider recovery instead of leading with disabled default controls.
6364
- **Control UI Talk session isolation:** stop active realtime Talk media and retire its callbacks before chat session changes, Gateway disconnects, or pane disposal so previous-session audio, transcript, camera, and status updates cannot leak into the next view. Thanks @shakkernerd.

‎apps/macos/Sources/OpenClaw/VoiceWakeRuntime.swift‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ import SwabbleKit
88
import AppKit
99
#endif
1010

11+
enum VoiceWakeRuntimeTaskSupport {
12+
static func wait(nanoseconds: UInt64) async -> Bool {
13+
guard !Task.isCancelled else { return false }
14+
do {
15+
try await Task.sleep(nanoseconds: nanoseconds)
16+
} catch {
17+
return false
18+
}
19+
return !Task.isCancelled
20+
}
21+
}
22+
1123
/// Background listener that keeps the voice-wake pipeline alive outside the settings test view.
1224
actor VoiceWakeRuntime {
1325
static let shared = VoiceWakeRuntime()
@@ -448,7 +460,7 @@ actor VoiceWakeRuntime {
448460
let lastText = self.lastTranscript
449461
let windowNanos = UInt64(self.triggerPauseWindow * 1_000_000_000)
450462
self.triggerOnlyTask = Task { [weak self, lastSeenAt, lastText] in
451-
try? await Task.sleep(nanoseconds: windowNanos)
463+
guard await VoiceWakeRuntimeTaskSupport.wait(nanoseconds: windowNanos) else { return }
452464
guard let self else { return }
453465
await self.triggerOnlyPauseCheck(
454466
lastSeenAt: lastSeenAt,
@@ -468,7 +480,7 @@ actor VoiceWakeRuntime {
468480
let lastText = self.lastTranscript
469481
let windowNanos = UInt64(self.preDetectSilenceWindow * 1_000_000_000)
470482
self.preDetectTask = Task { [weak self, lastSeenAt, lastText] in
471-
try? await Task.sleep(nanoseconds: windowNanos)
483+
guard await VoiceWakeRuntimeTaskSupport.wait(nanoseconds: windowNanos) else { return }
472484
guard let self else { return }
473485
await self.preDetectSilenceCheck(
474486
lastSeenAt: lastSeenAt,
@@ -632,7 +644,7 @@ actor VoiceWakeRuntime {
632644
return
633645
}
634646

635-
try? await Task.sleep(nanoseconds: 200_000_000)
647+
guard await VoiceWakeRuntimeTaskSupport.wait(nanoseconds: 200_000_000) else { return }
636648
}
637649
}
638650

@@ -737,7 +749,7 @@ actor VoiceWakeRuntime {
737749
self.scheduledRestartTask?.cancel()
738750
self.scheduledRestartTask = Task { [weak self] in
739751
let nanos = UInt64(max(0, delay) * 1_000_000_000)
740-
try? await Task.sleep(nanoseconds: nanos)
752+
guard await VoiceWakeRuntimeTaskSupport.wait(nanoseconds: nanos) else { return }
741753
guard let self else { return }
742754
await self.consumeScheduledRestart()
743755
await self.restartRecognizerIfIdleAndOverlayHidden()

‎apps/macos/Tests/OpenClawIPCTests/VoiceWakeRuntimeTests.swift‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ import Testing
44
@testable import OpenClaw
55

66
struct VoiceWakeRuntimeTests {
7+
@Test func `cancelled runtime delay does not continue`() async {
8+
let task = Task {
9+
await VoiceWakeRuntimeTaskSupport.wait(nanoseconds: 60_000_000_000)
10+
}
11+
12+
await Task.yield()
13+
task.cancel()
14+
15+
#expect(await task.value == false)
16+
}
17+
718
@Test func `trims after trigger keeps post speech`() {
819
let triggers = ["claude", "openclaw"]
920
let text = "hey Claude how are you"

0 commit comments

Comments
 (0)