Skip to content

fix(audio): keep the chime's context running during a run (#1157) - #1185

Merged
agegr merged 1 commit into
mainfrom
fix/1157-keep-audio-during-run
Oct 11, 2026
Merged

agegr merged 1 commit into
mainfrom
fix/1157-keep-audio-during-run

Conversation

@agegr

@agegr agegr commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Follow-up to #1178 (#1157), based on @1tazura's device check on Firefox 153 for Android 14.

Problem

#1178 suspends the chime's AudioContext between chimes. That released the AudioMix wake lock and the AAudio stream while idle, as intended. However, a run that finished while the phone was locked no longer chimed: Firefox left the resume() of the suspended context pending, and no oscillators were scheduled. v0.10.0's always-running context did chime there.

Change

  • useAudio gets holdAudio(), which returns a release function. While any hold is outstanding, the idle suspend is skipped and a suspended context is resumed. Releasing the last hold suspends it AUDIO_IDLE_SUSPEND_MS later.
  • ChatWindow holds the context while its session's agentRunning is true. The hold is released when the run ends or the window unmounts. The output stream is therefore open during a run, when a chime can come, and closed between runs, which was the original complaint.
  • Sessions in other workspaces get no hold. Their chime comes from the sidebar's running poll, which stops while the page is hidden, so they never chimed on a locked phone anyway.
  • A chime whose resume() took longer than AUDIO_STALE_CHIME_MS (3 s) is dropped. Otherwise, a resume that was held back would play the chime when the user comes back. This also covers a chime requested before the page's first gesture, which used to play at the next click.
  • Sound off still suspends at once, even while held.
  • The demo/ copy of the hook is mirrored, and docs/agents/client-platform.md has one added line.

Verification

  • Four new tests in hooks/useAudio.test.mjs (12 in total), all of which fail against main:
    • a hold survives the chime's idle timer, and the context suspends once after the release;
    • two holds;
    • a hold while sound is off, then sound on and off;
    • a stale chime is dropped, while one within the limit plays.
  • tsc --noEmit, eslint and npm test pass (2606 passed, 1 skipped).
  • node e2e/run.mjs: 27/27 on the second run. The first run failed at the known flaky "Hide sidebar" step (run.mjs:493).
  • Not verified on a device. I couldn't confirm the locked-phone chime myself. The stream now stays open for as long as a run takes, which costs battery while the run is under way.

🤖 Generated with Claude Code

Device feedback on #1178 (Firefox 153, Android 14): with the context
suspended between chimes, a run that finished while the phone was locked
never chimed, since Firefox leaves the resume() of a suspended context
pending there. ChatWindow now holds the context running while its
session's run is under way (holdAudio(), released when the run ends or
the window unmounts), so the output stream stays open during a run but
not between runs. A chime whose resume() took longer than 3 s is dropped
instead of playing late when the user comes back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr
agegr merged commit d1529d0 into main Oct 11, 2026
4 checks passed
@agegr
agegr deleted the fix/1157-keep-audio-during-run branch October 29, 2026 13:01
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
agegr#1185)

Device feedback on agegr#1178 (Firefox 153, Android 14): with the context
suspended between chimes, a run that finished while the phone was locked
never chimed, since Firefox leaves the resume() of a suspended context
pending there. ChatWindow now holds the context running while its
session's run is under way (holdAudio(), released when the run ends or
the window unmounts), so the output stream stays open during a run but
not between runs. A chime whose resume() took longer than 3 s is dropped
instead of playing late when the user comes back.

Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
agegr#1185)

Device feedback on agegr#1178 (Firefox 153, Android 14): with the context
suspended between chimes, a run that finished while the phone was locked
never chimed, since Firefox leaves the resume() of a suspended context
pending there. ChatWindow now holds the context running while its
session's run is under way (holdAudio(), released when the run ends or
the window unmounts), so the output stream stays open during a run but
not between runs. A chime whose resume() took longer than 3 s is dropped
instead of playing late when the user comes back.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant