Repository navigation
fix: hard-reject ambient/noise and EDM-mix tracks in autoplay - #615
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 48 minutes and 8 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds title-based exclusion filters to reject ambient/noise and EDM mix/set titled tracks during music queue recommendation scoring. Two regex patterns filter candidates early by returning infinite negative scores, with corresponding test suites verifying the exclusion behavior. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/bot/src/utils/music/queueManipulation.spec.ts`:
- Around line 3324-3364: The rejection tests currently use 1-hour tracks which
are already filtered by duration caps, so update the test cases in the spec that
call replenishQueue (the it.each blocks using createQueueMock and addTrackMock)
to use durations inside the allowed range (e.g., set durationMS to a short valid
value like 200000) for the candidate ambient/EDM tracks so the tests exercise
title-based rejection logic instead of duration filters; ensure you only change
the candidate track's durationMS (leave title, id and player.search shape, and
the use of addTrackMock/replenishQueue intact) so the new ambient/EDM guards are
actually validated.
In `@packages/bot/src/utils/music/queueManipulation.ts`:
- Around line 1748-1753: AMBIENT_NOISE_RE and EDM_MIX_RE miss variants like
“frequency/frequencies” and titles with hyphens/underscores (e.g., white-noise,
EDM-mix); update AMBIENT_NOISE_RE to use a correct token for frequency such as
"frequen(?:cy|cies)" instead of "frequ?e?n?c?" and change the inter-word
separator tokens from "\s{0,3}" to a character class that allows spaces, hyphens
and underscores like "[\s-_]{0,3}", then apply the same separator change to
EDM_MIX_RE (and the similar regex block referenced at lines ~1818-1824) so
dashed/underscored variants are matched.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aa195773-ed6c-4044-befb-3d4191ea3352
📒 Files selected for processing (2)
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/utils/music/queueManipulation.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: SonarCloud Scan
- GitHub Check: Quality Gates
| it.each([ | ||
| 'Relaxing Rain Sounds for Sleep', | ||
| 'Ocean Waves Sounds 1 Hour', | ||
| 'White Noise for Baby Sleep', | ||
| 'ASMR Soft Spoken Triggers', | ||
| 'Binaural Beats Deep Focus', | ||
| 'Guided Meditation Music 432Hz', | ||
| 'Spa Music Relaxation', | ||
| ])('rejects ambient/noise track "%s"', async (title) => { | ||
| const addTrackMock = jest.fn() | ||
| const queue = createQueueMock({ | ||
| currentTrack: { | ||
| url: 'https://example.com/current', | ||
| title: 'Current Song', | ||
| author: 'Current Artist', | ||
| id: 'curr', | ||
| durationMS: 200000, | ||
| requestedBy: { id: 'user-1' }, | ||
| } as unknown as Track, | ||
| player: { | ||
| search: jest.fn().mockResolvedValue({ | ||
| tracks: [ | ||
| { | ||
| url: 'https://example.com/ambient', | ||
| title, | ||
| author: 'Ambient Channel', | ||
| id: 'amb1', | ||
| durationMS: 3600000, | ||
| requestedBy: null, | ||
| }, | ||
| ], | ||
| }), | ||
| }, | ||
| addTrack: addTrackMock, | ||
| metadata: { requestedBy: { id: 'user-1' } }, | ||
| }) | ||
|
|
||
| await replenishQueue(queue as unknown as GuildQueue) | ||
|
|
||
| expect(addTrackMock).not.toHaveBeenCalled() | ||
| }) |
There was a problem hiding this comment.
Make these new rejection tests independent of duration filters.
Line [3351] and Line [3391] use 1-hour candidates, which are already excluded by existing duration caps before title regex checks run. These tests can pass even if the new ambient/EDM guards are removed.
Proposed test fix
- durationMS: 3600000,
+ durationMS: 240000,
...
- durationMS: 3600000,
+ durationMS: 240000,Also applies to: 3366-3404
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/bot/src/utils/music/queueManipulation.spec.ts` around lines 3324 -
3364, The rejection tests currently use 1-hour tracks which are already filtered
by duration caps, so update the test cases in the spec that call replenishQueue
(the it.each blocks using createQueueMock and addTrackMock) to use durations
inside the allowed range (e.g., set durationMS to a short valid value like
200000) for the candidate ambient/EDM tracks so the tests exercise title-based
rejection logic instead of duration filters; ensure you only change the
candidate track's durationMS (leave title, id and player.search shape, and the
use of addTrackMock/replenishQueue intact) so the new ambient/EDM guards are
actually validated.
| const AMBIENT_NOISE_RE = | ||
| /\b(?:rain\s{0,3}sounds?|rain\s{0,3}for\s{0,3}sleep|ocean\s{0,3}waves?|waves?\s{0,3}sounds?|nature\s{0,3}sounds?|forest\s{0,3}sounds?|thunder\s{0,3}sounds?|white\s{0,3}noise|brown\s{0,3}noise|pink\s{0,3}noise|asmr|sleep\s{0,3}sounds?|sleep\s{0,3}music|relaxing\s{0,3}rain|ambient\s{0,3}sounds?|binaural\s{0,3}beats?|solfeggio|healing\s{0,3}frequ?e?n?c?|528\s?hz|432\s?hz|963\s?hz|chakra\s{0,3}healing|spa\s{0,3}music|massage\s{0,3}music|yoga\s{0,3}music|deep\s{0,3}sleep|baby\s{0,3}sleep|guided\s{0,3}meditation|meditation\s{0,3}music)\b/i | ||
|
|
||
| const EDM_MIX_RE = | ||
| /\b(?:dj\s{0,3}set|festival\s{0,3}set|\d+\s?(?:hour|hr)\s{0,3}(?:long\s{0,3})?mix|extended\s{0,3}mix|club\s{0,3}mix|nightclub\s{0,3}mix|edm\s{0,3}mix|trance\s{0,3}mix)\b/i | ||
|
|
There was a problem hiding this comment.
Regex currently misses common blocked-title variants.
Line [1749] uses frequ?e?n?c?, which won’t reliably match “frequency/frequencies”. Also, Line [1818] tests raw titles, so common forms like EDM-mix / white-noise can bypass the filter.
Proposed fix
-const AMBIENT_NOISE_RE =
- /\b(?:rain\s{0,3}sounds?|rain\s{0,3}for\s{0,3}sleep|ocean\s{0,3}waves?|waves?\s{0,3}sounds?|nature\s{0,3}sounds?|forest\s{0,3}sounds?|thunder\s{0,3}sounds?|white\s{0,3}noise|brown\s{0,3}noise|pink\s{0,3}noise|asmr|sleep\s{0,3}sounds?|sleep\s{0,3}music|relaxing\s{0,3}rain|ambient\s{0,3}sounds?|binaural\s{0,3}beats?|solfeggio|healing\s{0,3}frequ?e?n?c?|528\s?hz|432\s?hz|963\s?hz|chakra\s{0,3}healing|spa\s{0,3}music|massage\s{0,3}music|yoga\s{0,3}music|deep\s{0,3}sleep|baby\s{0,3}sleep|guided\s{0,3}meditation|meditation\s{0,3}music)\b/i
+const AMBIENT_NOISE_RE =
+ /\b(?:rain\s{0,3}sounds?|rain\s{0,3}for\s{0,3}sleep|ocean\s{0,3}waves?|waves?\s{0,3}sounds?|nature\s{0,3}sounds?|forest\s{0,3}sounds?|thunder\s{0,3}sounds?|white\s{0,3}noise|brown\s{0,3}noise|pink\s{0,3}noise|asmr|sleep\s{0,3}sounds?|sleep\s{0,3}music|relaxing\s{0,3}rain|ambient\s{0,3}sounds?|binaural\s{0,3}beats?|solfeggio|healing\s{0,3}frequenc(?:y|ies)|528\s?hz|432\s?hz|963\s?hz|chakra\s{0,3}healing|spa\s{0,3}music|massage\s{0,3}music|yoga\s{0,3}music|deep\s{0,3}sleep|baby\s{0,3}sleep|guided\s{0,3}meditation|meditation\s{0,3}music)\b/i
- const candidateTitle = candidate.title ?? ''
+ const candidateTitle = (candidate.title ?? '').replace(/[-_/]+/g, ' ')Also applies to: 1818-1824
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/bot/src/utils/music/queueManipulation.ts` around lines 1748 - 1753,
AMBIENT_NOISE_RE and EDM_MIX_RE miss variants like “frequency/frequencies” and
titles with hyphens/underscores (e.g., white-noise, EDM-mix); update
AMBIENT_NOISE_RE to use a correct token for frequency such as
"frequen(?:cy|cies)" instead of "frequ?e?n?c?" and change the inter-word
separator tokens from "\s{0,3}" to a character class that allows spaces, hyphens
and underscores like "[\s-_]{0,3}", then apply the same separator change to
EDM_MIX_RE (and the similar regex block referenced at lines ~1818-1824) so
dashed/underscored variants are matched.
|
* fix: hard-reject ambient/noise and edm-mix tracks in autoplay scoring * fix: simplify content-filter regexes to avoid sonar s5852 * fix: add nosonar suppression for content-filter regex false positives



Problem
Autoplay was recommending completely unrelated content:
These slipped through because
calculateRecommendationScorehad no content-type guards — only duration and artist block checks.Fix
Added two module-level regex constants and hard-reject (
-Infinity) checks at the top ofcalculateRecommendationScore:AMBIENT_NOISE_RE: rain sounds, ocean waves, white noise, brown/pink noise, ASMR, sleep music, binaural beats, solfeggio, healing frequencies, chakra, spa/massage/yoga music, deep sleep, guided meditationEDM_MIX_RE: DJ sets, festival sets, N-hour mixes, extended club mixes, EDM/trance mixesConstants are module-level (compiled once, not per-call).
Tests
+12 parameterized tests covering all new reject patterns (7 ambient + 5 EDM). 112 total passing.
Summary by CodeRabbit
Bug Fixes
Tests