[GH-ISSUE #2749] [Issue]: Notification ping is silently broken — AudioContext created suspended and never resumed (no webkit fallback) #1388

Closed
opened 2026-10-21 05:32:48 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2749

Originally assigned to: @SpicyMarinara on GitHub.

Summary

notification-sound.ts lazily constructs a module-level singleton AudioContext and never checks ctx.state/calls ctx.resume(). The very first real ping originates from a non-gesture event (incoming streamed message), so per browser autoplay policy the context is created suspended; its currentTime does not advance, oscillators scheduled at now/now+0.25 never render, and because the context is a singleton that is never resumed it stays suspended for the page lifetime. The sibling game-audio.ts does the correct if (state === 'suspended') void resume(), proving the intended pattern is simply absent here.

Sub-bug 1: Permanently-silent ping (#14)

  • How it breaks: getAudioContext() (lines 7-12) does new AudioContext() with no state check; playNotificationPing() (19-55) reads now = ctx.currentTime (frozen) and schedules/stops oscillators against a clock that never advances.
  • Repro: Enable the notification sound, let an incoming streamed message trigger the first ping (non-gesture). No sound. All later pings reuse the suspended singleton and are also silent.
  • Trace: new-message (use-generate.ts:1645/2242/2286, use-background-autonomous.ts:219, ConversationView.tsx:787/814, etc.) -> playNotificationPing -> getAudioContext creates suspended ctx -> osc.start(now)/stop(now+0.25) on frozen clock -> no audio.

Sub-bug 2: No webkit fallback, swallowed error (#15)

  • How it breaks: new AudioContext() (line 9) has no window.webkitAudioContext fallback. On prefixed-only WebKit engines the bare identifier throws ReferenceError, swallowed by the empty catch {} (52-54) — no sound, no log, no toast. game-audio.ts:190-196 resolves window.AudioContext ?? webkitAudioContext; this file omits it.
  • Repro: Run on legacy Safari / older iOS WebView lacking unprefixed AudioContext. Ping never plays, no error surfaced.
  • Trace: playNotificationPing -> getAudioContext -> bare new AudioContext() throws -> caught at 52 -> returns silently.

Suggested Fix

In getAudioContext(): resolve const Ctor = window.AudioContext ?? (window as any).webkitAudioContext; (guard undefined), and in playNotificationPing() after obtaining the context do if (ctx.state === 'suspended') void ctx.resume(); before scheduling (mirror game-audio.ts:198-199). The context recovers once any user gesture has occurred.

Verification checklist (all manual)

  • Manually verify the notification ping plays on a new incoming message (not just the settings-toggle preview) in a standard browser build
  • Verify the ping still plays after the context was first created during a non-gesture event
  • Manually verify behavior on a WebKit/older-Safari target (or stub to prefixed-only) does not throw and degrades gracefully
  • Run pnpm check

Affected files

  • packages/client/src/lib/notification-sound.ts

Audit provenance

Found by a multi-agent static audit of the TTS/voice + image-generation subsystems (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged staging tree. Severity: HIGH.

AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.

Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2749 Originally assigned to: @SpicyMarinara on GitHub. ## Summary `notification-sound.ts` lazily constructs a module-level singleton `AudioContext` and never checks `ctx.state`/calls `ctx.resume()`. The very first real ping originates from a non-gesture event (incoming streamed message), so per browser autoplay policy the context is created `suspended`; its `currentTime` does not advance, oscillators scheduled at `now`/`now+0.25` never render, and because the context is a singleton that is never resumed it stays suspended for the page lifetime. The sibling `game-audio.ts` does the correct `if (state === 'suspended') void resume()`, proving the intended pattern is simply absent here. ## Sub-bug 1: Permanently-silent ping (#14) - **How it breaks:** `getAudioContext()` (lines 7-12) does `new AudioContext()` with no state check; `playNotificationPing()` (19-55) reads `now = ctx.currentTime` (frozen) and schedules/stops oscillators against a clock that never advances. - **Repro:** Enable the notification sound, let an incoming streamed message trigger the first ping (non-gesture). No sound. All later pings reuse the suspended singleton and are also silent. - **Trace:** new-message (use-generate.ts:1645/2242/2286, use-background-autonomous.ts:219, ConversationView.tsx:787/814, etc.) -> playNotificationPing -> getAudioContext creates suspended ctx -> osc.start(now)/stop(now+0.25) on frozen clock -> no audio. ## Sub-bug 2: No webkit fallback, swallowed error (#15) - **How it breaks:** `new AudioContext()` (line 9) has no `window.webkitAudioContext` fallback. On prefixed-only WebKit engines the bare identifier throws `ReferenceError`, swallowed by the empty `catch {}` (52-54) — no sound, no log, no toast. `game-audio.ts:190-196` resolves `window.AudioContext ?? webkitAudioContext`; this file omits it. - **Repro:** Run on legacy Safari / older iOS WebView lacking unprefixed `AudioContext`. Ping never plays, no error surfaced. - **Trace:** playNotificationPing -> getAudioContext -> bare `new AudioContext()` throws -> caught at 52 -> returns silently. ## Suggested Fix In `getAudioContext()`: resolve `const Ctor = window.AudioContext ?? (window as any).webkitAudioContext;` (guard undefined), and in `playNotificationPing()` after obtaining the context do `if (ctx.state === 'suspended') void ctx.resume();` before scheduling (mirror game-audio.ts:198-199). The context recovers once any user gesture has occurred. ## Verification checklist (all manual) - [ ] Manually verify the notification ping plays on a new incoming message (not just the settings-toggle preview) in a standard browser build - [ ] Verify the ping still plays after the context was first created during a non-gesture event - [ ] Manually verify behavior on a WebKit/older-Safari target (or stub to prefixed-only) does not throw and degrades gracefully - [ ] Run `pnpm check` --- ### Affected files - `packages/client/src/lib/notification-sound.ts` ### Audit provenance Found by a multi-agent static audit of the TTS/voice + image-generation subsystems (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged `staging` tree. Severity: **HIGH**. > AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Addressed on PR #2747. notification-sound now resolves window.AudioContext with the webkitAudioContext fallback, handles unavailable audio contexts gracefully, and resumes a suspended singleton before scheduling the synthesized ping. Deferred full pnpm validation until the end of the issue sweep, per maintainer request.

<!-- gh-comment-id:4763258723 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed on PR #2747. notification-sound now resolves window.AudioContext with the webkitAudioContext fallback, handles unavailable audio contexts gracefully, and resumes a suspended singleton before scheduling the synthesized ping. Deferred full pnpm validation until the end of the issue sweep, per maintainer request.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1388
No description provided.