Skip to content

fix(hook_runner): v5.1.2 — wait for real clip length on Windows (#14)#15

Merged
ChanMeng666 merged 1 commit into
masterfrom
fix/windows-audio-truncation-14
Apr 20, 2026
Merged

fix(hook_runner): v5.1.2 — wait for real clip length on Windows (#14)#15
ChanMeng666 merged 1 commit into
masterfrom
fix/windows-audio-truncation-14

Conversation

@ChanMeng666
Copy link
Copy Markdown
Owner

Summary

  • Fixes #14 (reported by @Basdanucha): default permission-request.mp3 (~3.4 s) and elicitation.mp3 (~3.1 s) were always truncated on Windows because every PowerShell playback snippet hard-coded Start-Sleep -Seconds 3 before $player.Stop(); $player.Close().
  • All four sites in hooks/hook_runner.py (three fallback methods in play_audio_windows + the WSL path in play_audio_wsl) now poll the media player for the actual clip length and sleep for duration + 500 ms tail buffer. PresentationCore MediaPlayer uses $player.NaturalDuration.HasTimeSpan with a 1.5 s poll ceiling (Open() is async); WMPlayer.OCX uses $w.currentMedia.duration. Fallback Start-Sleep -Seconds 10 if the player never reports a duration — generous but bounded so the PowerShell host doesn't leak.
  • macOS (afplay) and Linux (mpg123/ffplay/paplay/aplay) are unaffected: those players block until playback completes by default.
  • Version bump 5.1.1 → 5.1.2 across every version-holding file; plugin copies synced via scripts/build-plugin.sh; CHANGELOG.md + CLAUDE.md Version-history row updated.

Why not the reporter's other options

  • Bump the constant — only moves the cliff. Any future voice > N seconds silently regresses.
  • Detach and fire-and-forgetMediaPlayer is hosted inside the PowerShell process; if PowerShell exits before playback completes, the player is disposed mid-clip. The Python subprocess.Popen layer was already fire-and-forget; this PR closes the gap that was inside the PowerShell command string.

Test plan

  • bash scripts/build-plugin.sh --check{"ok":true,"in_sync":true,"checked":60}
  • import hook_runner from both hooks/ and plugins/audio-hooks/hooks/ → both print 5.1.2
  • python bin/audio-hooks.py version | status | diagnose → valid JSON, "version":"5.1.2", errors:[], warnings:[]
  • python bin/audio-hooks.py test all{"ok":true,"passed":26,"failed":[],"total":26}
  • python bin/audio-hooks.py test permission_request → dispatches cleanly; logs tail --level error stays empty after playback
  • CI smoke workflow (Ubuntu / Windows / macOS × Python 3.9 / 3.12 / 3.13) — should stay green
  • Audible E2E (maintainer, Windows): audio-hooks test permission_request — confirm the ~0.4 s tail that used to be cut off is now audible; same for audio-hooks test elicitation

🤖 Generated with Claude Code

…t truncated (#14)

Every PowerShell playback snippet in play_audio_windows (three fallback
methods) and play_audio_wsl used a fixed Start-Sleep -Seconds 3 before
calling $player.Stop(); $player.Close(). The default
audio/default/permission-request.mp3 is ~3.4s (70,989 bytes, 128 kbps
after a 16 kB ID3v2 tag), so PowerShell tore the player down ~0.4s
early and the tail of the clip was always cut off on Windows. The
default elicitation.mp3 (~3.1s) was also clipped; subagent-start.mp3
and notification-urgent.mp3 were on the edge.

Fix: poll the media player for the real clip length, then sleep for
duration + 500ms tail buffer before Stop()/Close().

- PresentationCore MediaPlayer (Methods 1 & 2 and the WSL path):
  MediaPlayer.Open() is async, so we poll
  $player.NaturalDuration.HasTimeSpan with a 1.5s ceiling, then
  Start-Sleep -Milliseconds ([int]($player.NaturalDuration.TimeSpan.TotalMilliseconds + 500)).
- WMPlayer.OCX (Method 3): same pattern on $w.currentMedia.duration.
- Fallback when the player never reports a duration (corrupt file, etc.):
  Start-Sleep -Seconds 10 — generous enough to cover any plausible
  default clip, still bounded so the PowerShell host process does not
  leak.

The Python subprocess layer was already fire-and-forget
(subprocess.Popen); the fix closes the gap that was inside the
PowerShell command string itself. macOS afplay and Linux
mpg123/ffplay/paplay/aplay are unaffected: those players block until
playback completes by default.

Version bump to 5.1.2 across the usual version-holding files:
- hooks/hook_runner.py (HOOK_RUNNER_VERSION)
- bin/audio-hooks.py (PROJECT_VERSION)
- .claude-plugin/marketplace.json (metadata + plugin entry)
- plugins/audio-hooks/.claude-plugin/plugin.json
- config/default_preferences.json (_comment + _version + version)
- CLAUDE.md header + Version history row
- README.md version badge + sequence diagram + status line example
- docs/ARCHITECTURE.md status line example
- plugins/audio-hooks/skills/audio-hooks/SKILL.md status line example

CHANGELOG.md gets a 5.1.2 entry. Plugin copies synced via
scripts/build-plugin.sh; scripts/build-plugin.sh --check reports
in_sync:true.

Fixes #14

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 20, 2026 10:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Windows/WSL audio clips being truncated by replacing fixed PowerShell Start-Sleep delays with duration-aware waits, and bumps the project/plugin version to 5.1.2 across canonical + synced plugin copies.

Changes:

  • Update Windows/WSL PowerShell playback snippets to poll for real media duration and sleep for duration + 500ms (with bounded fallback).
  • Bump version strings to 5.1.2 across CLI, hook runner, plugin manifests, and default config templates.
  • Refresh documentation/examples (README/ARCHITECTURE/CLAUDE/CHANGELOG/SKILL) to reflect v5.1.2.

Reviewed changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
plugins/audio-hooks/skills/audio-hooks/SKILL.md Updates status line example version to v5.1.2.
plugins/audio-hooks/hooks/hook_runner.py Windows/WSL playback now waits for actual clip length (synced plugin copy).
plugins/audio-hooks/config/default_preferences.json Bumps default config template version fields to 5.1.2.
plugins/audio-hooks/bin/audio-hooks.py Bumps CLI PROJECT_VERSION to 5.1.2 (synced plugin copy).
plugins/audio-hooks/.claude-plugin/plugin.json Bumps plugin manifest version to 5.1.2.
hooks/hook_runner.py Windows/WSL playback now waits for actual clip length (canonical source).
docs/ARCHITECTURE.md Updates status line example version to v5.1.2.
config/default_preferences.json Bumps default config template version fields to 5.1.2 (canonical).
bin/audio-hooks.py Bumps CLI PROJECT_VERSION to 5.1.2 (canonical).
README.md Updates badge + examples to v5.1.2.
CLAUDE.md Updates header/version history with the Windows truncation fix entry.
CHANGELOG.md Adds 5.1.2 release notes describing the Windows/WSL playback fix.
.claude-plugin/marketplace.json Bumps marketplace/plugin listing versions to 5.1.2.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ChanMeng666 ChanMeng666 merged commit eee6b11 into master Apr 20, 2026
15 checks passed
@ChanMeng666 ChanMeng666 deleted the fix/windows-audio-truncation-14 branch April 20, 2026 10:10
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.

Default permission-request.mp3 (3.4s) is clipped by fixed Start-Sleep -Seconds 3

2 participants