Skip to content

Fix silent WASAPI capture startup hang - #1123

Merged
shanselman merged 1 commit into
mainfrom
shanselman-fix-audio-first-data-timeout
Aug 7, 2026
Merged

shanselman merged 1 commit into
mainfrom
shanselman-fix-audio-first-data-timeout

Conversation

@shanselman

Copy link
Copy Markdown
Collaborator

Closes #1097

Summary

  • add one generation-scoped, cancellable first-nonempty-audio deadline to AudioPipeline
  • stop and dispose a capture that opens but emits no audio, then use the existing Error state and localized actionable microphone diagnostic route
  • serialize Start, Stop, timeout, recording errors, disposal, and restart boundaries so late callbacks and stale watchdogs cannot revive or tear down a newer capture
  • retain existing RecordingStopped error behavior and keep bounded fixed-duration capture independent of the streaming startup watchdog
  • add an injectable capture seam and deterministic lifecycle/race tests

Validation

  • ./build.ps1 - passed
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore - 3,609 passed, 32 skipped
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore - 2,206 passed
  • dotnet test ./tests/OpenClaw.Tray.UITests/OpenClaw.Tray.UITests.csproj -r win-x64 --no-restore --filter FullyQualifiedName~AudioPipelineFirstAudioTimeoutTests - 13 passed
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore --filter FullyQualifiedName~SpeechInputContractTests - 5 passed
  • rubber-duck review - no blocking findings
  • python ./.agents/skills/autoreview/scripts/autoreview --mode local --stream-engine-output - clean, no accepted/actionable findings

Real behavior proof

Current head: a7407f6fed4b3e70dd59f9caef859a30aa6750c8

  • Deterministic silent-capture simulation opens successfully and emits no callbacks. After the first-audio deadline, the pipeline reaches Error, calls Stop and Dispose exactly once, surfaces the localized actionable microphone message, accepts Stop promptly, and ignores a deliberately invoked late callback.
  • Deterministic tests also prove healthy first audio cancels the deadline, Stop before timeout suppresses the error, restart cannot inherit an old watchdog, startup cancellation returns to Stopped, concurrent Stop/Dispose is idempotent, clean and error RecordingStopped paths remain bounded, and fixed-duration teardown cannot affect a restarted stream.
  • Supplemental production WASAPI stress used the real default microphone on a machine with four present input endpoints. The first of eight six-second runs reproduced the no-data path and reached Error; Stop recovered to Stopped. The next seven runs received audio, remained Listening, and stopped in 34-60 ms.
  • The isolated current-head Dev app launched with dedicated tray data and remained responsive while navigating Connection, Voice & Audio, and Permissions and toggling Node mode.

No permanent known-silent hardware endpoint was available. The one real no-data occurrence was transient; deterministic fake-capture coverage is the repeatable broken-device proof.

@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Aug 7, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 Urgent regression or broken agent/channel workflow affecting real users now. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 7, 2026
@clawsweeper

clawsweeper Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 7, 2026, 6:18 PM ET / 22:18 UTC.

ClawSweeper review

What this changes

The branch adds a generation-scoped timeout and coordinated cleanup around Windows WASAPI microphone capture so a capture that produces no audio transitions to an actionable error instead of remaining active indefinitely.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this collaborator-authored PR open for normal merge review. Its first-audio deadline directly addresses the current missing no-data path, but merge should wait for inspectable current-head evidence that real WASAPI recovery succeeds.

Priority: P1
Reviewed head: a7407f6fed4b3e70dd59f9caef859a30aa6750c8

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) PR readiness rating was derived from proof quality, review findings, security review, and reviewer confidence.
Proof confidence 🌊 off-meta tidepool Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 5 items Current main lacks a no-data deadline: Current main starts WasapiCapture and transitions to Listening after startup, with no first-audio timeout path.
PR implements guarded timeout cleanup: The PR head arms a first-audio watchdog and invalidates the capture generation before stopping and disposing the no-data capture.
Race coverage accompanies the lifecycle change: The added deterministic tests cover timeout cleanup, late callbacks, restart isolation, recording errors, concurrent stop/dispose, and fixed-duration capture boundaries.
Findings None None.
Security None None.

How this fits together

The Tray speech-input pipeline starts a Windows microphone capture, converts received samples, and feeds speech-to-text. This change governs the capture-start decision between proceeding to listening and releasing a no-data device with a visible diagnostic.

flowchart LR
  A[Voice record action] --> B[WASAPI capture startup]
  B --> C{First audio received?}
  C -->|Yes| D[Speech input pipeline]
  D --> E[Chat voice input]
  C -->|No by deadline| F[Stop and dispose capture]
  F --> G[Actionable microphone error]
Loading

Before merge

  • Resolve merge risk (P1) - Merging changes real capture teardown on an availability-sensitive path, but the PR body has no inspectable current-head WASAPI trace showing that StopRecording and Dispose recover from the no-data condition.
  • Complete next step (P2) - No safe automated repair is indicated: the remaining merge gate is contributor-provided, inspectable real-device proof and collaborator review.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test delta production +403, tests +404 The lifecycle refactor is substantial but is accompanied by roughly equal focused test growth.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #1097
Summary: This PR explicitly targets the reported WASAPI no-data capture failure.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Attach real WASAPI recovery evidence (recommended)
    Add a redacted current-head terminal trace, runtime log, or recording that shows the no-data timeout, error, and successful stop or restart before merge.

Technical review

Best possible solution:

Land the bounded watchdog only after a redacted current-head WASAPI run demonstrates no-data timeout, error visibility, and successful stop or restart recovery on the real capture boundary.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: current main starts capture and enters Listening without checking whether a first audio packet ever arrives. This read-only Linux review could not independently exercise a Windows WASAPI device.

Is this the best way to solve the issue?

Yes, a cancellable first-audio deadline with generation guards is a narrow maintainable repair for a capture that starts successfully but delivers no data, provided the real NAudio teardown path is evidenced before merge.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against f81c9fde0180.

Labels

Label changes:

  • add P1: Affected users can have the active voice-recording workflow become unresponsive when a microphone supplies no WASAPI data.
  • add merge-risk: 🚨 availability: The patch changes capture startup, stop, disposal, and error recovery, where an unproven real-device interaction could still leave voice input unavailable.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Label justifications:

  • P1: Affected users can have the active voice-recording workflow become unresponsive when a microphone supplies no WASAPI data.
  • merge-risk: 🚨 availability: The patch changes capture startup, stop, disposal, and error recovery, where an unproven real-device interaction could still leave voice input unavailable.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Evidence

What I checked:

Likely related people:

  • RBrid: Introduced the original audio capability that owns the microphone pipeline. (role: introduced audio capability; confidence: high; commits: b0ba9affa25d; files: src/OpenClaw.Tray.WinUI/Services/AudioPipeline.cs)
  • shanselman: Recent current-main history shows repeated contributions to the audio-pipeline file, in addition to this proposed repair. (role: recent area contributor; confidence: medium; commits: 05e87ffffe60; files: src/OpenClaw.Tray.WinUI/Services/AudioPipeline.cs)
  • christineyan4: Prior merged voice integration and speech-input test work connects the pipeline to its user-facing consumers. (role: voice UI and test contributor; confidence: medium; commits: cd4acf013e38, 99efc50cbc22; files: src/OpenClaw.Tray.WinUI/Services/VoiceService.cs, tests/OpenClaw.Tray.Tests/SpeechInputContractTests.cs)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@shanselman
shanselman merged commit 20d29e1 into main Aug 7, 2026
33 of 34 checks passed
@shanselman
shanselman deleted the shanselman-fix-audio-first-data-timeout branch August 7, 2026 22:43
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Voice recording freezes app (UI hang + 100% CPU) when WASAPI capture device delivers no data

1 participant