fix(device-ts): preserve accepted Whisper batches after stop

Merged
1A
2mo ago
+123-4

What changed and why

Fixes #12964. Stopping the TypeScript device SDK's local Whisper transcriber now preserves transcripts for accepted full batches and the final tail, delivered in input order. The implementation reuses the promise-queue pattern already present in the React Native Whisper adapter; empty or failed runner results do not strand subsequent batches, callback errors are contained even in the final batch, and stop still returns immediately.

The earlier work in #12971 and #13613 identified this defect and the ordering requirement. Both PRs are closed. Although #12971's closing comment says the production change is on main, the current 3f3af198ef2c implementation still discards an in-flight full batch after stop. The new factory-level regression reproduces that behavior on this base. This PR credits those investigations and supplies a fresh, compact fix against current main.

Product invariants affected

none

How it was verified

  • Bun 1.3.14: bun test sdks/device/typescript — 38 tests passed, 78 assertions. The five initial regression cases fail against the unchanged implementation; the existing buffered-tail control passes. A follow-up callback-error regression fails on the first PR commit and passes with the review fix, without intercepting unhandled rejections.
  • TypeScript passed both the production tsconfig.json check and a separate strict check of all three test files with Bun 1.3.14 type definitions (the production config excludes tests). Existing cached compiler/type dependencies were used without changing package dependencies.
  • make preflight — all 14 selected checks passed on Linux, including the SDK suite and draft PR metadata contracts.
  • No Whisper model, physical BLE device, credentials, or live service was used.
  • make setup installed the repository hooks and refreshed the task branch. Its unrelated locked backend install cannot build webrtcvad on this Windows host without MSVC; SDK checks and preflight use the existing test tooling and Python gate environment.
  • The full SDK suite also passed under Linux. Native Windows preflight intermittently timed out in the unchanged Noble subprocess test; the successful Linux run uses the same Bun version and unmodified test deadline.

Tests

sdks/device/typescript/src/stt/index.test.ts exercises the real shared factory and Whisper adapter with synthetic PCM and controlled runners: an in-flight full batch across stop, full-batch-before-tail ordering, repeated stop, post-stop input rejection, continuation after empty results, synchronous throws, and rejected promises, and safe completion when the first and final transcript callbacks throw. The suite already runs through the shared local/CI manifest.

Failure class (fixes)

Failure-Class: none

The failed boundary is completion of SDK audio accepted before stop. FC-active-only-guard-aborts-owed-delivery concerns budgeted proactive context evaluation, and FC-accepted-session-completes-silently-without-payload concerns sessions that never receive audio; neither covers this SDK runner-completion defect. This fix retains accepted work in the existing adapter and adds regression coverage to its existing suite; it introduces no new shared checker or registry guard.