Repository navigation
fix(autoplay): constrain spotify recs by current track audio features - #605
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
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 33 minutes and 10 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughA new Changes
Sequence DiagramsequenceDiagram
participant QueueMgr as Queue Manager
participant TrackFeatures as Track Audio Features API
participant SpotifyAPI as Spotify Recommendations API
QueueMgr->>TrackFeatures: getTrackAudioFeatures(currentTrackId)
activate TrackFeatures
TrackFeatures-->>QueueMgr: SpotifyAudioFeatures {energy, valence, danceability}
deactivate TrackFeatures
QueueMgr->>QueueMgr: Derive audioConstraints from currentFeatures
QueueMgr->>SpotifyAPI: getSpotifyRecommendations(token, seedIds, limit, audioConstraints)
activate SpotifyAPI
SpotifyAPI->>SpotifyAPI: Compute min_*/max_* bounds (±0.25 tolerance)
SpotifyAPI->>SpotifyAPI: Clamp values to [0, 1] range
SpotifyAPI->>SpotifyAPI: Format to 2 decimal places
SpotifyAPI-->>QueueMgr: Filtered recommendations matching audio constraints
deactivate SpotifyAPI
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 2970-2975: The mock-call assertions for
spotifyApiMock.getSpotifyRecommendations only check token, seed IDs, and limit;
update the assertions to also extract and assert the 4th argument
(audioConstraints) from the first call (e.g., const [callToken, callIds,
callLimit, callAudioConstraints] =
spotifyApiMock.getSpotifyRecommendations.mock.calls[0]!) and assert that
callAudioConstraints matches the expected constraints used in the test; apply
the same additional assertion in the other block around lines 3039-3044 that
validates the second call.
🪄 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: 75cfacee-cfa9-4a3e-88da-bb7887d44832
📒 Files selected for processing (4)
packages/bot/src/spotify/spotifyApi.spec.tspackages/bot/src/spotify/spotifyApi.tspackages/bot/src/utils/music/queueManipulation.spec.tspackages/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: Quality Gates
- GitHub Check: SonarCloud Scan
🔇 Additional comments (3)
packages/bot/src/spotify/spotifyApi.spec.ts (1)
522-576: Strong coverage for constraint query behavior.Constrained params, unconstrained fallback, and clamping are all explicitly validated here. Nice addition for regression safety.
packages/bot/src/utils/music/queueManipulation.ts (1)
375-400: Feature threading and fallback behavior look correct.
currentFeaturesis propagated end-to-end and only translated into Spotify constraints when available, while safely preserving unconstrained behavior otherwise.Also applies to: 773-815, 883-905
packages/bot/src/spotify/spotifyApi.ts (1)
8-12: Constraint mapping implementation is solid.The min/max bounds are conditionally added, clamped to
[0, 1], and keep existing behavior unchanged when constraints are absent.Also applies to: 27-89
|



Problem
Autoplay kept recommending "weird electro music" regardless of what was playing. Root cause: the Spotify
/v1/recommendationsAPI was called with onlyseed_tracksand no audio feature constraints. Spotify's algorithm picks recommendations purely from track audio features, so a reggaeton/forró track with high energy can drift to electro (same energy profile, different genre).Fix
Pass
min_energy/max_energy,min_valence/max_valence, andmin_danceability/max_danceabilityconstraints to the Spotify recommendations call, derived from the current track's audio features (±0.25 tolerance window). These are fetched earlier in the pipeline viagetTrackAudioFeaturesand now forwarded throughcollectRecommendationCandidates→collectSpotifyRecommendationCandidates→getSpotifyRecommendations.When
currentFeaturesis null (no Spotify link, or features unavailable), the call falls back to unconstrained — no behavior change for those cases.Changes
spotifyApi.ts:getSpotifyRecommendationsaccepts optionalSpotifyAudioFeatureConstraints(energy, valence, danceability) and appends min/max bounds to the API requestqueueManipulation.ts: threadcurrentFeaturesfrom the replenish call site down to the Spotify recommendations functionspotifyApi.spec.ts: constraints passed correctly, unconstrained when undefined, bounds clamped to [0,1]queueManipulation.spec.ts: flexible assertions for the new 4th argChecklist
Bump: v2.6.119
Summary by CodeRabbit
New Features
Tests