Skip to content

feat(bot): prioritize Spotify source in autoplay search and scoring - #585

Merged
LucasSantana-Dev merged 1 commit into
mainfrom
fix/autoplay-spotify-priority
Apr 13, 2026
Merged

LucasSantana-Dev merged 1 commit into
mainfrom
fix/autoplay-spotify-priority

Conversation

@LucasSantana-Dev

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

Copy link
Copy Markdown
Owner

Problem

Autoplay was falling back to YouTube silently because:

  1. The Spotify search query contained duplicated artist names (e.g. "Beyoncé - Halo Beyoncé" for seed title "Beyoncé - Halo") → Spotify returned 0 results → silent YouTube fallback
  2. Spotify-sourced tracks had no score advantage over equivalent YouTube tracks — and were even penalized (-0.25) when the current track was also from Spotify

Changes

Better Spotify query (searchSeedCandidates)

Uses extractSongCore + cleanAuthor to build a clean query for the Spotify engine:

  • "Ed Sheeran - Shape of You" → Spotify query: "Shape of You Ed Sheeran" (was: "Ed Sheeran - Shape of You Ed Sheeran")
  • "Beyoncé - Halo" (author: BeyoncéVEVO) → Spotify query: "Halo Beyoncé" (was: "Beyoncé - Halo Beyoncé")
  • YouTube/AUTO fallback engines still use the original query

Spotify source preference in scoring (calculateRecommendationScore)

  • Removed the same-source penalty (-0.25) when both current and candidate are Spotify — this was actively penalizing Spotify tracks
  • Replaced the narrow +0.08 "spotify mood match" (only when both tracks were Spotify) with a general +0.15 "spotify preferred" boost for any Spotify candidate

Net effect: Spotify candidates now score +0.15 higher than equivalent YouTube candidates. When Spotify has the track, it wins.

Tests

  • New: Spotify engine receives clean song-core query for artist-prefixed seed titles
  • New: Spotify candidate is selected over identical YouTube candidate
  • Updated: existing "boosts candidates when both current and candidate are from spotify" test updated to reflect new reason label

Summary by CodeRabbit

  • Tests

    • Added test coverage for Spotify search query construction and track prioritization behavior.
  • Improvements

    • Enhanced Spotify search query handling for better track matching.
    • Updated recommendation scoring to prioritize Spotify sources in queue selection.

@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 1:55pm

@coderabbitai

coderabbitai Bot commented Apr 13, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b4f3b7ed-403e-44c8-91c0-5cdd3410180d

📥 Commits

Reviewing files that changed from the base of the PR and between 791b0f3 and d4b8cf8.

📒 Files selected for processing (2)
  • packages/bot/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/utils/music/queueManipulation.ts
📜 Recent 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: Quality Gates
  • GitHub Check: SonarCloud Scan
🔇 Additional comments (7)
packages/bot/src/utils/music/queueManipulation.spec.ts (3)

2900-2903: LGTM!

The assertion correctly reflects the updated scoring reason from 'spotify mood match' to 'spotify preferred', matching the implementation change in calculateRecommendationScore.


3255-3278: LGTM!

The test correctly validates the Spotify song-core query construction:

  • Seeds with artist-prefixed titles (e.g., "Ed Sheeran - Shape of You") should produce clean queries like "Shape of You Ed Sheeran" rather than duplicated patterns like "Ed Sheeran - Shape of You Ed Sheeran".
  • The negative assertion at line 3275 combined with positive assertions at lines 3276-3277 comprehensively verifies the expected query format.

3280-3319: LGTM!

The test correctly validates that Spotify candidates receive preferential scoring over equivalent YouTube candidates. With identical track metadata, the +0.15 'spotify preferred' boost ensures the Spotify track is selected first.

The mock setup at line 3306 (size: 7 with empty toArray) is intentional to control missingTracks = 1 while keeping exclusion sets empty, allowing both candidates to be considered.

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

782-789: LGTM!

The Spotify-specific query construction correctly:

  1. Extracts the song core from artist-prefixed titles (e.g., "Ed Sheeran - Shape of You" → "Shape of You").
  2. Cleans the author to remove VEVO/Topic suffixes.
  3. Falls back to baseQuery when extractSongCore returns a falsy value.

This prevents duplicate artist names in queries like "Beyoncé - Halo Beyoncé".


797-828: LGTM!

The engine-specific query selection correctly applies spotifyQuery only for QueryType.SPOTIFY_SEARCH while preserving the original query for YouTube and AUTO engines. The debug/warn logs at lines 819 and 827 accurately report the actual query used.


1570-1577: LGTM!

The scoring logic correctly removes the -0.25 same-source penalty specifically for Spotify tracks while preserving it for other sources. This ensures Spotify-to-Spotify transitions aren't penalized, aligning with the goal of prioritizing Spotify as a source.


1630-1633: LGTM!

The unconditional +0.15 boost for Spotify candidates achieves the intended prioritization. Combined with the removed same-source penalty (lines 1570-1573), this produces the expected net scoring advantage:

  • Spotify candidate (any context): +0.15
  • Previously Spotify-to-Spotify: -0.25 + 0.08 = -0.17

The change ensures Spotify tracks are preferred when available, as stated in the PR objectives.


📝 Walkthrough

Walkthrough

Updated music queue manipulation to prioritize Spotify tracks during autoplay candidate selection. Modified searchSeedCandidates to construct Spotify-specific search queries using extracted song cores, and adjusted calculateRecommendationScore to reward Spotify candidates with higher scores and remove penalties for matching Spotify sources. Added corresponding test coverage.

Changes

Cohort / File(s) Summary
Test Coverage
packages/bot/src/utils/music/queueManipulation.spec.ts
Updated existing Spotify scoring metadata expectation (spotify mood match → spotify preferred) and added new "Spotify priority" test suite validating Spotify-specific search query construction using song-core format and preferential selection of Spotify tracks over YouTube alternatives.
Queue Manipulation Logic
packages/bot/src/utils/music/queueManipulation.ts
Modified searchSeedCandidates to build engine-specific queries for Spotify using extracted song cores. Updated calculateRecommendationScore to boost Spotify candidate scores from +0.08 to +0.15, remove source-match penalties for Spotify, and broaden Spotify mood-match eligibility to trigger whenever candidate source is Spotify regardless of current track source.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

bot, enhancement, 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 pull request title directly and clearly summarizes the main objective: prioritizing Spotify in autoplay search and scoring logic.

✏️ 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-spotify-priority

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.

@sonarqubecloud

Copy link
Copy Markdown

@LucasSantana-Dev
LucasSantana-Dev merged commit 31f45f1 into main Apr 13, 2026
12 checks passed
@LucasSantana-Dev
LucasSantana-Dev deleted the fix/autoplay-spotify-priority branch April 13, 2026 13:59

This branch was successfully deployed

1 active deployment
Preview — d4b8cf80 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

Labels

bot enhancement New feature or request size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant