Skip to content

fix: hard-reject ambient/noise and EDM-mix tracks in autoplay - #615

Merged
LucasSantana-Dev merged 3 commits into
mainfrom
fix/autoplay-content-filtering
Apr 14, 2026
Merged

LucasSantana-Dev merged 3 commits into
mainfrom
fix/autoplay-content-filtering

Conversation

@LucasSantana-Dev

@LucasSantana-Dev LucasSantana-Dev commented Apr 14, 2026 •

Copy link
Copy Markdown
Owner

Problem

Autoplay was recommending completely unrelated content:

  • Ambient/nature sounds (rain sounds, ocean waves, white noise)
  • ASMR and sleep music
  • Meditation/binaural beats
  • Long DJ sets and EDM mixes

These slipped through because calculateRecommendationScore had 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 of calculateRecommendationScore:

  • 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 meditation
  • EDM_MIX_RE: DJ sets, festival sets, N-hour mixes, extended club mixes, EDM/trance mixes

Constants 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

    • Improved music queue filtering to exclude ambient/noise content and EDM mix/set tracks from recommendations.
  • Tests

    • Added comprehensive test coverage verifying rejection of ambient/noise and EDM mix/set tracks in queue recommendations.

@vercel

vercel Bot commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lucky Ready Ready Preview, Comment Apr 14, 2026 8:07pm

@github-actions github-actions Bot added the bot label Apr 14, 2026
@coderabbitai

coderabbitai Bot commented Apr 14, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@LucasSantana-Dev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 48 minutes and 8 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a982a62f-5a85-4c57-b413-ce826e5a820e

📥 Commits

Reviewing files that changed from the base of the PR and between b0902f0 and 3738e38.

📒 Files selected for processing (1)
  • packages/bot/src/utils/music/queueManipulation.ts
📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Title-based track exclusion
packages/bot/src/utils/music/queueManipulation.ts
Introduced AMBIENT_NOISE_RE and EDM_MIX_RE regex patterns to filter candidate tracks in calculateRecommendationScore. Early filtering returns { score: -Infinity } with reason strings when candidate titles match ambient/noise or EDM mix patterns.
Exclusion filter test coverage
packages/bot/src/utils/music/queueManipulation.spec.ts
Added two parameterized test suites validating that ambient/noise-titled and EDM mix/set-titled tracks are rejected (no addTrack calls) during queue replenishment.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

bot, size/m

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: hard-reject ambient/noise and EDM-mix tracks in autoplay' directly and clearly summarizes the main change: filtering out ambient/noise and EDM-mix content from the autoplay recommendation system.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/autoplay-content-filtering

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2222fc7 and b0902f0.

📒 Files selected for processing (2)
  • packages/bot/src/utils/music/queueManipulation.spec.ts
  • packages/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

Comment on lines +3324 to +3364
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()
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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.

Comment on lines +1748 to +1753
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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.

@sonarqubecloud

Copy link
Copy Markdown

@LucasSantana-Dev
LucasSantana-Dev merged commit d6b9ae9 into main Apr 14, 2026
12 checks passed
@LucasSantana-Dev
LucasSantana-Dev deleted the fix/autoplay-content-filtering branch April 14, 2026 20:11
LucasSantana-Dev added a commit that referenced this pull request May 13, 2026
* 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

This branch was successfully deployed

1 active deployment
Preview — 3738e382 Deployed Apr 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant