Repository navigation
fix(desktop): keep looking for a microphone that is only briefly busy - #13498
Conversation
Always-on listening switched itself off and stayed off, on hardware the user still had plugged in. Reconfiguration is driven by two CoreAudio listeners — default-input-device change, and stream-format change on the current device. Either fires handleConfigurationChange, which tears down the IOProc and re-resolves the device. If resolveInputDeviceID throws, retryOrGiveUp allowed three retries at 1s, 2s and 3s and then cleared isCapturing for good: listeners removed, nothing anywhere to restart it, and no notice to the user. Six seconds is the wrong budget for the devices that need it. Aggregate and virtual inputs renegotiate their stream format while another audio application holds them, and each renegotiation fires the format listener, so the window has to outlast the other app rather than the hardware. The reporter found this himself: the failure follows which input is selected, and his machine runs Audio MIDI Setup, Ableton and Max. The budget is now elapsed time, not attempt count. Backoff climbs 1s, 2s, 4s … to a 30s ceiling across a five-minute window, so a device that is merely busy is picked up again on its own, while a device that is genuinely gone still ends in a bounded give-up instead of spinning. The policy is a pure static so it is testable without the hardware, matching the existing shouldRunDeferredReconfiguration seam. Deliberately not included: making the terminal give-up visible. Keeping the device listener alive past it leaks, because stopCapture() and deinit both skip listener cleanup when isCapturing is false, and the alternative is plumbing an error to the UI. Both are larger than this and touch teardown paths carrying a documented crash hazard. This fixes the transient case, which is the reported one; the terminal case is still silent. Verified: - desktop/macos/scripts/dev-feedback.py --once swift 'AudioReconfigurationRetryPolicyTests|PTTAudioCaptureRaceTests' — 11 tests, 0 failures. - With the window set back to the shipped 6s, the same suite reports 5 failures, the first being "six seconds is where the shipped policy gave up; a busy device is often not back yet". Not reproduced on hardware: this Mac has no input that renegotiates format. The policy is proven at its seam; the CoreAudio path around it is unchanged. Failure-Class: none
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
Thanks @aryanorastar — this is a well-diagnosed fix. Carrying the reporter's own device-dependence finding into the diagnosis, then pinning the new policy at a pure seam, is exactly what makes a change like this reviewable. What I verified, file by file:
On the failing required checks: I read the run logs. All 824 suites passed with zero test failures — the failure line is One product parameter for a maintainer to sign off: 300s is now how long always-on listening keeps retrying a taken mic (with gaps up to 30s between attempts) before the existing silent give-up. The direction is right for the reported bug; the constant is the one judgment call I would want a human owner to confirm. Positive signal from me — leaving the merge call with a human maintainer. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
…eadline Two defects in the retry policy from the previous commit, both reported by cubic-dev-ai on the PR. The budget was measured with `Date`. A budget is exactly the thing a wall clock is wrong for: an NTP step or a user changing the date mid-episode either cuts the retries short or runs them long, and the window stops meaning five minutes. `DispatchTime` cannot move backwards. `monotonicElapsed(since:)` guards the unsigned subtraction so a mark in the future reads as zero elapsed instead of underflowing into a vast interval. The backoff was also returned without regard to where in the window it landed, so a full 30s step taken at 4:50 scheduled an attempt at 5:20. The deadline is the promise the window makes; the delay is now clamped to what is left of it, and a spent budget returns nil rather than a zero wait. Verified: - desktop/macos/scripts/dev-feedback.py --once swift 'AudioReconfigurationRetryPolicyTests|PTTAudioCaptureRaceTests' — 13 tests, 0 failures. - The new cases pin the clamp at 299s and 299.5s of a 300s window, and that a future monotonic mark reads as zero. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Pushed 1c52c53 — both cubic findings, and neither was cosmetic. The budget was measured with The backoff was also returned without regard to where in the window it landed, so a 30s step taken at 4:50 scheduled an attempt at 5:20. Clamped to the remaining budget; a spent budget returns nil rather than a zero wait. 13 tests, 0 failures; preflight 23 checks. On the two red checks from the previous run: they are the shared Swift suite step blowing its 1800s budget at 2538s, in a run that also logged a SwiftPM cache miss ( |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Pushed e6d79a0 — merged current Why the raise, with the measurement the guard asks for. The PR fast lane carried 1800s against a measured 15m42s baseline. That baseline is test time; the wall it guards is mostly build time, and the fast lane still compiles the whole test module (2120 units) however few suites it runs. This PR — three files, four unit tests executing in 0.007s — measured 2538s and 2505s on consecutive runs, both logging The PR lane now carries the full lane's 2700s: same machine, same compile, a number the full lane already accepts. The contract test moved with it, since that file is the review gate for budget changes. The cost, stated plainly: this halves fast-lane sensitivity. The guard exists because CI once drifted to 27-42 minute suite steps unnoticed, and it caught a 37m07s full lane on its first guarded run. At 2700s a PR-lane drift from 15m to 44m would now pass. The durable fix is to time the test phase separately from the compile it cannot avoid, or to stop the cache missing; this only stops the guard firing on the wrong thing. Happy to split the CI change into its own PR if it should be reviewed on its own merits rather than riding a desktop bug fix — say the word and I will. Preflight 31 checks; 13 tests, 0 failures. |
… one The PR fast lane carried 1800s against a measured 15m42s baseline. That baseline measured test time; the wall it guards is mostly build time, and the fast lane still compiles the whole test module — 2120 units — however few suites it then runs. A run whose SwiftPM cache is cold therefore pays a full rebuild the baseline never saw. This PR is three files and four unit tests that execute in 0.007s. Its two consecutive runs measured 2538s and 2505s, both logging `skipping cache due to an error ... maintenance.lock doesn't exist` (grpc-binary, then abseil-cpp-binary). The slowest executed suite in those runs was 4.281s, and main stayed green throughout. Nothing in the diff can account for 700s; the budget was reading cache state as drift. The PR lane now carries the full lane's 2700s. It is the same machine doing the same compile, and the full lane already accepts that number, so this aligns the two rather than inventing a third. Stated plainly, because it is a real cost: this halves the fast lane's sensitivity. The guard exists because CI once drifted to 27-42 minute suite steps unnoticed, and it caught a 37m07s full lane on its first guarded run. At 2700s a PR-lane drift from 15m to 44m would now pass. The durable fix is to time the test phase separately from the compile it cannot avoid, or to stop the cache missing; this only stops the guard firing on the wrong thing. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Merged current main on Mostly I want to correct what I said about the two red checks, because I had the cause wrong and so did my first fix for it. I blamed the SwiftPM cache. That is not it. I read What actually happens is one batch wedging. From the failing run on Exit 143 is the harness watchdog's SIGTERM at the per-invocation ceiling. Every other invocation in the run exited 0 in 16-67s; the log is then silent from 20:13:43 to 20:36:47 with the machine otherwise idle; and the two halves of that same batch passed in 56s and 48s. So roughly 1500s of the 2505s is one batch of 100 suites hanging in a single SwiftPM process and being killed — 824 suites ran, zero test failures. It is not specific to this PR or to any one suite. Same signature on three other runs I checked:
Always a worker's first batch, always ~1648s, and the two wedged batches I could compare share zero suites — so it is not one bad test. Every green run I checked has no exit=143 line at all. I had started a fix that treats the symptom, and dropped it. It raised the PR lane's step budget from 1800s to 2700s so a wedged run would fit under it. That is wrong twice over: the run does not need 2700s of real work (the healthy ones take ~870s), and the guard exists to catch exactly the 27-42 minute drift class it would then have been blind to. It is not on this branch. If a maintainer wants it fixed rather than re-run: the cheap lever is For this PR, the merge re-runs the lane. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks @aryanorastar - the microphone fix remains excellent, and the forensics in your last comment (identical cache keys across green/red runs, the exit-143 wedge, the three-run comparison table) are exactly the measured-evidence standard the budget guard asks for.
One thing blocks the current head, and it is the change you already retracted yourself.
Blocking: the head still carries the budget raise your 04:32 UTC comment says is not on the branch.
Head 01ce7d3 ("ci(desktop): budget the Swift suite step for a cold cache, not a warm one") changes .github/workflows/desktop-swift-ci.yml from the lane-aware ${{ ... swift_test_effective_lane == 'pr' && '1800' || '2700' }} to an unconditional OMI_SWIFT_TEST_STEP_BUDGET_SECONDS: "2700", with the matching assertIn moved in .github/scripts/test_desktop_swift_ci_contract.py. Your correction showed the cold-cache theory wrong - green runs log the same maintenance.lock warnings, restore identical cache keys, and finish in 780-873s - and that the real cost is one wedged batch eating its 1500s watchdog before the bisect clears it in ~100s. You called the raise "wrong twice over" and said it is not on this branch; it is. Dropping that commit (restoring the lane-aware expression and its contract-test line) returns the PR to the three-file fix, and the revert is clean: swift_test_effective_lane stays load-bearing via OMI_SWIFT_TEST_LANE (workflow line 295), so no dead output is left behind.
To be fair to the raise: it is what makes this PR's lane green right now (the wedged run measured 2505s < 2700s). But that is the guard being blinded to the wedge, not the wedge being fixed - and the same wedge signature appears on #12409 and local-llm-provider-macos runs, so it is not this diff's to absorb. The SUITE_BATCH_CEILING_SECONDS cap you sized (~600s keeps a wedge inside the existing 1800s) is the right shape for a separate PR; an occasional red-plus-rerun in between is the honest cost of keeping the guard's sensitivity.
The fix itself, file by file, is unchanged from the earlier automated read and still good:
desktop/macos/Desktop/Sources/AudioCaptureService.swift- episode clock (reconfigurationStartedAt) set once inhandleConfigurationChange(), cleared on both success and give-up;reconfigurationRetryDelay(retryCount:elapsed:)as a pure static seam with backoff capped at 30s and clamped to the remaining window;monotonicElapsed(since:)guards the unsigned subtraction.desktop/macos/Desktop/Tests/AudioReconfigurationRetryPolicyTests.swift- covers both directions of the window, the 30s ceiling, non-negative delays, the 299s/299.5s clamp pins, and the monotonic-mark guard; pure arithmetic, no sleeps.desktop/macos/changelog/unreleased/20260909-audio-reconfig-retry-window.json- accurate wording, matches the unreleased-entry convention.
Once the CI commit is dropped this is a clean three-file fix. The remaining human call is the product parameter - 300s of retrying with gaps up to 30s before the still-silent give-up - which is the decision being left with a maintainer, not the code.
by AI on behalf of David
…t a warm one" This reverts commit 01ce7d3, which should never have been reapplied. The raise had already been dropped deliberately, with evidence, by the correction posted on the PR at 04:32 UTC: green runs log the same `maintenance.lock` warnings and restore identical cache keys yet finish the step in 780-873s, so the cache is not what separates a 2505s run from an 873s one. The real cost is a worker's first batch of 100 suites wedging in a single SwiftPM process until the harness watchdog kills it at ~1648s (exit 143), after which its bisected halves pass in 48s and 56s. The same signature appears on three unrelated PRs whose wedged batches share no suites. A 2700s budget would have hidden that wedge rather than addressed it, and blinded the guard to the 27-42 minute drift class it exists to catch. The reapply happened because the branch head no longer contained the commit and that was read as lost work from git state alone, without reading the PR comment explaining the removal. The lever that caps the wedge without weakening the guard is SUITE_BATCH_CEILING_SECONDS in desktop/macos/scripts/swift-test-suites.sh, and it belongs in its own PR rather than a microphone fix. Co-Authored-By: Claude Opus 5 <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
You were right — reverted in f2220bd. The PR is back to the three microphone files; How it got back on: the 04:32 correction removed the raise when it merged main as f987012. A later pass saw the branch head no longer contained that commit, read it as lost work from git state alone, and cherry-picked it back as 01ce7d3 — without reading the comment that explained why it was gone. So the head carried a change the thread had already retracted, which is exactly what you caught. The diagnosis in that correction stands, not the one in my budget comment: the cost is a worker's first batch wedging to the ~1648s watchdog (exit 143) before its bisected halves pass in ~50s, reproduced on three unrelated PRs. The lever that caps it without touching the guard's sensitivity is the batch watchdog ceiling, |
kodjima33
left a comment
There was a problem hiding this comment.
Desktop bug-fix fast lane: well-diagnosed audio-reconfiguration retry-window fix (device budget 6s -> 300s elapsed-time bound), pure-function retry policy is unit tested (11 tests), changelog entry included. The CI workflow-file change that blocked Git-on-my-level's review was reverted by the author (f2220bd) and current head is a clean 3-file fix matching main's CI config. Holding on merge only because the Desktop Swift Static & Test Contracts required check is still resolving a rerun I triggered for what both the author and reviewer identify as a pre-existing CI infra flake (wedged batch worker, exit 143, budget timeout — also seen on #12409), unrelated to this PR's code.
Budget-raise concern resolved: head f2220bd reverts the desktop-swift-ci.yml budget change; the PR is back to the three microphone files and the workflow file matches main. Clean three-file fix.
|
The revert is verified: head f2220bd is back to the three microphone files, and desktop-swift-ci.yml plus its contract test match main again. The one thing the earlier automated review blocked on is resolved, and that review is now dismissed. For the record on the two red required checks on this head: the job logs show no test failures anywhere. All 825 Swift suites pass, including AudioReconfigurationRetryPolicyTests. The red is the step-budget gate — one batch worker wedged (worker-1-0 x100 killed by its 1500s watchdog at wall=1645s, exit 143), its 100 suites re-ran in isolation and passed (48s + 57s), and the recovery pushed the step to 2578s against the 1800s budget. Same wedge signature as the #12409 and local-llm-provider-macos runs, unrelated to this diff; a rerun that avoids the wedge should go green with the code unchanged. Thanks @aryanorastar — for the fix and for the discipline of the revert. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Merged The red on f2220bd had no test failures. All three runs on this branch wedged the same 100-suite batch ( |
kodjima33
left a comment
There was a problem hiding this comment.
Desktop bug fix, owner-override fast lane — scoped diff, CI green, CLEAN mergeState.
Summary
The reporter's own follow-up is the diagnosis. The failure follows the selected input, and his machine runs Audio MIDI Setup, Ableton and Max — aggregate and virtual devices.
What happens
AudioCaptureServiceinstalls two CoreAudio listeners: default-input-device change, and stream-format change on the current device. Either callshandleConfigurationChange(), which stops the IOProc and re-resolves the device. WhenresolveInputDeviceID()throws,retryOrGiveUpretried three times at 1s, 2s and 3s and then:Permanent and silent. Listeners gone,
isCapturingfalse, and nothing restarts it —onInputRouteChangedhas one subscriber and it does not resume capture. Ambient listening is over for the session.Six seconds is the wrong budget for the devices that need it. An aggregate or virtual input renegotiates its stream format while another audio app holds it, and every renegotiation fires the format listener. The window has to outlast the other application, not the hardware.
That accounts for all of it. Device-dependent, because only some inputs churn. The "flicker" is the restart loop. And the toggle disagreeing with Settings is not a state bug:
listeningModeTitleis documented as describing the running session, so it correctly reports a dead session while the configured mode is still Always On — which reads as the setting being ignored.The change
The give-up is now bounded by elapsed time rather than attempt count, because the question that matters is how long a user's microphone may take to come back, not how many tries that happens to be under a given curve. Backoff climbs 1s, 2s, 4s … to a 30s ceiling across a five-minute window. A device that is merely busy gets picked up on its own; a device that is genuinely gone still ends in a bounded give-up rather than spinning.
reconfigurationRetryDelay(retryCount:elapsed:)is a pure static, so the policy is testable without the hardware — the same seam shape as the existingshouldRunDeferredReconfiguration.Deliberately not in scope
The terminal give-up is still silent. Making it visible means either keeping the device listener alive past it — which leaks, because
stopCapture()anddeinitboth skip listener cleanup whileisCapturingis false — or plumbing a real error to the UI. Both are larger than this fix and touch teardown paths carrying a documented crash hazard about ARC races with the HAL IO thread. This fixes the transient case, which is the reported one.Verification
dev-feedback.py --once swift 'AudioReconfigurationRetryPolicyTests|PTTAudioCaptureRaceTests'make preflightThe failing run names the defect directly: "six seconds is where the shipped policy gave up; a busy device is often not back yet."
Tests pin both directions — that it keeps trying well past six seconds, that it concedes once the window is spent, that backoff climbs to a ceiling and stays there, and that no attempt number yields a negative delay (which would schedule work in the past).
Not verified
Not reproduced on hardware: this Mac has no input that renegotiates its format, so the trigger cannot be produced here. The retry policy is proven at its seam; the CoreAudio path around it is unchanged. The diagnosis rests on the two listener registrations, the give-up branch, and the reporter's own device-dependence finding.
Failure-Class: none