Skip to content

fix(notifications): replay completion sounds reliably - #15940

Merged
nwparker merged 2 commits into
stablyai:mainfrom
DEOWL-kan:fix/completion-notification-sound
Oct 6, 2026
Merged

nwparker merged 2 commits into
stablyai:mainfrom
DEOWL-kan:fix/completion-notification-sound

Conversation

@DEOWL-kan

@DEOWL-kan DEOWL-kan commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Two completions close together could show two notifications but play only the first sound. Each delivered custom-sound notification now restarts one cached player, so a later completion is audible without overlapping players.

What Changed

Removed the global “already playing” gate, including the flag that could stay set after an audio stall. Concurrent cold loads reuse the same player. Removed the event listeners used only to maintain that deleted flag. Added seek-reset, concurrency, failed-play retry, volume, missing-configuration, and real Electron audio coverage.

Why

A timeout, as proposed in #15938, limits permanent silence but still drops legitimate completions during its dedupe window. Restarting the existing player avoids that window and bounds playback resources. Bursts restart the file; this does not queue every sound to play to completion.

Linked Issue

Fixes #15933

Visual Proof

Same reproducer before and after: a two-second WAV is requested at approximately 0.0s, 0.6s and 3.0s. Turn audio on. The short high note at the beginning makes the restart at 0.6s audible. The waveform comes from the actual Chromium audio, recorded with MediaRecorder through CDP; it is not a synthesized reconstruction.

Before — current main drops the middle request:

notification-sound-before.mp4

After — the middle request restarts the same player:

notification-sound-after.mp4

Three passing Electron repetitions for each implementation. All runs construct one real Audio element. Decoded PCM at 2.25–2.4s is silent before (RMS 0) and audible after (RMS 0.1295), demonstrating the restarted sound lasts beyond the original endpoint. This isolates playback through the real preload and sound IPC; it does not automate macOS Notification Center or capture the physical speakers.

Testing

  • Verified locally through automated CDP interaction and actual decoded audio on macOS arm64.
  • Automated tests added/updated.
  • Focused notification/preload/dispatch suite: 45 passed.
  • Real Electron playback: 3/3 before and 3/3 after. A first baseline batch had an Electron page/teardown failure; replaced with a fully passing batch before uploading evidence.
  • Renderer and CLI typecheck, changed-code quality, focused lint, and Electron e2e build passed.
  • Full pnpm tc is blocked by an existing missing codexProviderHandle symbol in src/main/native-chat/agent-session-journal/journal-submission-positions.test.ts:29 on base commit 9323443c835f. Renderer and CLI projects pass.
  • Reproduce: ORCA_BACKGROUND_LAUNCH=1 pnpm exec playwright test tests/e2e/notification-sound-replay.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1 --repeat-each=3.

AI Disclosure

Original implementation used Codex. Maintainer review, rebase, regression coverage, and evidence capture also used Codex.

Review

Checked cold-cache races, cached replay, recovery after rejected playback, resource disposal, volume bounds, and delivery suppression. Intentionally suppressed notifications still do not reach playback. Shared HTML audio code has no new platform or remote-wire branch; only macOS was exercised in Electron.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer implementation copied.

Notes

Rebased onto 9323443c835f; reviewed head 88e47c79f857. The attachments compare the same preload playback behavior on the earlier b6c5f3f12337 base; the rebased head was rechecked with the regression suite and real Electron playback. Sound remains client-local for SSH and runtime workspaces. No Git-provider or mobile contract change. Media is attached, not committed.

Checklist

  • Small and focused.
  • Before/after behavior, mechanism, and alternative explained.
  • Before/after audible evidence attached.
  • Reviewed correctness, security, and resource use.
  • Cross-platform and remote implications considered.
  • Focused tests, relevant typechecks, quality gate, and build pass; full-typecheck base failure documented above.

@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 23ac4ee9-5c56-4247-b92c-aa9388e6667c
📥 Commits

Reviewing files that changed from the base of the PR and between 3d6de18537aa03416a44c70fdbf14b6507b4bca8 and e757ec2ff72976cd5fb533cfe1be554b4b1864f0.

📒 Files selected for processing (3)
  • src/preload/api/notification-sound-playback.test.ts
  • src/preload/api/notifications-bridge.ts
  • tests/e2e/notification-sound-replay.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Notification sound playback no longer tracks an active-playing flag or suppresses repeated requests. Concurrent loads reuse a matching cached sound entry. New Vitest coverage checks repeated and concurrent playback, failures, volume limits, and missing paths. A new end-to-end test generates a WAV tone and records Chromium playback.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to e757e

Notification sounds now play for every eligible notification instead of being suppressed while a previous sound is playing. The change is small and has regression tests. I found no concrete merge-blocking risk.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to e757e

The change restarts an existing notification sound without granting new file access or privileges. Concurrent requests reuse one cached player, and playback failures remain recoverable. No material security risk introduced or worsened by this change was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed capability is client-local replay of the configured notification sound. A caller controlling the existing renderer API could already request replay with force in the base; the head therefore does not introduce that authority. No new path argument or file-selection capability is added.

Trust Boundaries and Controls

  • observed — Main still derives the selected sound from stored notification settings rather than IPC arguments. It normalizes the path, checks the supported extension, and checks regular-file status and a 10 MiB limit before reading. These are existing sound-loading controls, not evidence of a general filesystem sandbox. The added tests exercise the existing API; their mocks and CDP instrumentation add no production entrypoint.

Resilience and Maintainability Implications

  • inferred — Same-path cache convergence reduces duplicate player ownership without changing replacement authority. Different-path loads can still evict an in-flight player, and settings can change between resolution and loading; both behaviors exist in the base. Their browser-specific interruption outcomes remain untested here, but the comparison does not support treating them as newly introduced security concerns.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #15933 requires reliable configured playback for eligible notifications, a regression test, and continued silence for muted or suppressed notifications. notifications-bridge.ts removes the glo…
Out of Scope Changes check ✅ Passed The changes are limited to notification sound playback and its unit and end-to-end regression tests. The generated tone and playback recording support verification of the issue behavior. No unrelated …
Title check ✅ Passed The title clearly and concisely describes the main change: reliable replay of notification completion sounds.
Description check ✅ Passed The description covers the required sections, links issue #15933, explains the change and rationale, provides before-and-after evidence, and documents testing and a known typecheck blocker.
  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@DEOWL-kan
DEOWL-kan force-pushed the fix/completion-notification-sound branch from 9d98292 to 3d6de18 Compare September 4, 2026 08:25
@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@DEOWL-kan

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main and resolved the conflict. Now 1 commit, 2 files, +90/−16.

The conflict was not a normal one: #14703 split src/preload/index.ts from 5136 lines down to 197 plus src/preload/api/*, so this change had to move rather than merge. It now lands in src/preload/api/notifications-bridge.ts.

The bug is still present on main (notifications-bridge.ts:55 as of 2ee507d) — playSound returns { played: false, reason: 'deduped' } whenever a previous sound is still ringing, so a burst of completions plays once instead of once per notification.

What changed:

  • src/preload/api/notifications-bridge.ts — drop the in-flight gate and restart the cached Audio instead, and reuse an entry a concurrent call already cached for the same path so two parallel first playbacks share one Audio rather than revoking each other's blob URL.
  • src/preload/api/notification-sound-playback.test.ts (new) — two cases. Both fail against unpatched main with expected { played: false, reason: 'deduped' } to deeply equal { played: true } and expected "vi.fn()" to be called once, but got 2 times.

The force option and the 'deduped' member of the reason union are kept for type/API compatibility even though nothing produces 'deduped' any more. Happy to remove both if you would rather not carry a dead parameter — it touches three call sites and the shared union.

Verified locally: pnpm tc clean, oxlint clean, and a targeted sweep of the notification/preload/ipc-events/activation surface passes (528 files, 4755 tests).

@nwparker

nwparker commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

@DEOWL-kan thanks, reviewing this and your other PRs
Sorry for delay!

@nwparker
nwparker force-pushed the fix/completion-notification-sound branch from 3d6de18 to e757ec2 Compare October 6, 2026 00:21
Laku and others added 2 commits October 5, 2026 17:40
The in-flight `isNotificationSoundPlaying` gate dropped every notification
sound that arrived while the previous one was still ringing, so bursts played
once. Drop the gate and restart the cached Audio instead, and reuse an entry a
concurrent call already cached for the same path so parallel first playbacks
share one Audio rather than revoking each other's blob URL.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_016S8SZpkXGcnU5UWwA8UiF2
@nwparker
nwparker force-pushed the fix/completion-notification-sound branch from e757ec2 to 88e47c7 Compare October 6, 2026 00:41

@nwparker nwparker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adversarial review of #15933 and this PR, followed by rebase and fixes. Reviewed head: 88e47c79f8574da6b7aec3a92eccc9255cb2234e on 9323443c835f.

  • The old global playing flag drops an eligible second completion while audio is active; a stalled element can also leave later notifications silent indefinitely. Removing that gate satisfies the issue's eligible-notification requirement better than the 10-second guard in #15938, which still drops completions inside its window.
  • Confirmed the cold-cache race reuses one Audio element instead of overlapping players. Removed ended/error listeners that existed only to maintain the deleted flag. Added regression checks for restart seek, concurrent loading, rejected-play retry, volume limits, and cache disposal when configuration disappears.
  • Playback restarts the current sound; bursts truncate the earlier sound rather than queueing full recordings. That behavior is explicit in the updated description.

Evidence is attached in the PR body: actual audible Chromium recordings before and after, with the second request at about 0.6 seconds. Three passing baseline runs and three passing after runs; the final rebased head also passed three real-Electron runs. One Audio element in every run; decoded audio remains audible past the old endpoint after the restart. The recording uses the real preload and sound IPC with audio redirected into MediaRecorder, so physical speakers and OS banner delivery are not claimed.

45 focused tests passed. Changed-code quality, focused lint, renderer/CLI typecheck, and Electron build pass. Full typecheck remains blocked by main's unrelated missing codexProviderHandle symbol in journal-submission-positions.test.ts:29. Suppressed/muted notification delivery is covered by the dispatch suite. Only macOS was exercised with Electron; Linux/Windows and live SSH were not run. No new remote protocol behavior.

No remaining blocker found in this sound change. CI has not reported checks on the pushed fork head; this is a comment review, not a blanket CI or native-OS approval.

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.

[Bug]: Completion notifications intermittently play no sound

2 participants