Skip to content

fix(android): stop interrupted assistant audio and remove cached files - #129574

Merged
steipete merged 1 commit into
mainfrom
codex/android-audio-cancel
Aug 25, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/android-audio-cancel

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Interrupting a compressed assistant-audio reply cancelled its playback coroutine before either cleanup dispatcher could run. The Android MediaPlayer could continue playing without being released, and the reply's audio bytes remained in a private app-cache file. Cancellation while handing a newly created file back from the I/O dispatcher, or an exception during player setup, also lost the corresponding resource before its existing cleanup scope began.

Why This Change Was Made

Give the existing playback owner immediate ownership of each temporary file and MediaPlayer as soon as it is allocated. Keep the existing player teardown on Android's main dispatcher and file deletion on the I/O dispatcher, but make both cleanup sections non-cancellable. Nested ownership preserves file deletion even if player teardown fails, while keeping active-playback registration, replacement, formats, and public behavior unchanged.

Production delta: +53/-43 (net +10), justified by the four independently reproduced resource-lifetime gaps. Regression coverage: +171 test lines. No new dependency, permission, configuration, fallback, or product policy.

User Impact

Interrupted Android assistant replies stop playing immediately and do not leave their speech audio cached on disk. Failed player initialization and cancellation during audio-file creation also release their resources reliably.

Evidence

  • Before the fix, the unchanged owner failed four focused regressions while three existing format controls passed: an active player remained STARTED, its private speech file remained on disk, cancellation before the file-creation dispatcher returned orphaned a second file, and a player whose initialization failed remained IDLE instead of reaching released END.
  • After the fix, 70 focused owner and caller tests passed: 7 audio-owner tests, 56 Talk-mode tests, and 7 message-speech tests. ShadowMediaPlayer.State.END directly proves that MediaPlayer.release() ran.
  • All four Android Kotlin formatting modules passed: app, benchmark, wear, and wear-shared.
  • Real Android API 36 played a task-generated, valid RIFF/WAV sample through the production TalkAudioPlayer and a real platform MediaPlayer, confirmed active speech playback through AudioManager, and confirmed creation of the actual private app-cache audio file.
  • Before the fix: the Android instrumentation runner passed (OK (1 test)) while proving that cancelling real playback left activePlayers=1 and the actual 384,044-byte private WAV in orphanFiles.
  • After the fix: the identical instrumentation command exited successfully and the real Android owner emitted TALK_AUDIO_CANCELLED expectedLeak=false activePlayers=0 initialPlayers=0 orphanFiles=[] after cancellation.
  • AudioManager proves that real playback stopped; the owner-level END regression independently proves the stronger player-release contract. Test audio was synthetic and all task-created cache files were removed.

@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 25, 2026 19:33
@openclaw-barnacle openclaw-barnacle Bot added app: android App: android size: M maintainer Maintainer-authored PR labels Aug 25, 2026
@steipete
steipete merged commit 52bce84 into main Aug 25, 2026
107 of 115 checks passed
@steipete
steipete deleted the codex/android-audio-cancel branch August 25, 2026 21:07
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

app: android App: android maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant