Skip to content

fix(audio): bound Piper tar extract WaitForExit - #1268

Closed
SebTardif wants to merge 1 commit into
openclaw:mainfrom
SebTardif:fix/f003-piper-tar-timeout
Closed

SebTardif wants to merge 1 commit into
openclaw:mainfrom
SebTardif:fix/f003-piper-tar-timeout

Conversation

@SebTardif

@SebTardif SebTardif commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users downloading a Piper voice from Voice Settings would freeze the Settings window when tar -xjf hung or filled its redirected stderr pipe. Extract used unbounded WaitForExit() after the download finished, so the 2 second tar --version probe did not protect this path. Settings then sat on the extract step until the child exited or the operator killed the app.

A first-round bound still left cancellation waiting on a post-exit stderr drain if a descendant kept the pipe open. Voice Settings cancels the prior Piper request before starting a new download, so that drain could still stall the UI.

Why This Change Was Made

Piper extract now waits for process exit plus complete stdout and stderr drain on one linked caller and timeout deadline. Timeout or cancel starts process-tree termination, closes local readers that inherited handles can hold, and bounds cleanup to one second. A timed-out extract fails closed and the existing download cleanup still deletes the partial voice directory. This does not change the SHA-256 check, the catalog, or the tar --version preflight.

User Impact

Operators can download a Piper voice without Voice Settings hanging when the OS tar child sticks. A timeout surfaces as a failed extract so they can retry. Cancel still stops the child instead of leaving tar running, including when a descendant still holds redirected pipes.

Evidence

Current-head BoundedProcessWait.WaitAsync against the inherit-handles fixture: the parent exits, a child keeps both redirected pipes, then cancel returns in 3ms instead of waiting the 120s extract budget.

$ cd /tmp/wn-1268-head-proof && dotnet run
current_head_helper=OpenClaw.Shared.Audio.BoundedProcessWait
parent_exited=True
wait_completed_before_cancel=False
wait_status=canceled
elapsed_ms=3
child_pid=71189

Piper extract now calls BoundedProcessWait.WaitAsync from ExtractTarBz2Async instead of unbounded WaitForExit() plus blocking StandardError.ReadToEnd().

Change Type

  • Bug fix

Scope

  • Tray or WinUI UX

Required proof pools

  • none: the hang is the Voice Settings Piper tar extract wait. A hung child plus the current-head helper is enough. No installer, WSL, or interactive WinUI host is required.

Validation

  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --filter FullyQualifiedName~BoundedProcessWaitTests|FullyQualifiedName~PiperVoiceExtractionTests
  • 10 passed, 0 failed (Windows tar.exe extract case returns on non-Windows)
  • Current-head inherit-handle cancel: elapsed_ms=3
  • dotnet format on the changed helper, Piper extract, TestHost fixture, and tests
  • WinUI project and ./build.ps1 were not run on this macOS host

Real behavior proof

  • Behavior or issue addressed: Voice Settings Piper download extract blocked forever on unbounded WaitForExit() with stderr redirected. After the first bound, cancel could still wait on a descendant-held drain.

  • Real environment tested: macOS 26.6.2, Darwin, .NET 10.0.400, branch fix/f003-piper-tar-timeout replayed onto origin/main 09bc834, invoked with dotnet run from /tmp/wn-1268-head-proof against current-head BoundedProcessWait.

  • Exact steps or command run after this patch:

    cd /tmp/wn-1268-head-proof
    dotnet run
  • Evidence after fix: terminal output from the current-head helper:

    current_head_helper=OpenClaw.Shared.Audio.BoundedProcessWait
    parent_exited=True
    wait_completed_before_cancel=False
    wait_status=canceled
    elapsed_ms=3
  • Observed result after fix: After the fixture parent exited, WaitAsync was still pending on inherited pipes. Cancel returned in 3ms and did not consume the 120s extract budget.

  • What was not tested: Interactive Voice Settings download on a Windows host against a real hung tar.exe.

Security Impact

  • New permissions or capabilities? (No)
  • Secrets or tokens handling changed? (No)
  • New or changed network calls? (No)
  • Command or tool execution surface changed? (No)
  • Data access scope changed? (No)

Extract still launches the same OS tar -xjf command on the already hashed tarball. Only the wait, stream drain, and kill-on-timeout behavior changed.

Compatibility and Migration

  • Backward compatible? (Yes)
  • Config or environment changes? (No)
  • Migration needed? (No)

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

Related

  • Introduced in #288 (2026-05-07). The unbounded extract wait has been present for 118 days.
  • Same hang class as #1168 (bounded drain after WaitForExit) and #1267 (Tailscale status ReadToEnd before WaitForExit).
  • This remains the first PR for F003. It now includes the Claw P2 drain-cancel repair (interrupt readers after the immediate process exits).

@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Codex review: blocked before merge. Reviewed September 3, 2026, 12:52 AM ET / 04:52 UTC.

ClawSweeper review

What this changes

The branch makes Piper voice extraction await tar process exit and redirected output under one timeout, with bounded cleanup on cancellation or timeout.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open. The branch removes the unbounded wait, but its cancellation path returns after a post-exit descendant survives, allowing Piper cleanup to race an extractor that is still running.

Priority: P2
Reviewed head: cf75bc688bb17722801d484cd22d638755b40472

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The branch has direct current-head process-lifecycle proof and broad focused coverage, but the cancellation cleanup leaves a concrete child-lifecycle defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body provides a current-head terminal trace of the changed BoundedProcessWait production helper against a real parent/descendant inherited-pipe scenario, observing cancellation in 3 ms after the parent exits. That proves the intended no-hang recovery, though it does not prove termination of the surviving descendant identified in the finding.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides a current-head terminal trace of the changed BoundedProcessWait production helper against a real parent/descendant inherited-pipe scenario, observing cancellation in 3 ms after the parent exits. That proves the intended no-hang recovery, though it does not prove termination of the surviving descendant identified in the finding.
Evidence reviewed 6 items Post-exit descendants are not terminated: The introduced cleanup explicitly skips Process.Kill when the tracked tar parent has already exited. Closing the readers releases the blocked wait, but cannot stop that surviving descendant.
Regression fixture confirms separate child cleanup: The inherited-handle fixture records the child PID, then the test itself calls KillProcessTree in finally after WaitAsync has returned. It does not establish that the helper terminates the child.
Cancellation now races partial-directory cleanup: After ExtractTarBz2Async returns cancellation, DownloadVoiceCoreAsync immediately attempts to delete the voice directory. A surviving extraction descendant can still hold or create files there.
Findings 1 actionable finding [P2] Terminate the post-exit extractor descendant
Security None None.

How this fits together

Voice Settings downloads and hash-validates a Piper voice archive, then invokes the operating system tar extractor into the local voice directory. Extraction completion controls whether the UI reports success, cancellation, or a retryable failure and cleanup.

flowchart LR
  A[Voice Settings download] --> B[Hash-verified Piper archive]
  B --> C[Tar extraction process]
  C --> D[Bounded exit and pipe wait]
  D --> E{Completed or cancelled}
  E -->|Completed| F[Verify voice files]
  E -->|Cancelled or timed out| G[Stop extraction and clean partial files]
  F --> H[Voice ready]
  G --> I[Retryable failure]
Loading

Before merge

  • Terminate the post-exit extractor descendant (P2) - When the parent has already exited, this guard skips the only tree kill. The inherited-pipe test then kills that child itself, while Piper immediately deletes the voice directory after cancellation. Keep the extractor in a lifecycle owner that can stop descendants after the parent exits, and assert that child termination before returning.
  • Resolve merge risk (P1) - A tar descendant that outlives its parent can continue running after cancellation and race deletion of the partial voice directory, leaving files locked or recreated after the UI reports cancellation.
  • Complete next step (P2) - Before merge, ensure cancellation terminates an extractor descendant that outlives its parent, and add a regression assertion that it is gone before Piper cleans partial files.

Findings

  • [P2] Terminate the post-exit extractor descendant — src/OpenClaw.Shared/Audio/BoundedProcessWait.cs:98-101
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test delta production +194/-11, tests +514 The lifecycle helper is substantially covered, but the inherited-handle test currently cleans up the child outside the production helper.

Merge-risk options

Maintainer options:

  1. Own and terminate post-exit descendants (recommended)
    Assign the extractor to a lifecycle mechanism that remains able to terminate descendants after the immediate tar process exits, then assert the inherited-pipe child is gone before returning.
  2. Accept the orphan-process tradeoff
    Land the bounded UI cancellation behavior while explicitly accepting that an already-detached extractor descendant may continue and interfere with partial-file cleanup.

Technical review

Best possible solution:

Make extraction own the complete child-process lifecycle, such as a Windows kill-on-close job assigned immediately after tar starts, and prove the post-exit descendant is gone before partial-voice cleanup proceeds.

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

Yes. The introduced inherited-handle fixture creates a parent that exits while a child retains the redirected pipes, and the source shows the helper returns without terminating that child.

Is this the best way to solve the issue?

No. Sharing a deadline fixes the blocked wait, but the cleanup deliberately cannot terminate a descendant after the parent exits; lifecycle ownership must persist until every descendant is stopped.

Full review comments:

  • [P2] Terminate the post-exit extractor descendant — src/OpenClaw.Shared/Audio/BoundedProcessWait.cs:98-101
    When the parent has already exited, this guard skips the only tree kill. The inherited-pipe test then kills that child itself, while Piper immediately deletes the voice directory after cancellation. Keep the extractor in a lifecycle owner that can stop descendants after the parent exits, and assert that child termination before returning.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a current-head terminal trace of the changed BoundedProcessWait production helper against a real parent/descendant inherited-pipe scenario, observing cancellation in 3 ms after the parent exits. That proves the intended no-hang recovery, though it does not prove termination of the surviving descendant identified in the finding.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body provides a current-head terminal trace of the changed BoundedProcessWait production helper against a real parent/descendant inherited-pipe scenario, observing cancellation in 3 ms after the parent exits. That proves the intended no-hang recovery, though it does not prove termination of the surviving descendant identified in the finding.
  • remove status: 📣 needs proof: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P2: Cancellation avoids the reported Settings hang, but a surviving extractor descendant can still interfere with retry and cleanup.
  • merge-risk: 🚨 availability: The changed timeout and cancellation path can leave a child process running after the UI resumes.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body provides a current-head terminal trace of the changed BoundedProcessWait production helper against a real parent/descendant inherited-pipe scenario, observing cancellation in 3 ms after the parent exits. That proves the intended no-hang recovery, though it does not prove termination of the surviving descendant identified in the finding.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a current-head terminal trace of the changed BoundedProcessWait production helper against a real parent/descendant inherited-pipe scenario, observing cancellation in 3 ms after the parent exits. That proves the intended no-hang recovery, though it does not prove termination of the surviving descendant identified in the finding.

Evidence

What I checked:

Likely related people:

  • Régis Brid: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • shanselman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Ensure the post-exit descendant is terminated before extraction cancellation returns and before partial-directory cleanup.
  • Add a regression assertion that the inherited-pipe child PID no longer exists after cancellation.
  • Post a redacted current-head Windows trace covering the repaired descendant lifecycle and tar extraction boundary.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-29T18:58:00.298Z sha 40f3502 :: needs real behavior proof before merge. :: [P2] Interrupt the stderr drain on cancellation

@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 2, 2026
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 2, 2026
@shanselman

Copy link
Copy Markdown
Collaborator

Maintainer repair is now in #1294 because this PR's contributor-fork head is not writable. Replacement head: 36e6994. It merges current origin/main, unifies the extraction deadline across exit and both drains, bounds cleanup, adds deterministic lifecycle coverage, and includes native Windows ar.exe proof. Neither PR was merged.

Voice Settings Piper download extract called WaitForExit() with
stderr redirected and no timeout. A hung tar child or a full
stderr pipe blocked the UI until the process exited.

Wait for exit and both redirected drains on one deadline. Kill
the process tree, close local readers, and bound cleanup on
timeout or cancel so a descendant-held pipe cannot stall Settings.

Signed-off-by: Sebastien Tardif <[email protected]>
@SebTardif
SebTardif force-pushed the fix/f003-piper-tar-timeout branch from 40f3502 to cf75bc6 Compare September 2, 2026 23:51
@SebTardif

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Claw P2 on 40f35021: cancel only killed the tree and could still wait on a post-exit stderr drain. Current head cf75bc68 waits for exit plus both drains on one deadline, closes local readers, and bounds cleanup. Inherit-handle cancel now returns in 3ms against current-head BoundedProcessWait.

@SebTardif

Copy link
Copy Markdown
Contributor Author

@shanselman

Maintainer repair is now in #1294 because this PR's contributor-fork head is not writable.

This PR is still the first F003 extract-timeout fix (opened 2026-08-29). The fork head is writable by the author and is now replayed onto current main (cf75bc68): one deadline for exit plus both drains, reader dispose on cancel, inherited-handle coverage, and current-head helper proof. Please review here rather than treating #1294 as a replacement.

@clawsweeper

clawsweeper Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 3, 2026
@SebTardif

Copy link
Copy Markdown
Contributor Author

Superseded on current main.

#1294 landed BoundedProcessWait (1d32722c) for the Piper extract deadline. The file is on origin/main. Closing this older fork head instead of replaying it.

@SebTardif

Copy link
Copy Markdown
Contributor Author

Superseded by #1294 on main.

@SebTardif SebTardif closed this Sep 7, 2026
@SebTardif
SebTardif deleted the fix/f003-piper-tar-timeout branch September 24, 2026 00:50
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. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants