Skip to content

fix(bot): eliminate same-song repetition in autoplay - #575

Merged
LucasSantana-Dev merged 1 commit into
mainfrom
fix/autoplay-same-song-v2
Apr 12, 2026
Merged

LucasSantana-Dev merged 1 commit into
mainfrom
fix/autoplay-same-song-v2

Conversation

@LucasSantana-Dev

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

Copy link
Copy Markdown
Owner

Problem

Autoplay was repeatedly queuing different versions of the same song (e.g. "Song - Remastered", "Song - Live Version", "Song - Deluxe Edition") because:

  1. HYPHENATED_VERSION_SUFFIXES was incomplete — patterns like "Live Version", "Remastered Version", "Deluxe Edition" didn't match, so cleanTitle() left the suffix in place and two versions normalized to different keys
  2. Last.fm seed deduplication used raw titles — if Last.fm stored both "Song" and "Song - Remastered" as top tracks, both passed dedup and generated separate searches
  3. Seed search queries were built with raw titles — "Song - Remastered Artist" as a search query produces different YouTube results than "Song Artist", allowing version variants to slip through the candidates map

Changes

  • searchQueryCleaner.ts: Expand HYPHENATED_VERSION_SUFFIXES to handle "Live Version", "Remastered Version", "Deluxe Edition", "Explicit Version", "Instrumental Version", etc.
  • lastFmSeeds.ts: Use cleanTitle() when building the dedup key so "Song - Remastered" and "Song" collapse to one seed entry
  • queueManipulation.ts: Use cleanSearchQuery() for all seed-based Last.fm searches (direct search + getSimilarTracks) to strip version noise before querying

Result

Different versions of the same song now normalize to the same key at every stage of the pipeline — seed dedup, search query, candidates map, and history exclusion — so they can't both make it into the queue.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced track deduplication logic to better identify and remove duplicate music entries that differ only by formatting, whitespace, or minor title variations.
    • Improved search query processing and title normalization for more accurate music recommendations and better matching of similar tracks across music databases.

…eed dedup and expanded version suffix patterns

- Expand HYPHENATED_VERSION_SUFFIXES to strip 'Live Version', 'Remastered Version', 'Deluxe Edition', etc.
- Normalize seed titles via cleanTitle() before Last.fm deduplication so 'Song - Remastered' and 'Song' collapse to one seed
- Use cleanSearchQuery() for all seed-based Last.fm search queries to strip version noise before searching
- Pass cleaned title to getSimilarTracks() so Last.fm finds the canonical track, not a decorated version
@LucasSantana-Dev
LucasSantana-Dev enabled auto-merge (squash) April 12, 2026 21:29
@vercel

vercel Bot commented Apr 12, 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 12, 2026 9:30pm

@coderabbitai

coderabbitai Bot commented Apr 12, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

These changes improve track deduplication and Last.fm search accuracy by applying consistent title normalization across the music utility pipeline. The cleanTitle function is now used in deduplication keys and search queries, while version suffix patterns are expanded to recognize more formatting variants.

Changes

Cohort / File(s) Summary
Deduplication and Search Normalization
packages/bot/src/utils/music/autoplay/lastFmSeeds.ts, packages/bot/src/utils/music/queueManipulation.ts
Updated deduplication key generation and Last.fm search query construction to use cleanTitle() and cleanSearchQuery() for consistent title normalization instead of raw string manipulation.
Version Suffix Patterns
packages/bot/src/utils/music/searchQueryCleaner.ts
Expanded HYPHENATED_VERSION_SUFFIXES regex patterns to recognize additional title suffix variants including remaster versions, music video formats, instrumental/karaoke variants, explicit/clean editions, and deluxe variants.

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(bot): eliminate same-song repetition in autoplay' directly addresses the core problem solved by the PR: preventing autoplay from repeatedly queuing different decorated versions of the same song.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/autoplay-same-song-v2

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.

🧹 Nitpick comments (2)
packages/bot/src/utils/music/queueManipulation.ts (1)

754-754: Normalize artist for getSimilarTracks too, for full symmetry.

Line 754 cleans only title. Using cleanAuthor(seed.artist) here keeps Last.fm similar-track seeding consistent with the cleaned-query path.

Proposed patch
-        const similar = await getSimilarTracks(seed.artist, cleanTitle(seed.title))
+        const similar = await getSimilarTracks(
+            cleanAuthor(seed.artist),
+            cleanTitle(seed.title),
+        )
🤖 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` at line 754, Call
cleanAuthor on the seed artist before passing it to getSimilarTracks to mirror
the title normalization path; replace the direct use of seed.artist in the
getSimilarTracks call with cleanAuthor(seed.artist) so
getSimilarTracks(seedArtist, cleanTitle(seed.title)) uses normalized artist and
title (refer to getSimilarTracks, cleanAuthor, cleanTitle, and seed.artist).
packages/bot/src/utils/music/autoplay/lastFmSeeds.ts (1)

8-8: Consider normalizing artist in dedupe keys as well.

Line 32–33 now normalizes title (great), but artist is still only lowercased. Trimming/cleaning artist too will make dedup keys more stable.

Proposed patch
-import { cleanTitle } from '../searchQueryCleaner'
+import { cleanAuthor, cleanTitle } from '../searchQueryCleaner'
...
-        const normalizedTitle = cleanTitle(t.title).toLowerCase().trim()
-        const key = `${t.artist.toLowerCase()}|${normalizedTitle}`
+        const normalizedArtist = cleanAuthor(t.artist).toLowerCase().trim()
+        const normalizedTitle = cleanTitle(t.title).toLowerCase().trim()
+        const key = `${normalizedArtist}|${normalizedTitle}`

Also applies to: 32-33

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bot/src/utils/music/autoplay/lastFmSeeds.ts` at line 8, The dedupe
key generation in lastFmSeeds.ts currently only lowercases the artist while
calling cleanTitle on the title; update the artist normalization to match by
trimming and cleaning it (e.g., replace artist.toLowerCase() with
cleanTitle(artist) or trim+clean equivalent) wherever the dedupe key is
constructed (the function that builds the dedupe key in this file), so artist
values are normalized the same way as titles.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/bot/src/utils/music/autoplay/lastFmSeeds.ts`:
- Line 8: The dedupe key generation in lastFmSeeds.ts currently only lowercases
the artist while calling cleanTitle on the title; update the artist
normalization to match by trimming and cleaning it (e.g., replace
artist.toLowerCase() with cleanTitle(artist) or trim+clean equivalent) wherever
the dedupe key is constructed (the function that builds the dedupe key in this
file), so artist values are normalized the same way as titles.

In `@packages/bot/src/utils/music/queueManipulation.ts`:
- Line 754: Call cleanAuthor on the seed artist before passing it to
getSimilarTracks to mirror the title normalization path; replace the direct use
of seed.artist in the getSimilarTracks call with cleanAuthor(seed.artist) so
getSimilarTracks(seedArtist, cleanTitle(seed.title)) uses normalized artist and
title (refer to getSimilarTracks, cleanAuthor, cleanTitle, and seed.artist).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b9a7ba2a-7e78-4aab-bb1c-776c08bb2c9a

📥 Commits

Reviewing files that changed from the base of the PR and between c7267f0 and 57a61a8.

📒 Files selected for processing (3)
  • packages/bot/src/utils/music/autoplay/lastFmSeeds.ts
  • packages/bot/src/utils/music/queueManipulation.ts
  • packages/bot/src/utils/music/searchQueryCleaner.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
🔇 Additional comments (2)
packages/bot/src/utils/music/searchQueryCleaner.ts (1)

87-93: Expanded hyphen-suffix normalization is on point.

Line 87–93 strengthens canonicalization for remaster/live/deluxe/explicit variants and aligns with the duplicate-prevention path in cleanTitle.

packages/bot/src/utils/music/queueManipulation.ts (1)

728-729: Good consistency win: cleaned queries are now used in Last.fm-driven searches.

Line 728, Line 756, and Line 872 now funnel through cleanSearchQuery, which should materially reduce variant-title leakage into candidate generation.

Also applies to: 756-757, 872-873

@sonarqubecloud

Copy link
Copy Markdown

@LucasSantana-Dev
LucasSantana-Dev merged commit c480824 into main Apr 12, 2026
12 checks passed
LucasSantana-Dev added a commit that referenced this pull request May 13, 2026
…eed dedup and expanded version suffix patterns (#575)

- Expand HYPHENATED_VERSION_SUFFIXES to strip 'Live Version', 'Remastered Version', 'Deluxe Edition', etc.
- Normalize seed titles via cleanTitle() before Last.fm deduplication so 'Song - Remastered' and 'Song' collapse to one seed
- Use cleanSearchQuery() for all seed-based Last.fm search queries to strip version noise before searching
- Pass cleaned title to getSimilarTracks() so Last.fm finds the canonical track, not a decorated version

This branch was successfully deployed

1 active deployment
Preview — 57a61a84 Deployed Apr 12, 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