Skip to content

[Bug]: A slow microphone refresh can mark an unplugged microphone as in use #39593

Done

Description

@StiensWout

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/web

Steps to reproduce

  1. Open Settings → Voice with a USB microphone connected and microphone access already granted.
  2. Move the USB microphone to the top of the microphone list.
  3. Click Refresh microphones.
  4. Unplug the USB microphone before the refresh finishes.
  5. Watch the USB microphone row as the two updates arrive.

Expected behavior

Once the microphone shows Not connected, it stays disconnected until it is plugged back in.

Actual behavior

The row changes from Not connected back to In use when the older refresh finishes.

after stale microphone scan

failure

Impact

Minor bug or occasional failure. People who unplug their preferred microphone during a slow refresh can see the wrong active input until another refresh.

Version or commit

main at d6cdb4f161. The cause is at apps/web/src/components/settings/VoiceSettingsPanel.tsx:1338.

Environment

Linux x64 boat.dev default machine, a fresh checkout.

Logs or stack traces

The unplugged microphone remains marked Not connected
Automated repro

Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.

diff --git a/scripts/scenarios/microphone-refresh-keeps-newer-device-list.e2e.ts b/scripts/scenarios/microphone-refresh-keeps-newer-device-list.e2e.ts
new file mode 100644
index 0000000000..71c5945438
--- /dev/null
+++ b/scripts/scenarios/microphone-refresh-keeps-newer-device-list.e2e.ts
@@ -0,0 +1,95 @@
+/// <reference lib="dom" />
+import { expect } from "e2e";
+
+import { test, WEB } from "./t3.ts";
+
+declare global {
+  interface Window {
+    microphoneEnumeration?: {
+      holdOldScan(): void;
+      readonly oldScanStarted: Promise<void>;
+      disconnectUsbMicrophone(): void;
+      releaseOldScan(): void;
+    };
+  }
+}
+
+test(
+  "A slow microphone scan cannot bring back a disconnected microphone",
+  WEB,
+  async ({ t3, app, browser, screen }) => {
+    await t3.project("demo");
+    await browser.addInitScript(() => {
+      const devices = navigator.mediaDevices;
+      const internalMic = {
+        kind: "audioinput",
+        deviceId: "internal",
+        label: "Internal test microphone",
+      };
+      const usbMic = { kind: "audioinput", deviceId: "usb", label: "USB test microphone" };
+      let connected = [internalMic, usbMic];
+      let holdNext = false;
+      const started = Promise.withResolvers<void>();
+      const release = Promise.withResolvers<void>();
+      // Emulate device snapshots when each enumeration starts and vary their delivery order.
+      Object.defineProperty(devices, "enumerateDevices", {
+        value: async () => {
+          const snapshot = connected;
+          if (holdNext) {
+            holdNext = false;
+            started.resolve();
+            await release.promise;
+          }
+          return snapshot;
+        },
+      });
+      window.microphoneEnumeration = {
+        holdOldScan: () => {
+          holdNext = true;
+        },
+        oldScanStarted: started.promise,
+        disconnectUsbMicrophone: () => {
+          connected = [internalMic];
+          devices.dispatchEvent(new Event("devicechange"));
+        },
+        releaseOldScan: release.resolve,
+      };
+    });
+
+    await t3.open("/settings/voice");
+    const moveUsbUp = screen.getByRole("button", "Move USB test microphone up", { exact: true });
+    await moveUsbUp.waitFor();
+    while (await moveUsbUp.isEnabled()) await moveUsbUp.tap();
+
+    const list = screen.getByRole("list", "Microphones, preferred first", { exact: true });
+    const usbRow = list.getByRole("listitem").filter({ hasText: "USB test microphone" });
+    await usbRow.getByText("In use", { exact: true }).waitFor();
+
+    await browser.evaluate(() => {
+      window.microphoneEnumeration!.holdOldScan();
+      return null;
+    });
+    await screen.getByRole("button", "Refresh microphones", { exact: true }).tap();
+    await browser.evaluate(async () => {
+      await window.microphoneEnumeration!.oldScanStarted;
+      window.microphoneEnumeration!.disconnectUsbMicrophone();
+      return null;
+    });
+    const disconnected = usbRow.getByText("Not connected", { exact: true });
+    await disconnected.waitFor();
+
+    await browser.evaluate(async () => {
+      window.microphoneEnumeration!.releaseOldScan();
+      // Sample after the delivered device list has had a chance to paint.
+      await new Promise<void>((resolve) =>
+        requestAnimationFrame(() => requestAnimationFrame(() => resolve())),
+      );
+      return null;
+    });
+    await app.screenshot("after-stale-microphone-scan");
+    expect(
+      await disconnected.isVisible(),
+      "The unplugged microphone remains marked Not connected",
+    ).toBe(true);
+  },
+);
pnpm scenarios:prove scripts/scenarios/microphone-refresh-keeps-newer-device-list.e2e.ts --base main

Workaround

No response

Activity

  1. added
    vouch:trusted
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vouch:trusted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions