Repository navigation
feat: LLM-guided discovery mode for AI auto-playlist - #96
ErfanBagheri404 wants to merge 5 commits into
Conversation
#49) - modules/aiMixPlaylist.ts: seed = most recent play, pool = liked + recent + replay top tracks deduped, scoring via buildSmartQueue + loadPlayCounts - stable AI_MIX_ID so regenerating replaces the mix; user playlists untouched - null when history is too thin — nothing stored, the alert says so - FullPlayerModal: sparkle button in the track row, lazy import, Alert for both outcomes - locale: player.aiMixTitle/aiMixReady/aiMixEmpty in en+fa - regression: tests/ai-mix-regression.cjs 12/12, sabotage-verified
Two real defects in the AI Mix generator: - candidatePool took a third list built from the play-count summary, but those ids all come from liked/recent, so the dedupe dropped every one of them. The resolution loop is deleted; the counts are still passed to buildSmartQueue for scoring. - Regenerate read loadPlaylists() twice and routed the create path through addPlaylist, which re-reads the list internally. A playlist the user made between the first and second read was silently lost. Read once, write once with savePlaylists. Tests: 3 new regressions covering read/write counts, survival of an externally added playlist, and the absence of the top-tracks list. 15/15 pass; 4 sabotage mutations all caught.
…evice fallback - aiMixGenerator: Pollinations text API (anonymous, no key) turns listening history into search queries; app search resolves them; deterministic scoring picks tracks. openai -> mistral fallback, then on-device mix. - aiMixPlaylist: shared persistAiMix, exported pickSeed - FullPlayerModal button now calls generateAiMixWithDiscovery - 12 new regression checks (26/26), e2e harness for the live endpoint
Pollinations retired the 'mistral' alias (HTTP 404) and now serves a single anonymous model, 'openai-fast', behind the 'openai' alias. Walk the alias first, then the canonical id, so a retired alias does not cost a whole run. Probed live: mistral 404, openai 200.
Reviewer's GuideThis PR adds a lazy, localized discovery action to the player that asks an anonymous Pollinations model for bounded search queries based on listening history, resolves those queries through the existing search API, and deterministically scores and persists new tracks in the stable @ai_mix playlist; failures fall back to the existing on-device generator, with extensive contract, regression, and live E2E coverage. Sequence diagram for AI discovery mix generationsequenceDiagram
actor User
participant Player as FullPlayerModal
participant Generator as aiMixGenerator
participant Stats as listeningStats
participant LLM as Pollinations
participant Search as searchAPI
participant Storage as StorageService
User->>Player: handleAiMix()
Player->>Generator: generateAiMixWithDiscovery(language)
Generator->>Stats: loadReplaySummary(alltime)
Generator->>Storage: loadLikedSongs() and loadPreviouslyPlayedSongs()
Generator->>Generator: pickSeed(liked, recent)
Generator->>LLM: fetchSearchQueries(prompt)
LLM-->>Generator: JSON search queries
Generator->>Search: resolveQueries(queries)
Search-->>Generator: discovery candidates
Generator->>Generator: buildSmartQueue(seed, candidates, playCounts)
Generator->>Storage: persistAiMix(discovered, language)
Storage-->>Generator: Playlist(@ai_mix)
Generator-->>Player: Playlist or null
Player-->>User: Alert.alert(AI Mix ready or empty)
Flow diagram for AI discovery fallback chainflowchart TD
Start[User taps AI Mix] --> Seed[Load listening history and pickSeed]
Seed --> HasSeed{Seed available?}
HasSeed -- No --> Empty[Return null]
HasSeed -- Yes --> Alias[fetchSearchQueries with openai alias]
Alias --> Queries{Queries returned?}
Queries -- No --> Canonical[fetchSearchQueries with openai-fast]
Canonical --> Queries2{Queries returned?}
Queries2 -- No --> Local[generateAiMixPlaylist]
Queries -- Yes --> Resolve[resolveQueries via searchAPI]
Queries2 -- Yes --> Resolve
Resolve --> Enough{At least 8 candidates?}
Enough -- No --> Local
Enough -- Yes --> Score[buildSmartQueue]
Score --> Scored{At least 8 tracks scored?}
Scored -- No --> Local
Scored -- Yes --> Persist[persistAiMix as @ai_mix]
Local --> Result[Return playlist or null]
Persist --> Result
Empty --> Result
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 54 minutes. View limit details
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. |
There was a problem hiding this comment.
Hey - I've found 14 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="modules/aiMixPlaylist.ts" line_range="23" />
<code_context>
+ // Read once, write once. addPlaylist re-reads the list internally, so
+ // going through it here would race another writer's change; and reading
+ // twice (once for `existing`, once for `rest`) lets the two disagree.
+ const stored = await StorageService.loadPlaylists();
+ const existing = stored.find((p) => p.id === AI_MIX_ID);
+ const playlist: Playlist = {
</code_context>
<issue_to_address>
**Existing playlists can be erased**
When `StorageService.loadPlaylists()` encounters a read or parse error, `persistAiMix` treats the returned empty array as a successful read and saves only the AI Mix, overwriting the user's other playlists.
Distinguish a failed playlist read from a valid empty list and do not save a replacement after a failed read.
</issue_to_address>
### Comment 2
<location path="modules/aiMixPlaylist.ts" line_range="23-39" />
<code_context>
+ const stored = await StorageService.loadPlaylists();
</code_context>
<issue_to_address>
**Concurrent playlist changes disappear**
When another playlist writer or AI Mix generation saves between `persistAiMix` loading and saving the list, `persistAiMix` saves its earlier snapshot over the concurrent change, so the user's playlist edit or newer mix disappears.
Serialize playlist read-modify-write operations or use an atomic update that preserves concurrent changes.
</issue_to_address>
### Comment 3
<location path="modules/aiMixGenerator.ts" line_range="201" />
<code_context>
+ continue;
+ }
+ for (const t of results) {
+ if (!t?.id || !t.title || seen.has(String(t.id))) continue;
+ seen.add(String(t.id));
+ found.push(t);
</code_context>
<issue_to_address>
**Known tracks enter discovery mix**
When a search query returns a track the user has liked or previously played, `resolveQueries` passes the track to `buildSmartQueue`, which excludes only the seed and can include the already-known track in the discovery mix.
Exclude liked and previously played track IDs from discovery candidates before scoring them.
Also at `modules/aiMixGenerator.ts:258`, `modules/aiMixGenerator.ts:268-273`.
</issue_to_address>
### Comment 4
<location path="modules/aiMixGenerator.ts" line_range="268-273" />
<code_context>
+
+ // Seed scoring gives the discovery pool taste; new tracks have no play
+ // history, so playCounts only discriminates tracks the user already has.
+ const discovered = buildSmartQueue({
+ seed,
+ library: candidates,
+ size: 30,
+ playCounts,
+ });
+ if (discovered.length < MIN_DISCOVERY_TRACKS) {
+ console.log("[aiMix] scoring kept too little, falling back to on-device mix");
</code_context>
<issue_to_address>
**Unrelated tracks enter discovery mix**
When discovery queries return enough candidates with no meaningful artist or title overlap with the seed, `buildSmartQueue` gives every candidate a positive liked-track baseline, so unrelated search results remain eligible and can be included instead of triggering fallback.
Require meaningful similarity to the seed before accepting discovery candidates, and fall back when too few qualify.
</issue_to_address>
### Comment 5
<location path="modules/aiMixGenerator.ts" line_range="195" />
<code_context>
+ for (const query of queries.slice(0, MAX_QUERIES)) {
+ let results: Track[] = [];
+ try {
+ results = await search(query);
+ } catch {
+ // one dead query source must not sink the batch
</code_context>
<issue_to_address>
**A hanging search stalls generation**
When a search request remains pending instead of resolving or rejecting, `resolveQueries` awaits each search without a deadline, so it never reaches the remaining queries or on-device fallback and the generating indicator stays active indefinitely.
Give search requests a deadline so a stalled request can be skipped and generation can continue.
</issue_to_address>
### Comment 6
<location path="components/FullPlayerModal.tsx" line_range="1683-1693" />
<code_context>
+ const { generateAiMixWithDiscovery } = await import(
+ "../modules/aiMixGenerator"
+ );
+ const mix = await generateAiMixWithDiscovery(
+ language === "fa" ? "fa" : "en",
+ );
+ // null = not enough history to curate from. The icon stops spinning and
+ // the user is still looking at the player, so the alert carries the
+ // outcome — the same pattern the credits sheet already uses here.
+ Alert.alert(
+ t("player.aiMixTitle"),
+ t(mix ? "player.aiMixReady" : "player.aiMixEmpty"),
+ );
+ } finally {
+ setIsGeneratingAiMix(false);
+ }
</code_context>
<issue_to_address>
**Failed generation gives no outcome**
When playlist persistence or another uncaught generator operation rejects, `handleAiMix` runs only its `finally` block, clears the spinner, and lets the rejection escape without showing an alert, so the user receives no outcome.
Catch generation and persistence errors in `handleAiMix` and show an alert describing the failure.
Also at `modules/aiMixGenerator.ts:282`.
</issue_to_address>
### Comment 7
<location path="modules/aiMixPlaylist.ts" line_range="39" />
<code_context>
+ // Replace in place, keep every other playlist, and put the mix first so
+ // it stays where the user expects it.
+ const rest = stored.filter((p) => p.id !== AI_MIX_ID);
+ await StorageService.savePlaylists([playlist, ...rest]);
+ return playlist;
+}
</code_context>
<issue_to_address>
**Saved mix may not refresh the library**
When the metadata-cache update fails after the playlist write succeeds, `savePlaylists` rejects after storing the mix but before updating the metadata cache and emitting the library event, so the library may not refresh and the player shows no result alert.
Keep the metadata cache and library event consistent when a playlist write succeeds, even if the cache update initially fails.
Also at `components/FullPlayerModal.tsx:1693-1695`.
</issue_to_address>
### Comment 8
<location path="modules/aiMixGenerator.ts" line_range="240-241" />
<code_context>
+ const [{ artists, tracks: trackNames }, liked, recent, playCounts] =
+ await Promise.all([
+ loadHistoryNames(),
+ StorageService.loadLikedSongs(),
+ StorageService.loadPreviouslyPlayedSongs(),
+ loadPlayCounts(),
+ ]);
</code_context>
<issue_to_address>
**History read failures look like no history**
When reading liked songs or previously played songs fails while the user has history, `StorageService` returns empty arrays, so `pickSeed` returns `null` and generation reports an empty-history outcome instead of a read failure.
Propagate history read errors or distinguish them from valid empty lists before deciding there is no seed.
Also at `modules/aiMixGenerator.ts:248`.
</issue_to_address>
### Comment 9
<location path="modules/aiMixGenerator.ts" line_range="210-220" />
<code_context>
+}
+
+/** Default resolver: YouTube Music via the existing search surface. */
+async function defaultSearch(query: string): Promise<Track[]> {
+ const result = await searchAPI.searchWithYouTubeMusic(query, "all", 1, SEARCH_LIMIT);
+ const items = result?.items || [];
+ return items.map((item: any) => ({
+ id: String(item.id),
+ title: item.title || "",
+ artist: item.author || item.artist || "",
+ thumbnail: item.img || item.thumbnailUrl || item.thumbnail,
+ url: item.href,
+ source: "youtubemusic",
+ })) as Track[];
+}
+
</code_context>
<issue_to_address>
**Discovery searches only one catalog**
When a discovery track is available from another supported search catalog but not YouTube Music, `defaultSearch` calls only `searchWithYouTubeMusic`, so tracks from the other mixed-search providers never enter the candidate pool.
Use the app's mixed search providers to resolve discovery queries.
</issue_to_address>
### Comment 10
<location path="modules/aiMixPlaylist.ts" line_range="105-113" />
<code_context>
+ }
+
+ const pool = candidatePool(liked, recent);
+ const tracks = buildSmartQueue({
+ seed,
+ library: pool,
+ size: MIX_SIZE,
+ playCounts,
+ });
+ if (!tracks.length) {
+ return null;
+ }
+
+ return persistAiMix(tracks, language);
</code_context>
<issue_to_address>
**Small history pool reports empty mix**
When the user has some liked or recently played tracks but fewer than five distinct tracks, and discovery cannot produce a usable mix, `buildSmartQueue` returns no tracks for the small pool, so the on-device path and discovery fallback return `null` and the player reports an empty-history outcome despite existing history.
Handle a nonempty but undersized history pool without treating it as no listening history.
Also at `modules/aiMixGenerator.ts:255`, `modules/aiMixGenerator.ts:275-277`.
</issue_to_address>
### Comment 11
<location path="modules/aiMixGenerator.ts" line_range="74-75" />
<code_context>
+ : "These are what I listen to most:";
+ return [
+ head,
+ `Top artists: ${artists.slice(0, 10).join(", ")}`,
+ `Top tracks: ${tracks.slice(0, 15).join("; ")}`,
+ buildHistoryPrompt(language),
+ ].join("\n");
</code_context>
<issue_to_address>
**Listening history sent to third party**
When the user taps the AI Mix button with listening history available, `loadHistoryNames` puts ranked artist and track names into the prompt, and `fetchFrom` posts it to Pollinations. The player tells the user only that an AI Mix is being generated, so they are not informed that personal listening preferences leave the device and are sent to an external service.
Disclose the third-party transfer and obtain informed opt-in before sending history names, or keep the history-based generation on-device.
Also at `modules/aiMixGenerator.ts:128`.
</issue_to_address>
### Comment 12
<location path="tests/ai-mix-discovery-e2e.cjs" line_range="6-8" />
<code_context>
+ *
+ * NOT a hermetic regression test — it hits text.pollinations.ai over the
+ * network and asserts the real response parses into real search queries.
+ * Exits 0 if the discovery path works OR if it cleanly falls back (both
+ * are valid product outcomes); logs which happened. Fails only if the
+ * call throws uncaught or a track slips through from the wrong pool.
+ */
+const assert = require('node:assert/strict');
</code_context>
<issue_to_address>
**Live discovery test accepts fallback**
When the generator always falls back, or the live endpoint returns no usable queries, `main` in `ai-mix-discovery-e2e.cjs` accepts any nonempty mix at line 93 and labels fallback a pass at line 114; the real queries are only logged at lines 100–103, so this test passes without verifying that the live response parsed or discovery ran.
Assert that live queries were produced and require a discovery result when the endpoint responds; report endpoint unavailability as skipped rather than as a passing discovery check.
</issue_to_address>
### Comment 13
<location path="tests/ai-mix-regression.cjs" line_range="358-364" />
<code_context>
+
+ await check('discovery: LLM queries resolve to a pinned mix of NEW tracks', async () => {
+ resetDiscovery();
+ const mix = await GEN.generateAiMixWithDiscovery('en', { fetchImpl: llmFetch, search: discoverySearch });
+ assert.ok(mix, 'expected a mix');
+ assert.equal(mix.id, MIX.AI_MIX_ID);
+ assert.equal(llmCalls, 1, 'the LLM must be called exactly once');
+ // Every track came from discovery, none from the user's library.
+ assert.ok(mix.tracks.length >= 8, 'expected a real discovery pool');
+ assert.ok(mix.tracks.every((t) => t.id.startsWith('d')), 'mix must be new tracks only');
+ assert.equal(playlists.filter((p) => p.id === MIX.AI_MIX_ID).length, 1);
+ });
</code_context>
<issue_to_address>
**Mock search ignores generated queries**
When the generator calls the injected search with a constant or empty query instead of the parsed LLM output, in `discovery: LLM queries resolve to a pinned mix of NEW tracks`, `discoverySearch` at line 183 returns the same results for every input, so the assertions at lines 358–364 pass even if the generator ignores the LLM queries and searches with a constant or empty string.
Capture the query arguments in `discoverySearch` and assert they match the queries parsed from the mocked LLM response.
</issue_to_address>
### Comment 14
<location path="tests/ai-mix-regression.cjs" line_range="394-400" />
<code_context>
+ assert.equal(long[0].length, 80);
+ });
+
+ await check('discovery: a failed LLM call falls back to the on-device mix', async () => {
+ resetDiscovery();
+ llmStatus = 500;
+ const mix = await GEN.generateAiMixWithDiscovery('en', { fetchImpl: llmFetch, search: discoverySearch });
+ assert.ok(mix, 'fallback must still produce a mix');
+ // On-device mix draws from the user's library, not discovery ids.
+ assert.ok(mix.tracks.every((t) => !t.id.startsWith('d')), 'fallback must be the on-device mix');
+ });
+
</code_context>
<issue_to_address>
**Fallback tests accept empty mixes**
When the fallback returns a playlist whose track list is empty, when a fallback returns a non-null playlist with `tracks: []`, the failed-LLM, unparseable-response, and thin-discovery checks pass because `.every(...)` is true for an empty array; the throwing-search check only asserts `mix` is truthy. These tests pass without a usable fallback mix.
Assert that each fallback mix contains at least one track before checking that its tracks came from the on-device pool.
Also at `tests/ai-mix-regression.cjs:403-408`, `tests/ai-mix-regression.cjs:411-416`, `tests/ai-mix-regression.cjs:419-425`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 14 findings to address first, and the feature sends users' top artist and track names to an anonymous third-party LLM service and persists its resulting playlist locally. Reverting can remove the feature and playlist, but it cannot retract listening-history data already disclosed to the external service, and an incorrect generated mix may remain until it is replaced or deleted.
Blocking findings: modules/aiMixPlaylist.ts:23, modules/aiMixPlaylist.ts:39, modules/aiMixGenerator.ts:201, modules/aiMixGenerator.ts:273, modules/aiMixGenerator.ts:195, and 9 more
| // Read once, write once. addPlaylist re-reads the list internally, so | ||
| // going through it here would race another writer's change; and reading | ||
| // twice (once for `existing`, once for `rest`) lets the two disagree. | ||
| const stored = await StorageService.loadPlaylists(); |
There was a problem hiding this comment.
🔴 Critical · Existing playlists can be erased
When StorageService.loadPlaylists() encounters a read or parse error, persistAiMix treats the returned empty array as a successful read and saves only the AI Mix, overwriting the user's other playlists.
Distinguish a failed playlist read from a valid empty list and do not save a replacement after a failed read.
Prompt for AI agents
In `modules/aiMixPlaylist.ts` at line 23:
**Existing playlists can be erased**
When `StorageService.loadPlaylists()` encounters a read or parse error, `persistAiMix` treats the returned empty array as a successful read and saves only the AI Mix, overwriting the user's other playlists.
Distinguish a failed playlist read from a valid empty list and do not save a replacement after a failed read.| const stored = await StorageService.loadPlaylists(); | ||
| const existing = stored.find((p) => p.id === AI_MIX_ID); | ||
| const playlist: Playlist = { | ||
| id: AI_MIX_ID, | ||
| name: aiMixName(language), | ||
| description: language === "fa" ? "از تاریخچه پخش شما" : "Built from your listening history", | ||
| tracks, | ||
| createdAt: existing?.createdAt ?? now, | ||
| updatedAt: now, | ||
| // The top track's art doubles as the cover: a real image beats a | ||
| // placeholder glyph, and it changes as the mix does. | ||
| thumbnail: tracks[0]?.thumbnail, | ||
| }; | ||
| // Replace in place, keep every other playlist, and put the mix first so | ||
| // it stays where the user expects it. | ||
| const rest = stored.filter((p) => p.id !== AI_MIX_ID); | ||
| await StorageService.savePlaylists([playlist, ...rest]); |
There was a problem hiding this comment.
🟠 High · Concurrent playlist changes disappear
When another playlist writer or AI Mix generation saves between persistAiMix loading and saving the list, persistAiMix saves its earlier snapshot over the concurrent change, so the user's playlist edit or newer mix disappears.
Serialize playlist read-modify-write operations or use an atomic update that preserves concurrent changes.
Prompt for AI agents
In `modules/aiMixPlaylist.ts` at lines 23-39:
**Concurrent playlist changes disappear**
When another playlist writer or AI Mix generation saves between `persistAiMix` loading and saving the list, `persistAiMix` saves its earlier snapshot over the concurrent change, so the user's playlist edit or newer mix disappears.
Serialize playlist read-modify-write operations or use an atomic update that preserves concurrent changes.| continue; | ||
| } | ||
| for (const t of results) { | ||
| if (!t?.id || !t.title || seen.has(String(t.id))) continue; |
There was a problem hiding this comment.
🟠 High · Known tracks enter discovery mix
When a search query returns a track the user has liked or previously played, resolveQueries passes the track to buildSmartQueue, which excludes only the seed and can include the already-known track in the discovery mix.
Exclude liked and previously played track IDs from discovery candidates before scoring them.
Also at modules/aiMixGenerator.ts:258, modules/aiMixGenerator.ts:268-273.
Prompt for AI agents
In `modules/aiMixGenerator.ts` at line 201:
**Known tracks enter discovery mix**
When a search query returns a track the user has liked or previously played, `resolveQueries` passes the track to `buildSmartQueue`, which excludes only the seed and can include the already-known track in the discovery mix.
Exclude liked and previously played track IDs from discovery candidates before scoring them.
Also at `modules/aiMixGenerator.ts:258`, `modules/aiMixGenerator.ts:268-273`.| const discovered = buildSmartQueue({ | ||
| seed, | ||
| library: candidates, | ||
| size: 30, | ||
| playCounts, | ||
| }); |
There was a problem hiding this comment.
🟡 Medium · Unrelated tracks enter discovery mix
When discovery queries return enough candidates with no meaningful artist or title overlap with the seed, buildSmartQueue gives every candidate a positive liked-track baseline, so unrelated search results remain eligible and can be included instead of triggering fallback.
Require meaningful similarity to the seed before accepting discovery candidates, and fall back when too few qualify.
Prompt for AI agents
In `modules/aiMixGenerator.ts` at lines 268-273:
**Unrelated tracks enter discovery mix**
When discovery queries return enough candidates with no meaningful artist or title overlap with the seed, `buildSmartQueue` gives every candidate a positive liked-track baseline, so unrelated search results remain eligible and can be included instead of triggering fallback.
Require meaningful similarity to the seed before accepting discovery candidates, and fall back when too few qualify.| for (const query of queries.slice(0, MAX_QUERIES)) { | ||
| let results: Track[] = []; | ||
| try { | ||
| results = await search(query); |
There was a problem hiding this comment.
🟡 Medium · A hanging search stalls generation
When a search request remains pending instead of resolving or rejecting, resolveQueries awaits each search without a deadline, so it never reaches the remaining queries or on-device fallback and the generating indicator stays active indefinitely.
Give search requests a deadline so a stalled request can be skipped and generation can continue.
Prompt for AI agents
In `modules/aiMixGenerator.ts` at line 195:
**A hanging search stalls generation**
When a search request remains pending instead of resolving or rejecting, `resolveQueries` awaits each search without a deadline, so it never reaches the remaining queries or on-device fallback and the generating indicator stays active indefinitely.
Give search requests a deadline so a stalled request can be skipped and generation can continue.| const tracks = buildSmartQueue({ | ||
| seed, | ||
| library: pool, | ||
| size: MIX_SIZE, | ||
| playCounts, | ||
| }); | ||
| if (!tracks.length) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
🟡 Medium · Small history pool reports empty mix
When the user has some liked or recently played tracks but fewer than five distinct tracks, and discovery cannot produce a usable mix, buildSmartQueue returns no tracks for the small pool, so the on-device path and discovery fallback return null and the player reports an empty-history outcome despite existing history.
Handle a nonempty but undersized history pool without treating it as no listening history.
Also at modules/aiMixGenerator.ts:255, modules/aiMixGenerator.ts:275-277.
Prompt for AI agents
In `modules/aiMixPlaylist.ts` at lines 105-113:
**Small history pool reports empty mix**
When the user has some liked or recently played tracks but fewer than five distinct tracks, and discovery cannot produce a usable mix, `buildSmartQueue` returns no tracks for the small pool, so the on-device path and discovery fallback return `null` and the player reports an empty-history outcome despite existing history.
Handle a nonempty but undersized history pool without treating it as no listening history.
Also at `modules/aiMixGenerator.ts:255`, `modules/aiMixGenerator.ts:275-277`.| `Top artists: ${artists.slice(0, 10).join(", ")}`, | ||
| `Top tracks: ${tracks.slice(0, 15).join("; ")}`, |
There was a problem hiding this comment.
🟡 Medium · Listening history sent to third party
When the user taps the AI Mix button with listening history available, loadHistoryNames puts ranked artist and track names into the prompt, and fetchFrom posts it to Pollinations. The player tells the user only that an AI Mix is being generated, so they are not informed that personal listening preferences leave the device and are sent to an external service.
Disclose the third-party transfer and obtain informed opt-in before sending history names, or keep the history-based generation on-device.
Also at modules/aiMixGenerator.ts:128.
Prompt for AI agents
In `modules/aiMixGenerator.ts` at lines 74-75:
**Listening history sent to third party**
When the user taps the AI Mix button with listening history available, `loadHistoryNames` puts ranked artist and track names into the prompt, and `fetchFrom` posts it to Pollinations. The player tells the user only that an AI Mix is being generated, so they are not informed that personal listening preferences leave the device and are sent to an external service.
Disclose the third-party transfer and obtain informed opt-in before sending history names, or keep the history-based generation on-device.
Also at `modules/aiMixGenerator.ts:128`.| * Exits 0 if the discovery path works OR if it cleanly falls back (both | ||
| * are valid product outcomes); logs which happened. Fails only if the | ||
| * call throws uncaught or a track slips through from the wrong pool. |
There was a problem hiding this comment.
🟡 Medium · Live discovery test accepts fallback
When the generator always falls back, or the live endpoint returns no usable queries, main in ai-mix-discovery-e2e.cjs accepts any nonempty mix at line 93 and labels fallback a pass at line 114; the real queries are only logged at lines 100–103, so this test passes without verifying that the live response parsed or discovery ran.
Assert that live queries were produced and require a discovery result when the endpoint responds; report endpoint unavailability as skipped rather than as a passing discovery check.
Prompt for AI agents
In `tests/ai-mix-discovery-e2e.cjs` at lines 6-8:
**Live discovery test accepts fallback**
When the generator always falls back, or the live endpoint returns no usable queries, `main` in `ai-mix-discovery-e2e.cjs` accepts any nonempty mix at line 93 and labels fallback a pass at line 114; the real queries are only logged at lines 100–103, so this test passes without verifying that the live response parsed or discovery ran.
Assert that live queries were produced and require a discovery result when the endpoint responds; report endpoint unavailability as skipped rather than as a passing discovery check.| const mix = await GEN.generateAiMixWithDiscovery('en', { fetchImpl: llmFetch, search: discoverySearch }); | ||
| assert.ok(mix, 'expected a mix'); | ||
| assert.equal(mix.id, MIX.AI_MIX_ID); | ||
| assert.equal(llmCalls, 1, 'the LLM must be called exactly once'); | ||
| // Every track came from discovery, none from the user's library. | ||
| assert.ok(mix.tracks.length >= 8, 'expected a real discovery pool'); | ||
| assert.ok(mix.tracks.every((t) => t.id.startsWith('d')), 'mix must be new tracks only'); |
There was a problem hiding this comment.
🟡 Medium · Mock search ignores generated queries
When the generator calls the injected search with a constant or empty query instead of the parsed LLM output, in discovery: LLM queries resolve to a pinned mix of NEW tracks, discoverySearch at line 183 returns the same results for every input, so the assertions at lines 358–364 pass even if the generator ignores the LLM queries and searches with a constant or empty string.
Capture the query arguments in discoverySearch and assert they match the queries parsed from the mocked LLM response.
Prompt for AI agents
In `tests/ai-mix-regression.cjs` at lines 358-364:
**Mock search ignores generated queries**
When the generator calls the injected search with a constant or empty query instead of the parsed LLM output, in `discovery: LLM queries resolve to a pinned mix of NEW tracks`, `discoverySearch` at line 183 returns the same results for every input, so the assertions at lines 358–364 pass even if the generator ignores the LLM queries and searches with a constant or empty string.
Capture the query arguments in `discoverySearch` and assert they match the queries parsed from the mocked LLM response.| await check('discovery: a failed LLM call falls back to the on-device mix', async () => { | ||
| resetDiscovery(); | ||
| llmStatus = 500; | ||
| const mix = await GEN.generateAiMixWithDiscovery('en', { fetchImpl: llmFetch, search: discoverySearch }); | ||
| assert.ok(mix, 'fallback must still produce a mix'); | ||
| // On-device mix draws from the user's library, not discovery ids. | ||
| assert.ok(mix.tracks.every((t) => !t.id.startsWith('d')), 'fallback must be the on-device mix'); |
There was a problem hiding this comment.
🟡 Medium · Fallback tests accept empty mixes
When the fallback returns a playlist whose track list is empty, when a fallback returns a non-null playlist with tracks: [], the failed-LLM, unparseable-response, and thin-discovery checks pass because .every(...) is true for an empty array; the throwing-search check only asserts mix is truthy. These tests pass without a usable fallback mix.
Assert that each fallback mix contains at least one track before checking that its tracks came from the on-device pool.
Also at tests/ai-mix-regression.cjs:403-408, tests/ai-mix-regression.cjs:411-416, tests/ai-mix-regression.cjs:419-425.
Prompt for AI agents
In `tests/ai-mix-regression.cjs` at lines 394-400:
**Fallback tests accept empty mixes**
When the fallback returns a playlist whose track list is empty, when a fallback returns a non-null playlist with `tracks: []`, the failed-LLM, unparseable-response, and thin-discovery checks pass because `.every(...)` is true for an empty array; the throwing-search check only asserts `mix` is truthy. These tests pass without a usable fallback mix.
Assert that each fallback mix contains at least one track before checking that its tracks came from the on-device pool.
Also at `tests/ai-mix-regression.cjs:403-408`, `tests/ai-mix-regression.cjs:411-416`, `tests/ai-mix-regression.cjs:419-425`.There was a problem hiding this comment.
LlamaPReview — No blocking issues found
Safe to merge: every discovery stage is wrapped with a fallback to the shipped on-device mix, the mix persists through one stable write path, and the LLM only ever produces search queries.
2 non-blocking findings retained — highest: Sparkle tap now sends top artist/track names to a third-party endpoint, undisclosed.
Change flow
The whole discovery pipeline is a fallback chain: one persistence step under the stable @ai_mix id, the LLM fenced behind a strict parse and the app's own search, and every failure converging on the unchanged on-device generator.
sequenceDiagram
participant U as User
participant P as FullPlayerModal
participant G as aiMixGenerator
participant L as Pollinations LLM
participant S as YT Music Search
participant D as Local Storage
U->>P: tap sparkle
P->>G: generateAiMixWithDiscovery(language)
G->>D: loadHistory + liked + recent + counts
G->>G: pickSeed -> none -> null (alert)
note over G: PR change — discovery-first: LLM writes queries, search resolves, scoring stays deterministic
alt keyless LLM returns queries
G->>L: POST keyless prompt (no auth)
L-->>G: JSON array of <=6 queries
G->>S: resolveQueries (per-query catch, dedupe)
S-->>G: candidates
G->>G: buildSmartQueue(seed, candidates, 30)
opt queries empty or <8 candidates or <8 scored
G->>G: fall back to on-device mix
end
G->>D: persistAiMix: replace @ai_mix, keep rest
D-->>P: library-updated event
P-->>U: mix ready alert
else LLM unparseable or no candidates
G->>G: on-device mix fallback
G->>D: persistAiMix
P-->>U: mix ready alert
end
note over G,D: Impact — user sees a pinned replayable AI Mix, or the unchanged on-device mix
Review details and evidence
| Priority | File | Finding | Evidence |
|---|---|---|---|
| P2 | modules/aiMixGenerator.ts |
Sparkle tap now sends top artist/track names to a third-party endpoint, undisclosed | confirmed |
| P2 | modules/aiMixGenerator.ts |
Discovery ordering carries little signal, so 'curated' is weaker than on-device | confirmed |
Finding details
P2 · Sparkle tap now sends top artist/track names to a third-party endpoint, undisclosed
modules/aiMixGenerator.ts
Every sparkle tap posts the user's top artist names and track titles to a third-party anonymous endpoint, and there is no user-facing disclosure; the tradeoff is documented only in the module header and PR body. The request is evidenced as body-only and credential-free, so the consequence is preference data leaving the device on a user-initiated action — not an exploitable path — and no pre-merge change is required.
Owner action: Optional: surface a one-line notice or setting for the discovery call.
Verification boundary: confirmed; scope: bounded reviewed context.
P2 · Discovery ordering carries little signal, so 'curated' is weaker than on-device
modules/aiMixGenerator.ts
In the discovery branch the scoring weights have little to bite on: the prompt explicitly tells the model not to reuse the seed's artist/track names, the liked-baseline weight is added to every candidate, and play counts mostly refer to ids that are not in the discovery pool — so ordering is largely title-token overlap plus search order for ties. Selection is still deterministic and size-capped, so the consequence is a weaker curated claim than the on-device path, not a broken playlist.
Owner action: Optional: accept as-is, or give discovery its own signal later.
Verification boundary: confirmed; scope: bounded reviewed context.
Material unknowns
- Whether StorageService.loadPlaylists() throws or silently returns [] on a failed read. If it swallows errors and returns [], a failed read would make a successful write persist a mix-only playlist set locally, which would become a P1 data-consistency finding and move the posture to request changes (distinguish failed reads from an empty library, or serialize/guard the write). If it throws, the current behavior is simply a failed generation. Deep did not raise this as pre-merge because the premise is unobserved.
- Check: Check loadPlaylists failure semantics in the storage layer.
- Whether tests/ai-mix-regression.cjs and tests/ai-mix-discovery-e2e.cjs are wired into a repository runner. If not wired, the 27-check and live-run claims remain manual-only and the regression protection is not enforced. A coverage gap, not a defect claim.
- Check: Confirm the two suites are invoked from package.json or CI.
LlamaPReview checks
- Reviewed changed regions in
modules/aiMixGenerator.ts. - Read bounded PR-head context from
modules/aiMixGenerator.ts. - Read bounded PR-head context from
modules/aiPlaylistService.ts. - Read bounded PR-head context from
utils/storage.ts. - Inspected matching PR-head repository snippets in
utils/storage.ts,components/screens/LibraryScreen.tsx,lib/cloud-library-sync.tsand 2 more path(s). - Reviewed changed regions in
modules/aiMixPlaylist.ts.
Still coding alone? Open CarbonChat, a chat room right inside Codex.
… after main merge
Scope decision(a) Local-only reviews. No backend, no accounts, no sync — matches the offline-first rule this app is built on. The note lives on the rating row in Room, is shown on the dish detail next to the stars, and is searchable. (b) would need an anonymous vote endpoint and (c) accounts + moderation; neither is justified for a personal recipe app. |
Extends #89 / #49: the auto-playlist only resampled tracks the user already knew (liked + history pool). This adds a discovery mode that can generate genuinely new tracks, with zero API keys.
How it works
The LLM only ever writes search strings; track selection stays deterministic on-device. No credentials, no Authorization header, anonymous lane only.
Verified
Summary by Sourcery
Enable keyless LLM-guided discovery for AI auto-playlists while retaining deterministic track selection and robust on-device fallbacks.
New Features:
Bug Fixes:
Enhancements:
Tests: