Skip to content

fix(autoplay): strip modifiers from Spotify query, broaden cover dedup - #589

Merged
LucasSantana-Dev merged 2 commits into
mainfrom
fix/spotify-modifier-query
Apr 13, 2026
Merged

LucasSantana-Dev merged 2 commits into
mainfrom
fix/spotify-modifier-query

Conversation

@LucasSantana-Dev

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

Copy link
Copy Markdown
Owner

Problem

Two independent bugs causing wrong tracks to be queued:

1. YouTube fallback on every non-first replenish cycle

searchSeedCandidates appended query modifiers (similar, like, playlist, mix) to all engines, including Spotify. Spotify doesn't understand these text modifiers and returns 0 results, silently falling back to YouTube on every cycle where replenishCount > 0.

Before: "Água viva ANATOMIA similar" → Spotify: 0 results → YouTube fallback
After: "Água viva ANATOMIA" → Spotify: correct results

2. Cover variants bypassing dedup

The cover noise pattern was too narrow: /\(cover(?:\s{0,3}version)?\)/gi only matched (cover) and (cover version). Titles like (Cover - ao vivo) or (Cover by X) were not stripped, so their coreKey differed from the studio version and dedup missed them.

Before: "Água viva (Cover - ao vivo)" → coreKey "agua viva cover ao vivo" ≠ "agua viva" → queued
After: "Água viva (Cover - ao vivo)" → cleanTitle strips (Cover...) → coreKey "agua viva" → deduplicated

Changes

  • queueManipulation.ts: spotifyQuery = spotifyBase (no modifier appended)
  • searchQueryCleaner.ts: (cover[^)]*) / [cover[^\]]*] patterns, cover in HYPHENATED_VERSION_SUFFIXES and VERSION_KEYWORD_RE
  • Tests: modifier non-append (2× replenish), cover dedup, 6 cleanTitle cover-pattern tests

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved Spotify search accuracy by refining search query handling to prevent irrelevant results.
    • Enhanced detection and filtering of cover song variants to prevent duplicate covers of currently playing tracks from being added to the queue.
  • New Features

    • Expanded recognition of cover variant patterns in track titles for better music deduplication.

…p patterns

- Remove query modifiers ('similar', 'like', 'playlist', 'mix') from the
  Spotify search query — Spotify ignores these and returns 0 results,
  causing unnecessary fallback to YouTube on every non-first replenish cycle
- Broaden cover noise patterns from /(cover version)?/ to /cover[^)]*/
  so '(Cover - ao vivo)', '(Cover by X)' etc. are stripped before coreKey
  computation, enabling dedup to catch cover variants of the now-playing song
- Add 'cover' to HYPHENATED_VERSION_SUFFIXES and VERSION_KEYWORD_RE so
  '- Cover' suffixes are also trimmed by cleanTitle
- Tests: modifier non-append test (2x replenish), cover dedup test,
  6 cleanTitle cover-pattern tests
@github-actions github-actions Bot added the bot label Apr 13, 2026
@vercel

vercel Bot commented Apr 13, 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 13, 2026 4:39pm

@coderabbitai

coderabbitai Bot commented Apr 13, 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 49 minutes and 41 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 49 minutes and 41 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: be76e286-19f9-4b3d-8da8-30ade85ee062

📥 Commits

Reviewing files that changed from the base of the PR and between 76d0a24 and 554204c.

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

Walkthrough

The changes refine music search query handling by preventing query modifiers from being appended to Spotify searches while expanding detection and cleaning of cover and variant track patterns throughout the search pipeline.

Changes

Cohort / File(s) Summary
Spotify Query Modifier Removal
packages/bot/src/utils/music/queueManipulation.ts, packages/bot/src/utils/music/queueManipulation.spec.ts
Removed the modifier suffix from Spotify engine queries in searchSeedCandidates to prevent textual query qualifiers from affecting Spotify results, while maintaining modifiers for fallback engines. Added test asserting Spotify queries never contain modifier patterns across consecutive replenish calls.
Cover Variant Noise Stripping
packages/bot/src/utils/music/searchQueryCleaner.ts, packages/bot/src/utils/music/searchQueryCleaner.spec.ts
Expanded cleanTitle to recognize and strip broader cover/variant patterns including parenthetical (Cover...), bracketed [Cover], hyphenated - Cover, and qualified variants like (Cover - Ao vivo). Added cover to version-related pattern matching (HYPHENATED_VERSION_SUFFIXES and VERSION_KEYWORD_RE).
Queue Diversity Test Coverage
packages/bot/src/utils/music/queueManipulation.spec.ts
Added test verifying that cover/variant tracks matching the currently playing track are excluded from queue replenishment while different tracks are added.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • #567: Directly modifies the modifier behavior in searchSeedCandidates that this PR adjusts for Spotify-specific query construction.
  • #513: Updates both searchQueryCleaner for cover/version noise stripping and queue de-duplication logic around cover/variant exclusion.
  • #575: Expands hyphenated suffix patterns and version/variant noise stripping in searchQueryCleaner.ts alongside the main PR's cover-handling enhancements.

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 clearly and specifically summarizes the two main changes: removing modifiers from Spotify queries and improving cover deduplication through broader pattern matching.

✏️ 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/spotify-modifier-query

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.

…lexity

HYPHENATED_VERSION_SUFFIXES already handles '- Cover' via the pattern
added in the previous commit, so VERSION_KEYWORD_RE does not need it.
Removing it brings the regex back under SonarCloud S5843 threshold.
@sonarqubecloud

Copy link
Copy Markdown

@LucasSantana-Dev
LucasSantana-Dev merged commit 435384a into main Apr 13, 2026
12 checks passed
LucasSantana-Dev added a commit that referenced this pull request May 13, 2026
#589)

* fix(autoplay): strip modifiers from Spotify query, broaden cover dedup patterns

- Remove query modifiers ('similar', 'like', 'playlist', 'mix') from the
  Spotify search query — Spotify ignores these and returns 0 results,
  causing unnecessary fallback to YouTube on every non-first replenish cycle
- Broaden cover noise patterns from /(cover version)?/ to /cover[^)]*/
  so '(Cover - ao vivo)', '(Cover by X)' etc. are stripped before coreKey
  computation, enabling dedup to catch cover variants of the now-playing song
- Add 'cover' to HYPHENATED_VERSION_SUFFIXES and VERSION_KEYWORD_RE so
  '- Cover' suffixes are also trimmed by cleanTitle
- Tests: modifier non-append test (2x replenish), cover dedup test,
  6 cleanTitle cover-pattern tests

* fix(autoplay): remove cover from VERSION_KEYWORD_RE to fix S5843 complexity

HYPHENATED_VERSION_SUFFIXES already handles '- Cover' via the pattern
added in the previous commit, so VERSION_KEYWORD_RE does not need it.
Removing it brings the regex back under SonarCloud S5843 threshold.
@LucasSantana-Dev
LucasSantana-Dev deleted the fix/spotify-modifier-query branch May 23, 2026 02:21

This branch was successfully deployed

1 active deployment
Preview — 554204c7 Deployed Apr 13, 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