Skip to content

Fix recorder teardown race, CFHash overflow trap, ignored mic pin - #370

Merged
alexkroman merged 2 commits into
mainfrom
claude/modest-ramanujan-epnrq8
Nov 25, 2026
Merged

alexkroman merged 2 commits into
mainfrom
claude/modest-ramanujan-epnrq8

Conversation

@alexkroman

@alexkroman alexkroman commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What & why

Fixes #340 — three bugs in the Record button's recorder and voice commands — plus a flaky test this PR's CI surfaced.

1. Data race in SystemAudioRecorder.teardown(). The "recorder stopping" log read MixWriter.summary on the caller's thread before the IOProc was stopped, while the IOProc was still writing those counters (and the lastError string) on the recorder's queue. The summary is now read inside the existing queue.sync, after AudioDeviceStop/AudioDeviceDestroyIOProcID, just before the file closes.

2. Overflow trap on CFHash. PressFingerprint.focusedElement converted the unsigned CFHashCode with Int(_:), which traps whenever the top bit is set — on any press in Chromium/Electron or select in any app. It now uses Int(bitPattern:); only equality is ever asked of the value, so the type stays Int?.

3. Recorder ignored the pinned microphone. The recorder always bound the system default input, ignoring the microphone pinned in Settings › Microphone. It now resolves the pin first and falls back to the system default when the pinned device isn't connected, the same rule dictation follows. Doc comments in SystemAudioRecorder and MicDeviceStore updated to match.

Flaky test. SelectionSpeechRouterLifecycleTests "a held read starts once the key has been down for the hold delay" waited on the real 300 ms hold timer within waitUntil's 5 s budget; on a loaded CI run (every test taking ~7 s) the timer task was starved and it failed with CancellationError (unrelated to the changes above). It now steps the router's injected clock with TestClock, as its sibling test already did, asserting the hold is still 1 ms away before advancing the last millisecond. The shared press-wait-advance steps moved into a helper to satisfy jscpd.

How it was tested

  • scripts/check.sh passes (or CI will, if I'm not on a Mac)
  • I read AGENTS.md and this doesn't reintroduce anything deliberately removed
  • Docs updated if behavior changed

Written in a Linux sandbox: scripts/check.sh --portable passes locally; CI on macOS (full check, iOS build and sanitizers) is green on the head commit. No new tests for fixes 1–3: they live in Core Audio / Accessibility glue that the unit tests don't drive.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DS5B1SoHzenCMeXaqWBW2k

- SystemAudioRecorder.teardown() read MixWriter.summary on the caller's
  thread while the IOProc was still writing those counters on the
  recorder queue. Read it inside queue.sync, after the IOProc stops.
- PressFingerprint converted CFHash (UInt) with Int(_:), which traps on
  any hash with the top bit set. Convert by bit pattern instead.
- The Record button's recorder bound the system default input and
  ignored the microphone pinned in Settings. Resolve the pin first,
  falling back to the default when it isn't connected, as dictation does.

Fixes #340

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1SoHzenCMeXaqWBW2k
heldReadStartsAfterTheDelay waited on the router's real 300 ms hold timer
through waitUntil's 5 s budget. On a loaded CI run (every test in the
suite taking ~7 s) the timer task was starved past that budget and the
test failed with CancellationError, as on #370. Step it on
a TestClock as its sibling test already does, and assert the hold is
still 1 ms away rather than measuring a wall-time lower bound.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1SoHzenCMeXaqWBW2k
@alexkroman alexkroman changed the title Use pinned microphone in recorder, fix CFHash bit-pattern conversion Fix recorder teardown race, CFHash overflow trap, ignored mic pin Nov 24, 2026
@alexkroman
alexkroman added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit fcc7d48 Nov 25, 2026
13 checks passed
@alexkroman
alexkroman deleted the claude/modest-ramanujan-epnrq8 branch November 25, 2026 00:36
alexkroman pushed a commit that referenced this pull request Nov 25, 2026
…eld-read test

#375 gave the relay a ResultAddress presser; the injected clock now sits
beside it, and the delivered test steps the clock while asserting the
controller. #370 independently moved the held-read test onto a TestClock
with its own press helper; its version is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audio & Voice Commands: SystemAudioRecorder.teardown() data race on MixWriter.summary, unchecked Int(CFHash) overflow crash, and ignored pinned mic

2 participants