Repository navigation
Conversation
…ed element cannot silence every later notification The dedupe flag cleared only on the Audio element's ended/error events; an OS audio route change or device sleep mid-play fires neither, latching the flag true forever — every subsequent completion notification then returned 'deduped' silently, which the renderer treats as expected burst coalescing. Playback state moves to a small module that releases the window on ended, error, or a 10s time bound, whichever comes first. Fixes stablyai#15933
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe change adds a notification sound playback manager with event-based cleanup and a 10-second timeout fallback. The preload script now uses this manager for deduplication, playback start, release handling, and state clearing. Tests cover normal completion, errors, stalled playback, replacement, stale timers and events, forced release, listener cleanup, and idempotent release. Merge Risk: 🔵 Low · up to The change prevents a stalled notification sound from permanently suppressing later sounds by releasing the dedupe window after 10 seconds. It is mergeable with owner awareness that the timer-isolation regression test should clearly verify that an earlier playback cannot release a later one. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/preload/notification-sound-playback.ts (1)
1-6: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten the rationale comment.
Reduce this six-line comment to one concise line. Move the full incident detail to issue
#15933or a design document.As per coding guidelines, comments must be concise, non-obvious, and brief; prefer one line.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 24345875-2aa2-45d9-bd0b-d93ceec95ba0
📒 Files selected for processing (3)
src/preload/index.tssrc/preload/notification-sound-playback.test.tssrc/preload/notification-sound-playback.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| it('stops the fallback timer once ended fires, and a late timer fires nothing', () => { | ||
| const playback = createNotificationSoundPlayback() | ||
| const first = fakeAudio() | ||
| playback.begin(first.audio) | ||
| first.emit('ended') | ||
|
|
||
| // The timer for the finished playback must not release the NEXT one early. | ||
| const second = fakeAudio() | ||
| playback.begin(second.audio) | ||
| vi.advanceTimersByTime(MAX_NOTIFICATION_SOUND_PLAYBACK_MS + 5) | ||
| expect(playback.isPlaying()).toBe(false) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Test the old timer separately.
The two timers have the same deadline. This assertion passes when the second timer releases playback, even if the first timer was not cleared.
Advance time before ending the first playback. Then assert that playback remains active at the old timer deadline and releases only at the second timer deadline.
Proposed test change
const playback = createNotificationSoundPlayback()
const first = fakeAudio()
playback.begin(first.audio)
+ vi.advanceTimersByTime(1)
first.emit('ended')
- // The timer for the finished playback must not release the NEXT one early.
const second = fakeAudio()
playback.begin(second.audio)
- vi.advanceTimersByTime(MAX_NOTIFICATION_SOUND_PLAYBACK_MS + 5)
+ vi.advanceTimersByTime(MAX_NOTIFICATION_SOUND_PLAYBACK_MS - 1)
+ expect(playback.isPlaying()).toBe(true)
+
+ vi.advanceTimersByTime(1)
expect(playback.isPlaying()).toBe(false)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it('stops the fallback timer once ended fires, and a late timer fires nothing', () => { | |
| const playback = createNotificationSoundPlayback() | |
| const first = fakeAudio() | |
| playback.begin(first.audio) | |
| first.emit('ended') | |
| // The timer for the finished playback must not release the NEXT one early. | |
| const second = fakeAudio() | |
| playback.begin(second.audio) | |
| vi.advanceTimersByTime(MAX_NOTIFICATION_SOUND_PLAYBACK_MS + 5) | |
| expect(playback.isPlaying()).toBe(false) | |
| it('stops the fallback timer once ended fires, and a late timer fires nothing', () => { | |
| const playback = createNotificationSoundPlayback() | |
| const first = fakeAudio() | |
| playback.begin(first.audio) | |
| vi.advanceTimersByTime(1) | |
| first.emit('ended') | |
| const second = fakeAudio() | |
| playback.begin(second.audio) | |
| vi.advanceTimersByTime(MAX_NOTIFICATION_SOUND_PLAYBACK_MS - 1) | |
| expect(playback.isPlaying()).toBe(true) | |
| vi.advanceTimersByTime(1) | |
| expect(playback.isPlaying()).toBe(false) |
…nes differ Coderabbit review on stablyai#15938: with both timers armed at the same tick the test could not show the finished window's timer leaving the next one alone.
|
Right — with both timers armed at the same tick the deadlines coincided, so the test proved nothing about separation. Pushed a fix: the second |
|
Closing as superseded: the linked issue's requested behavior is already implemented on The global already-playing/dedupe flag was removed, so stalled audio cannot latch later notifications silent. Later delivered completions restart one cached player; no timeout gate is needed. Thanks for the contribution. This closes the redundant PR without deleting its branch. |
What
The custom notification sound's dedupe window is now bounded in time. A small
createNotificationSoundPlaybackmodule (src/preload/notification-sound-playback.ts) owns the in-flight flag and releases it onended,error, or a 10-second time bound, whichever comes first — replacing the inline pair of module-level variables in the preload whose flag cleared only on the two events.Why (issue #15933)
playSound's dedupe gate (if (!options?.force && isNotificationSoundPlaying) return { played: false, reason: 'deduped' }) existed to drop replays while a sound was still ringing. But the flag was released only by theAudioelement'sended/errorlisteners. An element that stalls — an OS audio route change (Bluetooth/HDMI disconnect), a device sleep mid-play, a decode stall — fires neither event, so the flag latchedtrueforever. Every subsequent completion notification then short-circuited to'deduped', a reason the renderer wrapper deliberately does not warn about (it means expected burst coalescing) — so the failure was both permanent-until-restart and completely silent. That matches the report's "intermittent, timing/state dependent" exactly: one stall event, and sounds stop from then on.The time bound makes one stall cost at most one missed sound. Normal sounds end well under 10s;
force(the settings test button) bypasses the gate entirely and is unaffected; intentionally muted/suppressed notifications never reachplaySoundat all.How
begin(audio)marks playback, wiresended/error, and armssetTimeout(finish, MAX_NOTIFICATION_SOUND_PLAYBACK_MS);finishis idempotent and unhooks everything.beginreleases the previous window first, so a stuck element cannot leak into the next notification;forceRelease()covers the dispose/reload paths (sound file change).playSoundflow is otherwise unchanged — same results, same IPC, same cache.Testing
New
src/preload/notification-sound-playback.test.ts(fake timers + fake audio element):ended; releases onerror;beginwhile one is stuck releases the previous, and the stuck element's lateendedcannot release the fresh window;forceReleasedrops the window, unhooks listeners, and the laterrelease()from theaudio.play()rejection path is a safe no-op.Full typecheck clean; the preload/dispatch suites pass. (Two unrelated failures visible in a full
src/renderer/src/librun — a cmd.exe quoting case and the activation-surface census — are load flakes: both pass in isolation on a tree with these changes present.)Fixes #15933