Skip to content

fix(audio): stop canceled voice extraction leaving its process running - #1645

Merged
shanselman merged 3 commits into
mainfrom
shanselman-fix-bounded-process-cleanup
Oct 6, 2026
Merged

shanselman merged 3 commits into
mainfrom
shanselman-fix-bounded-process-cleanup

Conversation

@shanselman

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: a canceled or timed-out Piper voice extraction can leave its extractor running when the cleanup worker runs after the caller has disposed its Process.

User Impact

Cancellation still returns promptly, but a delayed termination worker retains the process it needs to stop. Successful extraction and redirected output behavior are unchanged. Tree termination remains best effort, not an unconditional OS-level guarantee.

Why This Change Was Made

BoundedProcessWait now owns disposal, including after a delayed kill task finishes. Piper no longer disposes the supplied process on bounded return. This follows the existing MXC worker/caller-release ownership pattern without modifying MXC or introducing a PID-only kill target. The architecture ledger documents the new owner and preserved invariant: the caller deadline does not end the kill worker's process lifetime.

The internal scheduler seam holds the real kill worker in tests until after cancellation/timeout returns. Tests then verify the process is still owned, release the actual killer, and verify exit and disposal. The 1-second cleanup budget and existing 3-second cancellation assertions are unchanged.

Evidence

Native Windows ARM64, .NET SDK 10.0.401. No voice/model download; tests use OpenClaw.Shared.TestHost and local Windows tar.

Experiment Passed Failed Skipped Failure classification
Original b1a41be1, isolated Piper cancellation, 2 CPUs, 10 repetitions 8 2 0 Extractor still running (PIDs 51180 and 13708)
Initial implementation 8e113c86, same original test, 10 repetitions 9 1 0 PID-publication precondition timeout, before cancellation
Initial implementation, focused 12-test set, 10 repetitions 118 2 0 One PID-publication precondition timeout; one new regression stopwatch failure (3629ms, measurement included synchronous wait setup)
Final 39732636, original test, 10 repetitions 10 0 0 None
Final 39732636, focused 12-test set, 10 repetitions 120 0 0 None

Earlier precondition failures are not counted as cleanup passes. No after-change repetition failed the still-running-extractor assertion. The new stopwatch now starts at cancellation, matching the existing cancellation test; its 3-second threshold is unchanged. A separate 5-second test watchdog prevents a future unbounded regression from hanging the held-worker fixture.

Other development evidence, retained rather than hidden
  • Fresh unmodified normal-scheduling Piper baseline: 1 passed.
  • Initial regression fixture: 10 passed, 2 failed while waiting for Process.Disposed; corrected to observe actual Dispose(bool) via a real Process subclass, then 12 passed.
  • Temporarily reintroducing premature Dispose() made both deterministic lifetime cases fail at the not-disposed assertion (0 passed, 2 expected failures). Mutation removed; production code is unchanged since 8e113c86.
  • Stopwatch-corrected focused run: 12 passed, 0 failed/skipped.
  • Full build/Shared/Tray floor also passed at both intermediate commits; final floor below was rerun after the last test edit.

Change Type

  • Bug fix
  • Tests or validation

Scope

  • Tests, CI, or docs
  • Shared audio extraction process lifetime only. No workflow, UI readiness, credential, or CI policy changes.

Required proof pools

  • none: no specialized containment, gateway, installer, architecture-specific implementation, or interactive UI behavior changed. Real child-process proof runs in the ordinary Shared suite; local ARM64 execution does not substitute for hosted x64 CI.

Validation

Frozen head: 3973263666f3606d508e98f785721f4a1573ffc3
Tree: 7b3deb2ef7790e6ff74784064b63eaf9b2a625a2

Set $env:OPENCLAW_REPO_ROOT to this isolated worktree and $env:OPENCLAW_TRAY_DATA_DIR to a task-local directory. Fresh test projects were restored/built before --no-restore use.

Command Final result
.\build.ps1 All 5 product builds passed
dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore 4234 passed, 0 failed, 36 skipped
dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore 3899 passed, 0 failed, 0 skipped

Focused repeats set $env:DOTNET_PROCESSOR_COUNT='2' and run:

dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-build --no-restore --filter 'FullyQualifiedName~PiperVoiceExtractionTests.ExtractTarBz2Async_CancellationIsBoundedAndKillsExtractor'
dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-build --no-restore --filter 'FullyQualifiedName~BoundedProcessWaitTests|FullyQualifiedName~PiperVoiceExtractionTests'

Each command ran 10 times on final head; 130 total tests passed, zero failures/skips.

Concurrency review

Both app-native rubber-duck reviewers reviewed the pinned production diff and subsequent test-only deltas. Actual runtime metadata: claude-opus-5.5 (high) and gpt-6-astra (high, long_context).

Issue Opus 5.5 GPT-6 Astra Fix confidence
Final actionable findings None None N/A

Real Behavior Proof

  • Environment tested: native Windows ARM64, isolated test data, real local fixture processes.
  • PR head tested: 3973263666f3606d508e98f785721f4a1573ffc3.
  • Exact commands: focused commands above, 10 repetitions each at 2 CPUs.
  • Evidence after fix, copied final run output:
final=piper repetition=1 exit=0
[repetitions 2 through 9 also exit=0]
final=piper repetition=10 exit=0
final=focused repetition=1 exit=0
[repetitions 2 through 9 also exit=0]
final=focused repetition=10 exit=0
  • Observed result: original cancellation tests prove bounded return and actual extractor termination. Held-worker tests separately prove cancellation and timeout return before the killer is released, followed by real process exit and disposal. Success/late output/inherited pipe cases also pass.
  • Screenshot or artifact links verified? N/A. Copied evidence is inline; local TRX/logs and hashed proof inventory retained for maintainer handoff.
  • Not verified or blocked: hosted x64 CI pending at publication; no downloaded voice/end-to-end UI smoke claimed. Existing 36 Shared skips remain skips. PID-publication failures from the intermediate experiment are a distinct unresolved readiness limitation, not repaired by this PR. No scheduler/antivirus root-cause claim.

Security Impact

No new permissions, secrets handling, network calls, command exposure, or data access scope. The existing extractor's process object is retained for its existing termination operation.

Compatibility and Migration

No configuration changes or migration. Internal ownership contract updated at every BoundedProcessWait caller.

Review Conversations

  • Pre-publication local review findings addressed and verified.
  • Hosted bot review conversations checked before protected landing.

shanselman and others added 3 commits October 5, 2026 21:52
Keep Process disposal with BoundedProcessWait until its asynchronous tree-kill worker finishes, while retaining the caller cleanup deadline and redirected-output drain behavior. Cover delayed worker cancellation and timeout with deterministic real-process tests.

Co-authored-by: Copilot App <[email protected]>
Start the delayed-worker regression stopwatch at the cancellation boundary, matching the existing cancellation test. Preserve the three-second bound and held-worker assertions.

Co-authored-by: Copilot App <[email protected]>
Keep a five-second test watchdog around the held-worker wait so a future unbounded cleanup regression fails and releases the fixture instead of hanging the suite. The three-second product assertion is unchanged.

Co-authored-by: Copilot App <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Oct 6, 2026
@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 1:15 AM ET / 05:15 UTC.

ClawSweeper review

What this changes

The PR keeps canceled voice-extraction processes owned by the cleanup worker until termination finishes, with regression coverage for delayed cleanup.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main and the latest release retain the premature-disposal race. The focused repair has convincing native process evidence and no blocking findings.

Priority: P2
Reviewed head: 3973263666f3606d508e98f785721f4a1573ffc3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused ownership repair with deterministic real-process coverage and repeated native validation supports normal landing review.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Captured Windows ARM64 runs exercise PiperVoiceManager extraction cancellation and BoundedProcessWait with real child processes. Held-worker scenarios observe bounded return, retained ownership, then actual exit and disposal; 130 final-head focused cases passed. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Captured Windows ARM64 runs exercise PiperVoiceManager extraction cancellation and BoundedProcessWait with real child processes. Held-worker scenarios observe bounded return, retained ownership, then actual exit and disposal; 130 final-head focused cases passed. No stored-data contract changes.
Evidence reviewed 8 items Pinned introduced change: The complete introduced diff transfers disposal to BoundedProcessWait and removes caller disposal from Piper and the archive fixture. All WaitAsync callers were checked.
Still necessary on main: Main still wraps the extractor in using while cleanup can return after one second with the kill task unfinished, allowing disposal before that worker uses the process.
Latest release comparison: The v2026.9.4 waiter also schedules termination and returns after bounded cleanup without retaining disposal ownership; the release does not contain this repair.
Findings None None.
Security None None.

How this fits together

Piper voice installation starts a local extractor and waits for its exit and redirected output. The shared process waiter handles cancellation and timeout cleanup before installation reports success or failure.

flowchart TD
 A[Voice installation] --> B[Local extractor]
 B --> C[Wait for exit and output]
 C --> D{Completed within deadline?}
 D -->|Yes| E[Return extraction result]
 D -->|No| F[Bounded cleanup return]
 F --> G[Delayed worker terminates process]
 G --> H[Dispose process]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test growth production +62/-31; tests +110/-14; docs +1 Production growth establishes deferred disposal ownership, supported by two deterministic delayed-worker scenarios.

Technical review

Best possible solution:

Keep one process-lifetime owner that preserves bounded cancellation while retaining the original process object until its termination worker finishes.

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

Yes. Main permits caller disposal while its kill worker is delayed beyond the cleanup deadline; the supplied baseline native runs also report two surviving extractors. This reviewer did not execute a reproduction.

Is this the best way to solve the issue?

Yes. Transferring disposal to the existing waiter repairs the lifetime race without weakening the deadline or introducing a separate PID-based termination target.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b1a41be1b8ae.

Labels

Label changes:

  • add P2: This fixes a bounded voice-installation cleanup race without changing broader startup or command execution behavior.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Captured Windows ARM64 runs exercise PiperVoiceManager extraction cancellation and BoundedProcessWait with real child processes. Held-worker scenarios observe bounded return, retained ownership, then actual exit and disposal; 130 final-head focused cases passed. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Captured Windows ARM64 runs exercise PiperVoiceManager extraction cancellation and BoundedProcessWait with real child processes. Held-worker scenarios observe bounded return, retained ownership, then actual exit and disposal; 130 final-head focused cases passed. No stored-data contract changes.

Label justifications:

  • P2: This fixes a bounded voice-installation cleanup race without changing broader startup or command execution behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Captured Windows ARM64 runs exercise PiperVoiceManager extraction cancellation and BoundedProcessWait with real child processes. Held-worker scenarios observe bounded return, retained ownership, then actual exit and disposal; 130 final-head focused cases passed. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured Windows ARM64 runs exercise PiperVoiceManager extraction cancellation and BoundedProcessWait with real child processes. Held-worker scenarios observe bounded return, retained ownership, then actual exit and disposal; 130 final-head focused cases passed. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Scott Hanselman: Raw commit 1d32722 adds src/OpenClaw.Shared/Audio/BoundedProcessWait.cs:99 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1d32722cada4; files: src/OpenClaw.Shared/Audio/BoundedProcessWait.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 e23f43a into main Oct 6, 2026
29 checks passed
@shanselman
shanselman deleted the shanselman-fix-bounded-process-cleanup branch October 6, 2026 05:32
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Oct 6, 2026
@shanselman

Copy link
Copy Markdown
Collaborator Author

Landing receipt: merged through normal protected squash merge at e23f43a from exact reviewed/tested head 3973263. Build and Test run 37417483804 succeeded on attempt 1; required CI Gate job 112123759322 passed. No reruns, force push, or admin bypass. Hosted x64 CI is now verified, superseding the publication-time pending note. Final posted ClawSweeper review had no findings; both pinned local dual-model reviews were clean. Active-landing label removed. Original baseline and intermediate failure distinctions remain in the PR body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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.

1 participant