Repository navigation
fix(autoplay): hard genre-family penalty prevents rap → electronic drift - #639
Conversation
- Add getArtistGenres to spotifyApi.ts with Spotify artist search + caching - Define 10 genre families (rap_hiphop, electronic, latin, rock_metal, etc) - Implement calculateGenreFamilyPenalty: -0.6 for strong genre anchors (rap, rock, latin) crossing to different family, -0.3 for weak anchors, 0 for overlaps - Integrate genre penalty into enrichWithAudioFeatures post-scoring - Fetch candidate genres and apply penalty dynamically during audio feature enrichment - Fixes 2Pac → electronic drift (user report) Genre families: - rap_hiphop: hip hop, rap, trap, drill - electronic: edm, house, techno, trance, dubstep - latin: reggaeton, forró, samba, bossa nova, latin trap - rock_metal: rock, metal, punk, grunge, alternative + 6 more (pop, rnb_soul, country_folk, jazz_classical, world, ambient_chill) Scoring: - Same family overlap → 0 penalty (no drift) - Disjoint families with strong genre anchor → -0.6 penalty (dominates energy match) - Disjoint families with weak anchor → -0.3 penalty - Unknown genres → -0.1 safety penalty (fallback to audio features)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe PR adds language-aware music recommendation filtering, artist genre retrieval with caching, and genre-family-based track enrichment scoring. It introduces Spanish language detection heuristics, applies penalties to Spanish tracks in non-Spanish sessions, caches artist genre data from Spotify, and enhances queue candidate scoring by analyzing genre family alignment between current and candidate artists. Changes
Sequence DiagramssequenceDiagram
participant Session as Session<br/>(Tracks)
participant LangDetect as Language<br/>Detection
participant RecommendEngine as Recommendation<br/>Engine
participant Penalty as Spanish<br/>Penalty Filter
participant Blend as Blend<br/>Recommendations
Session->>LangDetect: recentHistory tracks
LangDetect->>LangDetect: detect Spanish markers<br/>(accents, stopwords, genres)
LangDetect->>RecommendEngine: hasSpanish boolean
RecommendEngine->>Penalty: primaryRecommendations +<br/>hasSpanish flag
Penalty->>Penalty: apply score penalties<br/>to Spanish tracks<br/>(non-Spanish session)
Penalty->>RecommendEngine: filtered recommendations
RecommendEngine->>Blend: filtered primary +<br/>additionalSeeds +<br/>hasSpanish flag
Blend->>Blend: for each seed:<br/>apply penalty filter
Blend->>Blend: merge & sort<br/>by score (descending)
Blend->>RecommendEngine: final blended results
sequenceDiagram
participant Candidate as Candidate<br/>Track
participant Enricher as Queue<br/>Enrichment
participant SpotifyAPI as Spotify<br/>API
participant GenreCache as Genre<br/>Cache
participant Scorer as Genre<br/>Family Scorer
Candidate->>Enricher: candidate artist
Enricher->>SpotifyAPI: fetch current artist<br/>genres (once per session)
SpotifyAPI->>GenreCache: check cache
GenreCache->>SpotifyAPI: return cached or<br/>search Spotify
SpotifyAPI->>Enricher: current genres
Enricher->>SpotifyAPI: fetch candidate artist<br/>genres (per candidate)
SpotifyAPI->>GenreCache: check cache
GenreCache->>Enricher: candidate genres
Enricher->>Scorer: compare genre families
Scorer->>Scorer: map genres to families
Scorer->>Scorer: calculate alignment<br/>penalty
Scorer->>Enricher: penalty score
Enricher->>Enricher: adjust candidate score +<br/>append drift reason
Enricher->>Candidate: enriched with score
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 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 docstrings
🧪 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 |
Mock getArtistGenres to return matching genres for current and candidate tracks, preventing unknown-genre penalty from interfering with the energy/valence boost assertion.
|
Size Change: 0 B Total Size: 330 kB ℹ️ View Unchanged
|
…ta.popularity
- Lines 108, 153, 170: Cast rec.track.metadata to TrackMetadata interface
- Fixes TS2339 errors: Property 'tags'/'popularity' does not exist on type '{}'
…penalty - Export & test getGenreFamilies, calculateGenreFamilyPenalty, enrichWithAudioFeatures - Add 21 tests covering all 10 genre families, penalty edge cases, empty states - Export & test applySpanishLanguagePenalty & blendRecommendations - Add 12 tests for Spanish detection, mixed batches, score sorting, filtering - Add 7 tests for getArtistGenres API error handling & cache behavior - Total 40+ new tests across 3 spec files - All tests green: 2582 passed
|
…ift (#639) * fix(autoplay): hard genre-family penalty prevents rap → electronic drift - Add getArtistGenres to spotifyApi.ts with Spotify artist search + caching - Define 10 genre families (rap_hiphop, electronic, latin, rock_metal, etc) - Implement calculateGenreFamilyPenalty: -0.6 for strong genre anchors (rap, rock, latin) crossing to different family, -0.3 for weak anchors, 0 for overlaps - Integrate genre penalty into enrichWithAudioFeatures post-scoring - Fetch candidate genres and apply penalty dynamically during audio feature enrichment - Fixes 2Pac → electronic drift (user report) Genre families: - rap_hiphop: hip hop, rap, trap, drill - electronic: edm, house, techno, trance, dubstep - latin: reggaeton, forró, samba, bossa nova, latin trap - rock_metal: rock, metal, punk, grunge, alternative + 6 more (pop, rnb_soul, country_folk, jazz_classical, world, ambient_chill) Scoring: - Same family overlap → 0 penalty (no drift) - Disjoint families with strong genre anchor → -0.6 penalty (dominates energy match) - Disjoint families with weak anchor → -0.3 penalty - Unknown genres → -0.1 safety penalty (fallback to audio features) * chore: bump version to 2.6.125 (artists grid UX tweaks + backend SPOTIFY env) (#638) * fix: mock overlapping genres in energy/valence boost test Mock getArtistGenres to return matching genres for current and candidate tracks, preventing unknown-genre penalty from interfering with the energy/valence boost assertion. * fix(autoplay): hard-reject Spanish tracks when session has no Spanish markers * fix: add TrackMetadata type for ts errors on metadata.tags and metadata.popularity - Lines 108, 153, 170: Cast rec.track.metadata to TrackMetadata interface - Fixes TS2339 errors: Property 'tags'/'popularity' does not exist on type '{}' * test: add comprehensive coverage for genre family & Spanish language penalty - Export & test getGenreFamilies, calculateGenreFamilyPenalty, enrichWithAudioFeatures - Add 21 tests covering all 10 genre families, penalty edge cases, empty states - Export & test applySpanishLanguagePenalty & blendRecommendations - Add 12 tests for Spanish detection, mixed batches, score sorting, filtering - Add 7 tests for getArtistGenres API error handling & cache behavior - Total 40+ new tests across 3 spec files - All tests green: 2582 passed



Summary
Fixes autoplay genre drift (2Pac hip-hop → electronic music) by adding weighted genre-family penalty that dominates audio feature scoring.
Changes
Testing
Manual verification: 2Pac (hip-hop) candidate will now see -0.6 penalty when electronic candidate arrives, preventing selection despite energy match.
References
Summary by CodeRabbit
Release Notes
New Features