Files
coucou/scripts/test-voice-backoff.sh
Louis RailleandClaude Sonnet 4.6 a1709acf77 voice: reliability — backoff, auto-repair, idempotent endCommand, AEC
1. WakeWindowBackoff (new pure struct): exponential backoff for wake-window
   reopening (0.5 → 1 → 2 → 4 → 5 s cap). After maxFastFails=3 consecutive
   fast-fail windows, returns .stop and waits for the next VAD segment.
   Eliminates the 40+ "window open" storm per second seen in the logs.

2. WakeSpotter: beginWindow() returns Bool (false = task not started);
   logs [WakeSpotter] task start / task refused (unavailable|already active) /
   task end: final|error domain/code, partials N.
   onWakeWindowEnded now carries wasError: Bool.
   VoiceEngine "window open" log only written when task actually started.

3. VoiceEngine: endCommand() is now idempotent — if not in command mode,
   only cancels pending timers and returns. endWindow() and resetVAD() are
   NOT called, so a freshly opened wake window is never closed by a delayed
   result-view dismissal.

4. VoiceEngine auto-repair:
   • AVAudioEngine config change (headphone connect/disconnect) → rebuild
   • 3 consecutive window errors → rebuild
   • Audio stall: if no buffers arrive within 2 s while VAD is active → rebuild
   • Recognizer unavailable: 1 s retries up to 10 s then rebuild

5. VoiceAudio: setVoiceProcessingEnabled(true) on macOS 14+ enables AEC
   (acoustic echo cancellation — removes Mac speaker echo from the mic).
   This does NOT duck other apps' audio (iOS-only API); music plays at
   full volume. Observes AVAudioEngineConfigurationChange and fires onConfigChange.
   lastBufferTime updated on every tap for stall detection.

6. stopAudioPipeline() nulls all callbacks before stop() so any pending
   main-thread dispatches from the old pipeline become no-ops after rebuild.

7. IslandWindowController: wrap voiceWoke/voiceFinished observer bodies in
   Task { @MainActor in } to silence Swift 6 Sendable-closure concurrency
   warnings introduced in revue 3.

8. New test: WakeWindowBackoff — 10/10 (pure, no AppKit, fast-fail math
   and streak-cap verified). All 230 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-10-09 23:47:45 +02:00

8 lines
225 B
Bash

#!/usr/bin/env bash
set -e
echo "Running WakeWindowBackoff tests…"
swiftc -o /tmp/voice-backoff-tests \
NotchBuddy/Sources/App/Voice/WakeWindowBackoff.swift \
tests/WakeWindowBackoffTests.swift
/tmp/voice-backoff-tests